예제 #1
0
파일: lls.py 프로젝트: mneeleman/pyigm
    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
예제 #2
0
    def from_dict(cls, idict, **kwargs):
        """ Generate an LLSSystem from a dict

        Parameters
        ----------
        idict : dict
          Usually read from the hard-drive
        """
        from linetools.isgm.abssystem import add_comps_from_dict, add_other_from_dict
        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)
        #
        add_other_from_dict(slf, idict)
        add_comps_from_dict(slf, idict, **kwargs)

        # 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
예제 #3
0
    def parse_dat_file(self, vlim=[-300.,300]*u.km/u.s):
        """ Parse the datdict read from the .dat file

        Parameters
        ----------
        vlim : Quantity array (2), optional
          Velocity limits of the subsystems
          Should be pulled from the .clm files
        """

        # LLS keys
        self.bgsrc = self._datdict['QSO name']
        self.zem = float(self._datdict['QSO zem'])  # Was zqso
        self.ZH = float(self._datdict['[M/H] ave'])
        self.nsub = int(self._datdict['N subsys'])
        self.cldyfil = self._datdict['Cloudy Grid File']

        # LLS Subsystems
        if self.nsub > 0:
            lbls= map(chr, range(65, 91))
            # Dict
            keys = (['zabs','NHI','NHIsig','NH','NHsig','log x','sigx','b','bsig','Abund file',
                     'U','Usig','flg_low','flg_alpha','[alpha/H]','sig[a/H]',
                     'flg_Fe','[Fe/H]','sig[Fe/H]','VPFIT file'])
            att = (['zabs','NHI','NHIsig','NH','NHsig','logx','sigx','bval','bsig','clm_file',
                     'U','Usig','flg_low','flg_alpha','alpha_H','sig_a_H',
                     'flg_Fe','Fe_H','sig_Fe_H','VPFIT_file'])
            values = ([0., 0., np.zeros(2), 0., np.zeros(2), 0., np.zeros(2), 0., 0.,
                    '', 0., np.zeros(2), 0, 0, 0., 0., 0, 0., 0., ''])
            null_dict = dict(zip(keys,values))
            # Loop on subsystems
            for i in range(self.nsub):
                # Generate
                zabs = float(self._datdict[lbls[i] + ' zabs'])
                self.subsys[lbls[i]] = AbsSubSystem(self, zabs, vlim, lbls[i])
                self.subsys[lbls[i]]._datdict = {}
                # Fill in dict
                for ii, key in enumerate(keys):
                    try:
                        tmpc = self._datdict[lbls[i]+' '+key]
                    except:
                        raise ValueError('lls_utils: Key "{:s}" not found in {:s}'
                                         .format(lbls[i]+key,self.dat_file))
                    else:  # Convert
                        val = null_dict[key]
                        if val.__class__ == np.ndarray:
                            self.subsys[lbls[i]]._datdict[att[ii]] = np.array(map(float,tmpc.split()))
                        else:  # Single value
                            self.subsys[lbls[i]]._datdict[att[ii]] = (map(type(val),[tmpc]))[0]
                # Set a few special ones as attributes
                self.subsys[lbls[i]].NHI = self.subsys[lbls[i]]._datdict['NHI']
                self.subsys[lbls[i]].sig_NHI = self.subsys[lbls[i]]._datdict['NHIsig']
예제 #4
0
def zonak2004():
    """Zonak, S. et al. 2004, ApJ, 2004, 606, 196

    PG1634+706
    HST+Keck spectra
    MgII, SiIV, SiIII from Table 2.  Summing Subsystems A (Model 2) and B
       Errors estimated by JXP (not reported)
       SiIII in A may be a model
       SiIV in B may be a model
    Total NHI from LL. Taken from Fig 3 caption.  
       Error estimated by JXP 
    Not all EWs in Table 1 included
    Adopting their M/H
    """
    # Setup
    radec = '163428.9897+703132.422'  # SIMBAD
    lls = LLSSystem(name='PG1634+706_z1.041', radec=radec, zem=1.337,
        zabs=1.0414, vlim=[-250., 100.]*u.km/u.s, NHI=17.23, ZH=-1.4,
        sig_NHI=np.array([0.15,0.15]))
    # SubSystems
    lls.nsub = 2
    # Abundances
    adict = dict(MgII={'clm': log_sum([11.45,11.90,12.02,11.68]), 'sig_clm': 0.05, 'flg_clm': 1},
        SiIII={'clm': log_sum([12.5,12.5,12.8,12.7]), 'sig_clm': 0.25, 'flg_clm': 1},
        SiIV={'clm': log_sum([10.9,10.8,11.2,11.1]), 'sig_clm': 0.15, 'flg_clm': 1} )
    lls.subsys['A'] = AbsSubSystem(lls, 1.0414, [-80, 100]*u.km/u.s, 'A')
    lls.subsys['A']._ionN = pyiau.dict_to_ions(adict)

    bdict = dict(SiIII={'clm': log_sum([11.8,12.8,12.4]), 'sig_clm': 0.15, 'flg_clm': 1},
        SiIV={'clm': log_sum([11.2,12.2,11.8]), 'sig_clm': 0.15, 'flg_clm': 1} )
    lls.subsys['B'] = AbsSubSystem(lls, 1.0414, [-240, -80]*u.km/u.s, 'B')
    lls.subsys['B']._ionN = pyiau.dict_to_ions(bdict)
    # Total
    lls._ionN = pyiau.sum_ionN(lls.subsys['A']._ionN, lls.subsys['B']._ionN)
    lls.Refs.append('Zon04')
    # Return
    return lls
예제 #5
0
파일: lls.py 프로젝트: SunilSimha/pyigm
    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")