Ejemplo n.º 1
0
    def fill_ions(self,
                  use_Nfile=False,
                  jfile=None,
                  use_components=False,
                  verbose=True):
        """ Loop on systems to fill in ions

        Parameters
        ----------
        jfile : str, optional
          JSON file containing the information
        use_Nfile : bool, optional
          Use (historic) .clm files?
        use_components : bool, optional
          Load up the Table with components (recommended)
        """
        if jfile is not None:
            # Load
            with open(jfile) as data_file:
                ions_dict = json.load(data_file)
            # Loop on systems
            for abs_sys in self._abs_sys:
                abs_sys.get_ions(idict=ions_dict[abs_sys.name])
        elif use_Nfile:
            for abs_sys in self._abs_sys:
                abs_sys.get_ions(use_Nfile=True, verbose=verbose)
        elif use_components:
            for abs_sys in self._abs_sys:
                abs_sys._ionN = ltiu.iontable_from_components(
                    abs_sys._components, ztbl=abs_sys.zabs)
        else:
            raise ValueError("Not sure how to load the ions")
Ejemplo n.º 2
0
    def fill_ions(self, use_Nfile=False, jfile=None, use_components=False):
        """ Loop on systems to fill in ions

        Parameters
        ----------
        jfile : str, optional
          JSON file containing the information
        use_Nfile : bool, optional
          Use (historic) .clm files?
        use_components : bool, optional
          Load up the Table with components (recommended)
        """
        if jfile is not None:
            # Load
            with open(jfile) as data_file:    
                ions_dict = json.load(data_file)
            # Loop on systems
            for abs_sys in self._abs_sys:
                abs_sys.get_ions(idict=ions_dict[abs_sys.name])
        elif use_Nfile:
            for abs_sys in self._abs_sys:
                abs_sys.get_ions(use_Nfile=True)
        elif use_components:
            for abs_sys in self._abs_sys:
                abs_sys._ionN = ltiu.iontable_from_components(abs_sys._components,
                                                              ztbl=abs_sys.zabs)
        else:
            raise ValueError("Not sure how to load the ions")
Ejemplo n.º 3
0
def test_iontable_from_components():
    # Lines
    abscomp,HIlines = mk_comp('HI')
    abscomp,SiIIlines = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True)
    # Components
    comps = ltiu.build_components_from_abslines([HIlines[0],HIlines[1],SiIIlines[0],SiIIlines[1]])
    tbl = ltiu.iontable_from_components(comps)
    assert len(tbl) == 2
Ejemplo n.º 4
0
def test_iontable_from_components():
    # Lines
    abscomp, HIlines = mk_comp('HI')
    abscomp, SiIIlines = mk_comp('SiII',
                                 vlim=[-250, 80.] * u.km / u.s,
                                 add_spec=True)
    # Components
    comps = ltiu.build_components_from_abslines(
        [HIlines[0], HIlines[1], SiIIlines[0], SiIIlines[1]])
    tbl = ltiu.iontable_from_components(comps)
    assert len(tbl) == 2
Ejemplo n.º 5
0
    def get_ions(self,
                 use_Nfile=False,
                 idict=None,
                 update_zvlim=True,
                 linelist=None,
                 verbose=True):
        """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)
          NOTE: This ignores velocity constraints on components (i.e. skip_vel=True)
        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)
            #pdb.set_trace()
            # Build components
            components = ltiu.build_components_from_dict(self._clmdict,
                                                         coord=self.coord,
                                                         chk_vel=False)
            # 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
            _ = igmau.read_all_file(all_file, components=components)
            # Build table
            self._ionN = ltiu.iontable_from_components(components,
                                                       ztbl=self.zabs)
            # Add to AbsSystem
            for comp in components:
                self.add_component(comp)
        elif idict is not None:
            table = dict_to_ions(idict)
            self._ionN = table
        else:
            raise IOError("Not ready for this")
Ejemplo n.º 6
0
    def build_table(self):
        """Generate an astropy QTable out of the components.
        Default columns are z, Ion, flag_N, logN, sig_logN

        Returns
        -------
        comp_tbl : Table
        """
        from linetools.isgm.utils import iontable_from_components
        comp_tbl = Table()
        if len(self._components) == 0:
            return comp_tbl
        comp_tbl = iontable_from_components(self._components)

        # Return
        return comp_tbl
Ejemplo n.º 7
0
    def build_table(self):
        """Generate an astropy QTable out of the components.
        Default columns are z, Ion, flag_N, logN, sig_logN

        Returns
        -------
        comp_tbl : Table
        """
        from linetools.isgm.utils import iontable_from_components
        comp_tbl = Table()
        if len(self._components) == 0:
            return comp_tbl
        comp_tbl = iontable_from_components(self._components)

        # Return
        return comp_tbl
Ejemplo n.º 8
0
Archivo: dla.py Proyecto: ninoc/pyigm
    def get_ions(self, use_Nfile=False, idict=None, update_zvlim=True,
                 linelist=None, verbose=True):
        """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)
          NOTE: This ignores velocity constraints on components (i.e. skip_vel=True)
        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)
            #pdb.set_trace()
            # Build components
            components = ltiu.build_components_from_dict(self._clmdict,
                                                         coord=self.coord,
                                                         chk_vel=False)
            # 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 = ltiu.iontable_from_components(components, ztbl=self.zabs)
            # Add to AbsSystem
            for comp in components:
                self.add_component(comp)
        elif idict is not None:
            table = dict_to_ions(idict)
            self._ionN = table
        else:
            raise IOError("Not ready for this")
