Example #1
0
    def from_dict(cls, idict):
        """ Instantiate from a dict.  Usually read from the hard-drive

        Parameters
        ----------
        idict : dict

        Returns
        -------
        AbsSystem

        """
        slf = cls(idict['abs_type'],
                  SkyCoord(ra=idict['RA']*u.deg, dec=idict['DEC']*u.deg),
                  idict['zabs'], idict['vlim']*u.km/u.s,
                  zem=idict['zem'], NHI=idict['NHI'],
                  sig_NHI=idict['sig_NHI'], name=idict['Name']
                  )
        # Components
        components = ltiu.build_components_from_dict(idict)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component)

        # Return
        return slf
Example #2
0
def add_comps_from_dict(slf, idict, skip_components=False, use_coord=False, **kwargs):
    """
    Parameters
    ----------
    slf : AbsSystem
    skip_components : bool, optional
      If True, absorption components (if any exist) are not loaded from the input dict.
      Use when you are only interested in the global properties of an AbsSystem
    use_coord : bool, optinal
      Use coordinates from the AbsSystem to build the components (and lines)
      Speeds up performance, but you should know things are OK before using this

    Returns
    -------

    """
    if not skip_components:
        # Components
        if use_coord:  # Speed up performance
            coord = slf.coord
        else:
            coord = None
        components = ltiu.build_components_from_dict(idict, coord=coord, **kwargs)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component, **kwargs)
Example #3
0
def add_comps_from_dict(slf, idict, skip_components=False, use_coord=False, **kwargs):
    """
    Parameters
    ----------
    slf : AbsSystem, AbsSightline
      Or any object with an add_component() method
    skip_components : bool, optional
      If True, absorption components (if any exist) are not loaded from the input dict.
      Use when you are only interested in the global properties of an AbsSystem
    use_coord : bool, optinal
      Use coordinates from the AbsSystem to build the components (and lines)
      Speeds up performance, but you should know things are OK before using this

    Returns
    -------

    """
    if not skip_components:
        # Components
        if use_coord:  # Speed up performance
            coord = slf.coord
        else:
            coord = None
        components = ltiu.build_components_from_dict(idict, coord=coord, **kwargs)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component, **kwargs)
Example #4
0
    def components_from_dict(self, abssys_name, coord=None, linelist=None):
        """ Build and return a list of AbsComponent objects
        from the dict for a given system

        Parameters
        ----------
        abssys_name : str
        coord : SkyCoord, optional
          coordinates to use for the components
        linelist : LineList, optional

        Returns
        -------
        compllist : list of AbsComponent objects

        """
        # Do it
        if linelist is None:
            linelist = default_linelist(self.verbose)
        # Components
        comps = ltiu.build_components_from_dict(self._dict[abssys_name],
                                                coord=coord,
                                                linelist=linelist)
        # Return
        return comps
Example #5
0
    def from_dict(cls, idict):
        """ Generate an LLSSystem from a dict

        Parameters
        ----------
        idict : dict
          Usually read from the hard-drive
        """
        kwargs = dict(zem=idict['zem'], NHI=idict['NHI'],
                      sig_NHI=idict['sig_NHI'], name=idict['Name'])
        slf = cls(SkyCoord(ra=idict['RA']*u.deg, dec=idict['DEC']*u.deg),
                  idict['zabs'], idict['vlim']*u.km/u.s, **kwargs)
        # Components
        components = ltiu.build_components_from_dict(idict)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component)

        # Subsystems
        if 'A' in idict.keys():
            lbls= map(chr, range(65, 91))
            for lbl in lbls:
                if lbl in idict.keys():
                    # Generate
                    subsys = AbsSubSystem.from_dict(slf, idict[lbl], lbl)
                    slf.subsys[lbl] = subsys
                else:
                    pass
            # Total them
            slf.nsub = len(slf.subsys.keys())

        # Return
        return slf
Example #6
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")
Example #7
0
File: dla.py Project: ninoc/pyigm
    def load_components(self, inp):
        """ Load components from an input object

        Parameters
        ----------
        inp : dict or ??
          Input object for loading the components
        """
        if isinstance(inp, dict):
            components = ltiu.build_components_from_dict(inp, coord=self.coord,
                                                         skip_vel=True)
            # Add in
            for component in components:
                self.add_component(component)
        else:
            raise NotImplementedError("Not ready for this input")
Example #8
0
    def load_components(self, inp):
        """ Load components from an input object

        Parameters
        ----------
        inp : dict or ??
          Input object for loading the components
        """
        if isinstance(inp, dict):
            components = ltiu.build_components_from_dict(inp,
                                                         coord=self.coord,
                                                         skip_vel=True)
            # Add in
            for component in components:
                self.add_component(component)
        else:
            raise NotImplementedError("Not ready for this input")
