Ejemplo n.º 1
0
Archivo: dla.py Proyecto: nhmc/pyigm
    def get_ions(self, use_Nfile=False, update_zvlim=True, linelist=None):
        """Parse the ions for each Subsystem

        And put them together for the full system
        Fills ._ionN with a QTable

        Parameters
        ----------
        idict : dict, optional
          dict containing the IonClms info
        use_Nfile : bool, optional
          Parse ions from a .clm file (JXP historical)
        update_zvlim : bool, optional
          Update zvlim from lines in .clm (as applicable)
        linelist : LineList
        """
        if use_Nfile:
            clm_fil = self.tree+self._datdict['Abund file']
            # Read
            self._clmdict = igmau.read_clmfile(clm_fil, linelist=linelist)
            # Build components
            components = igmau.build_components_from_abslines([], clmdict=self._clmdict, coord=self.coord)
            # Read .ion file and fill in components
            ion_fil = self.tree+self._clmdict['ion_fil']
            self._indiv_ionclms = igmau.read_ion_file(ion_fil, components)
            # Parse .all file
            all_file = ion_fil.split('.ion')[0]+'.all'
            self.all_file=all_file #MF: useful to have
            _ = igmau.read_all_file(all_file, components=components)
            # Build table
            self._ionN = igmau.iontable_from_components(components, ztbl=self.zabs)
            # Add to AbsSystem
            for comp in components:
                self.add_component(comp)
        else:
            raise IOError("Not ready for this")
Ejemplo n.º 2
0
Archivo: lls.py Proyecto: nhmc/pyigm
    def get_ions(self, use_Nfile=False, idict=None, update_zvlim=True, linelist=None):
        """Parse the ions for each Subsystem

        And put them together for the full system
        Fills ._ionN with a QTable

        Parameters
        ----------
        idict : dict, optional
          dict containing the IonClms info
        use_Nfile : bool, optional
          Parse ions from a .clm file (JXP historical)
        update_zvlim : bool, optional
          Update zvlim from lines in .clm (as applicable)
        linelist : LineList
        """
        if idict is not None:
            # Manipulate for astropy Table
            #  Could probably use add_row or dict instantiation
            table = None
            for ion in idict.keys():
                Zion = ltai.name_ion(ion)
                if table is None:
                    tkeys = idict[ion].keys()
                    lst = [[idict[ion][tkey]] for tkey in tkeys]
                    table = Table(lst, names=tkeys)
                    # Extra columns
                    if 'Z' not in tkeys:
                        table.add_column(Column([Zion[0]], name='Z'))
                        table.add_column(Column([Zion[1]], name='ion'))
                else:
                    tdict = idict[ion]
                    tkeys = idict[ion].keys()
                    if 'Z' not in tkeys:
                        tdict['Z'] = Zion[0]
                        tdict['ion'] = Zion[1]
                    # Add
                    table.add_row(tdict)
            # Finish
            try:  # Historical keys
                table.rename_column('clm', 'logN')
            except:
                pass
            else:
                table.rename_column('sig_clm', 'sig_logN')
                table.rename_column('flg_clm', 'flag_N')
            self._ionN = table
        elif use_Nfile:
            # Subsystems
            if self.nsub > 0:  # This speeds things up (but is rarely used)
                linelist = LineList('ISM')
            for lbl in self.subsys.keys():
                clm_fil = self.tree+self.subsys[lbl]._datdict['clm_file']
                # Parse .clm file
                self.subsys[lbl]._clmdict = igmau.read_clmfile(clm_fil, linelist=linelist)
                # Build components from lines
                components = igmau.build_components_from_abslines([], clmdict=self.subsys[lbl]._clmdict, coord=self.coord)
                # Update z, vlim
                if update_zvlim:
                    vmin,vmax = 9999., -9999.
                    for component in components:
                        vmin = min(vmin, component.vlim[0].value)
                        vmax = max(vmax, component.vlim[1].value)
                    self.subsys[lbl].zabs = self.subsys[lbl]._clmdict['zsys']
                    self.subsys[lbl].vlim = [vmin, vmax]*u.km/u.s
                # Read .ion file and fill in components
                ion_fil = self.tree+self.subsys[lbl]._clmdict['ion_fil']
                self.subsys[lbl]._indiv_ionclms = igmau.read_ion_file(ion_fil, components)
                # Parse .all file
                all_file = ion_fil.split('.ion')[0]+'.all'
                self.subsys[lbl].all_file=all_file #MF: useful to have
                _ = igmau.read_all_file(all_file, components=components)
                # Build table
                self.subsys[lbl]._ionN = igmau.iontable_from_components(components,ztbl=self.subsys[lbl].zabs)
                # Add to IGMSystem
                for comp in components:
                    self.add_component(comp)

            # Combine
            if self.nsub == 1:
                self._ionN = self.subsys['A']._ionN
                self._clmdict = self.subsys['A']._clmdict
                #xdb.set_trace()
            elif self.nsub == 0:
                raise ValueError('lls_utils.get_ions: Cannot have 0 subsystems..')
            else:
                self._ionN = self.subsys['A']._ionN
                self._clmdict = self.subsys['A']._clmdict
                warnings.warn('lls_utils.get_ions: Need to update multiple subsystems!! Taking A.')
        else:
            raise ValueError("Need an option in get_ions")