Ejemplo n.º 9
0
    def from_dict(cls, parent, idict, lbl):
        """ Generate a sub-system from a dict

        Parameters
        ----------
        parent : AbsSystem
          Link
        idict : dict
          Contains the sub-system parameters
        lbl : str
        """
        slf = cls(parent, idict['zabs'], idict['vlim'] * u.km / u.s, lbl)
        # Components
        components = ltiu.build_components_from_dict(idict)
        slf._components = components
        # Ion table
        slf._ionN = ltiu.iontable_from_components(components)
        # Return
        return slf
Ejemplo n.º 10
0
    def from_dict(cls, parent, idict, lbl):
        """ Generate a sub-system from a dict

        Parameters
        ----------
        parent : AbsSystem
          Link
        idict : dict
          Contains the sub-system parameters
        lbl : str
        """
        slf = cls(parent, idict['zabs'], idict['vlim']*u.km/u.s, lbl)
        # Components
        components = ltiu.build_components_from_dict(idict)
        slf._components = components
        # Ion table
        slf._ionN = ltiu.iontable_from_components(components)
        # Return
        return slf
Ejemplo n.º 11
0
 def fill_ionN(self, **kwargs):
     """ Fills the ionN Table from the list of components
     """
     self._ionN = ltiu.iontable_from_components(self._components, **kwargs)
Ejemplo n.º 12
0
 def fill_ionN(self, **kwargs):
     """ Fills the ionN Table from the list of components
     """
     self._ionN = ltiu.iontable_from_components(self._components, **kwargs)
Ejemplo n.º 13
0
    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)
          NOTE: This ignores velocity constraints on components (i.e. skip_vel=True)
        update_zvlim : bool, optional
          Update zvlim from lines in .clm (as applicable)
        linelist : LineList
        """
        if idict is not None:
            table = dict_to_ions(idict)
            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 = ltiu.build_components_from_dict(self.subsys[lbl]._clmdict,
                                                             coord=self.coord, skip_vel=True)
                self.subsys[lbl]._components = components
                # Update z, vlim
                if update_zvlim:
                    self.update_vlim(sub_system=lbl)
                    self.subsys[lbl].zabs = self.subsys[lbl]._clmdict['zsys']
                # 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 = ltiu.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")
Ejemplo n.º 14
0
    def get_ions(self,
                 use_Nfile=False,
                 idict=None,
                 update_zvlim=True,
                 linelist=None,
                 verbose=True):
        """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)
          NOTE: This ignores velocity constraints on components (i.e. chk_vel=False)
        update_zvlim : bool, optional
          Update zvlim from lines in .clm (as applicable)
        linelist : LineList
        """
        if idict is not None:
            table = dict_to_ions(idict)
            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 = ltiu.build_components_from_dict(
                    self.subsys[lbl]._clmdict, coord=self.coord, chk_vel=False)
                self.subsys[lbl]._components = components
                # Update z, vlim
                if update_zvlim:
                    self.update_vlim(sub_system=lbl)
                    self.subsys[lbl].zabs = self.subsys[lbl]._clmdict['zsys']
                # 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 = ltiu.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")