Example #9
0
File: dla.py Project: 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")
Example #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
Example #11
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
Example #12
0
    def from_dict(cls, idict, skip_components=False, use_coord=False, **kwargs):
        """ Instantiate from a dict.  Usually read from the hard-drive

        Parameters
        ----------
        idict : dict
        skip_components : bool, optional
          If True, absorption components (if any exist) are not loaded from the input dict.
          Use when you are only interested in the global properties of an AbsSystem
        use_coord : bool, optinal
          Use coordinates from the AbsSystem to build the components (and lines)
          Speeds up performance, but you should know things are OK before using this

        Returns
        -------
        AbsSystem

        """
        if 'NHI' in idict.keys():
            ckwargs = dict(NHI=idict['NHI'], sig_NHI=idict['sig_NHI'], flag_NHI=idict['flag_NHI'])
        slf = cls(SkyCoord(ra=idict['RA']*u.deg, dec=idict['DEC']*u.deg),
                  idict['zabs'], idict['vlim']*u.km/u.s, zem=idict['zem'],
                  name=idict['Name'], **ckwargs)
        # Other
        if 'kin' in idict.keys():
            slf.kin = ltu.convert_quantity_in_dict(idict['kin'])
        if 'Refs' in idict.keys():
            slf.Refs = idict['Refs']
        # Components
        if not skip_components:
            # Components
            if use_coord:  # Speed up performance
                coord = slf.coord
            else:
                coord = None
            components = ltiu.build_components_from_dict(idict, coord=coord, **kwargs)
            for component in components:
                # This is to insure the components follow the rules
                slf.add_component(component, **kwargs)

        # Return
        return slf
Example #13
0
    def from_dict(cls, idict):
        """ Generate a DLASystem from a dict

        Parameters
        ----------
        idict : dict
          Usually read from the hard-drive
        """
        kwargs = dict(zem=idict['zem'], sig_NHI=idict['sig_NHI'],
                      name=idict['Name'])
        slf = cls(SkyCoord(idict['RA'], idict['DEC'], unit='deg'),
                  idict['zabs'], idict['vlim']*u.km/u.s, idict['NHI'],
                  **kwargs)
        # Components
        components = ltiu.build_components_from_dict(idict)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component)
        # Return
        return slf
Example #14
0
    def from_dict(cls, idict, **kwargs):
        """ Generate a DLASystem from a dict

        Parameters
        ----------
        idict : dict
          Usually read from the hard-drive
        """
        from astropy.coordinates import SkyCoord
        kwargs['zem'] = idict['zem']
        kwargs['sig_NHI'] = idict['sig_NHI']
        kwargs['name'] = idict['Name']
        slf = cls(SkyCoord(idict['RA'], idict['DEC'],
                           unit='deg'), idict['zabs'],
                  idict['vlim'] * u.km / u.s, idict['NHI'], **kwargs)
        # Components
        components = ltiu.build_components_from_dict(idict, **kwargs)
        for component in components:
            # This is to insure the components follow the rules
            slf.add_component(component)
        # Return
        return slf
Example #15
0
    def load_components(self, inp):
        """ Load components for subsystems from an input object

        May also update/create subsystems

        Parameters
        ----------
        inp : dict or ??
          Input object for loading the components
        """
        if isinstance(inp, dict):
            lbls = map(chr, range(65, 91))
            # Subsystems?
            if 'A' in inp.keys():
                for lbl in lbls:
                    if lbl in inp.keys():
                        if lbl not in self.subsys.keys():
                            self.subsys[lbl] = AbsSubSystem(
                                self, inp[lbl]['zsys'],
                                [-300., 300] * u.km / u.s, lbl)
                        # Fill/update
                        self.subsys[lbl]._clmdict = inp[
                            lbl]  # Not so necessary
                        components = ltiu.build_components_from_dict(
                            self.subsys[lbl]._clmdict,
                            coord=self.coord,
                            chk_vel=True)
                        self.subsys[lbl]._components = components
                        # Update vlim
                        self.update_vlim(sub_system=lbl)
                    else:
                        pass
                self.nsub = len(self.subsys.keys())
            else:
                raise ValueError("Not sure what to do here")
        else:
            raise NotImplementedError("Not ready for this input")
Example #16
0
    def load_components(self, inp):
        """ Load components for subsystems from an input object

        May also update/create subsystems

        Parameters
        ----------
        inp : dict or ??
          Input object for loading the components
        """
        if isinstance(inp, dict):
            lbls= map(chr, range(65, 91))
            # Subsystems?
            if 'A' in inp.keys():
                for lbl in lbls:
                    if lbl in inp.keys():
                        if lbl not in self.subsys.keys():
                            self.subsys[lbl] = AbsSubSystem(self,
                                                            inp[lbl]['zsys'],
                                                            [-300., 300]*u.km/u.s,
                                                            lbl)
                        # Fill/update
                        self.subsys[lbl]._clmdict = inp[lbl]  # Not so necessary
                        components = ltiu.build_components_from_dict(self.subsys[lbl]._clmdict,
                                                                 coord=self.coord,
                                                                 skip_vel=True)
                        self.subsys[lbl]._components = components
                        # Update vlim
                        self.update_vlim(sub_system=lbl)
                    else:
                        pass
                self.nsub = len(self.subsys.keys())
            else:
                raise ValueError("Not sure what to do here")
        else:
            raise NotImplementedError("Not ready for this input")
Example #17
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")
Example #18
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")