Exemplo n.º 1
0
    def __getitem__(self, ion):
        '''Passback a dict of measured data on a given ion

        Parameters:
        -----------
        ion: tuple or str
          tuple:  (Z,ion_state) e.g. (14,2) 
          str:  Name, e.g. 'SiII'

        Returns:
        ----------
        Dict (from row in the data table)
        '''
        if isinstance(ion, tuple):
            mt = np.where((self._data['Z'] == ion[0])
                          & (self._data['ion'] == ion[1]))[0]
        elif isinstance(ion, basestring):
            # Convert to tuple
            return self.__getitem__(xai.name_ion(ion))
        else:
            raise ValueError('Not prepared for this type')

        if len(mt) == 0:
            raise KeyError
        else:
            return dict(zip(self._data.dtype.names, self._data[mt][0]))
Exemplo n.º 2
0
    def __getitem__(self, k):
        '''Passback list of lines with this input
        See also grab_line method for quries on individual lines

        Parameters:
        -----------
        k: Quantity, tuple, or str
          float -- Rest wavelength, e.g. 1215.6701*u.AA
          tuple   -- Zion, e.g. (14,2)
          str     -- Name of the ion, e.g. 'SiII'

        Returns:
        ----------
        float: List of all matching absorption lines 
        str:   Dict of info on that ion and wavelengths of matching lines
        '''
        if isinstance(k,Quantity):  # List of AbsLines
            return [ilin for ilin in self.lines if np.abs(ilin.wrest-k)<1e-4*u.AA]
        elif isinstance(k,(basestring,tuple)):  # 
            # Column densities
            idict = self._ionclms[k]
            # Matching Absorption lines matching
            if isinstance(k,basestring):
                Zion = xai.name_ion(k)
            else:
                Zion = k
            idict[str('lines')] = [ilin.wrest for ilin in self.lines if ( 
                (ilin.data['Z']==Zion[0]) & (ilin.data['ion']==Zion[1]))]
            return idict
            #lines = [ilin for ilin in self.lines if ilin.trans==k]
        else:
            raise ValueError('Not prepared for this type')
Exemplo n.º 3
0
    def __getitem__(self, ion):
        '''Passback a dict of measured data on a given ion

        Parameters:
        -----------
        ion: tuple or str
          tuple:  (Z,ion_state) e.g. (14,2) 
          str:  Name, e.g. 'SiII'

        Returns:
        ----------
        Dict (from row in the data table)
        '''
        if isinstance(ion,tuple):
            mt = np.where((self._data['Z'] == ion[0]) & (self._data['ion'] == ion[1]))[0]
        elif isinstance(ion,basestring):
            # Convert to tuple
            return self.__getitem__(xai.name_ion(ion))
        else:
            raise ValueError('Not prepared for this type')

        if len(mt) == 0:
            raise KeyError
        else:
            return dict(zip(self._data.dtype.names,self._data[mt][0]))
Exemplo n.º 4
0
    def __getitem__(self, k):
        '''Passback list of lines with this input
        See also grab_line method for quries on individual lines

        Parameters:
        -----------
        k: Quantity, tuple, or str
          float -- Rest wavelength, e.g. 1215.6701*u.AA
          tuple   -- Zion, e.g. (14,2)
          str     -- Name of the ion, e.g. 'SiII'

        Returns:
        ----------
        float: List of all matching absorption lines 
        str:   Dict of info on that ion and wavelengths of matching lines
        '''
        if isinstance(k,Quantity):  # List of AbsLines
            return [ilin for ilin in self.lines if np.abs(ilin.wrest-k)<1e-4*u.AA]
        elif isinstance(k,(basestring,tuple)):  # 
            # Column densities
            idict = self._ionclms[k]
            # Matching Absorption lines matching
            if isinstance(k,basestring):
                Zion = xai.name_ion(k)
            else:
                Zion = k
            idict[str('lines')] = [ilin.wrest for ilin in self.lines if ( 
                (ilin.data['Z']==Zion[0]) & (ilin.data['ion']==Zion[1]))]
            return idict
            #lines = [ilin for ilin in self.lines if ilin.trans==k]
        else:
            raise ValueError('Not prepared for this type')
Exemplo n.º 5
0
 def from_dict(self, idict, verbose=False):
     # Manipulate for astropy Table
     table = None
     for ion in idict.keys():
         Zion = xai.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]
             if 'Z' not in tkeys:
                 tdict['Z'] = Zion[0]
                 tdict['ion'] = Zion[1]
             # Add
             table.add_row(tdict)
     # Finish
     self._data = table
Exemplo n.º 6
0
 def from_dict(self,idict,verbose=False):
     # Manipulate for astropy Table
     table = None
     for ion in idict.keys():
         Zion = xai.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]
             if 'Z' not in tkeys:
                 tdict['Z'] = Zion[0]
                 tdict['ion'] = Zion[1]
             # Add
             table.add_row(tdict)
     # Finish
     self._data = table
Exemplo n.º 7
0
def tumlinson11():
    '''Tumlinson, J. et al. 2011, ApJ, 733, 111
    J1009+0713
    HST/COS
    Metal columns parsed from Table 1
    NHI from LL+Lyman series (uncertain)
    '''
    # Grab ASCII file from ApJ
    tab_fil = xa_path + "/data/LLS/tumlinson11.tb1.ascii"
    url = 'http://iopscience.iop.org/0004-637X/733/2/111/suppdata/apj388927t1_ascii.txt'
    chk_fil = glob.glob(tab_fil)
    if len(chk_fil) > 0:
        tab_fil = chk_fil[0]
    else:
        print('LLSSurvey: Grabbing table file from {:s}'.format(url))
        f = urllib2.urlopen(url)
        with open(tab_fil, "wb") as code:
            code.write(f.read())
    # Setup
    radec = xor.stod1('J100902.06+071343.8')  # From paper
    lls = LLSSystem(name='J1009+0713_z0.356',
                    RA=radec[0],
                    Dec=radec[1],
                    zem=0.456,
                    zabs=0.3558,
                    vlim=[-200., 250.] * u.km / u.s,
                    NHI=18.4,
                    sigNHI=np.array([0.41, 0.41]))
    #lls.mk_subsys(2)

    # Columns
    # Start with Table 3 (VPFIT)
    with open(tab_fil, 'r') as f:
        flines1 = f.readlines()
    # Trim
    flines1 = flines1[18:]
    #
    ion_dict = {}
    line_dict = dict(OI='1302',
                     OVI='1038',
                     MgII='2803^b',
                     SiII='1190',
                     CaII='3934',
                     FeII='2586')
    ion = None
    for iline in flines1:
        isplit = iline.split('\t')
        if ion == 'FeIII':  # Last line
            break
        # Ion
        is2 = isplit[0].split(' ')
        ion = is2[0] + is2[1]
        try:
            gdl = line_dict[ion]
        except:
            pass
            #print('Taking {:s}'.format(isplit[0]))
        else:
            if is2[2] != gdl:
                continue
        Zion = xai.name_ion(ion)
        ion_dict[ion] = dict(clm=0.,
                             sig_clm=0.,
                             flg_clm=0,
                             Z=Zion[0],
                             ion=Zion[1])
        # Combine components [could replace with SubSystems some day]
        for iis in isplit[1:-1]:
            # Upper limit
            if (iis.strip()[0] == '<') & (ion_dict[ion]['flg_clm'] == 0):
                ion_dict[ion]['flg_clm'] = 3
                ion_dict[ion]['clm'] = float(iis[1:])
            elif (iis.strip()[0] == '>'):  # Saturated
                ion_dict[ion]['flg_clm'] = 2
                ion_dict[ion]['clm'] = log_sum(
                    [ion_dict[ion]['clm'],
                     float(iis[1:5])])
            elif iis.strip()[0] in ['.', '<']:
                pass
            else:
                if ion_dict[ion]['flg_clm'] == 2:  # Add to saturated
                    ion_dict[ion]['clm'] = log_sum(
                        [ion_dict[ion]['clm'],
                         float(iis[0:4])])
                else:
                    ion_dict[ion]['flg_clm'] = 1
                    obj = dict(clm=float(iis[0:4]), sig_clm=float(iis[-4:]))
                    # Add
                    N, sig = xiai.sum_logN(ion_dict[ion], obj)
                    ion_dict[ion]['clm'] = N
                    ion_dict[ion]['sig_clm'] = sig
    # Finish
    lls._ionclms = IonClms(idict=ion_dict)
    lls.Refs.append('Tum11')
    return lls
Exemplo n.º 8
0
def dessauges09():
    '''Dessauges-Zavadsky et al. 2009, MNRAS, 396, L96
    SLLS with UVES
    Zn,Fe abundances from Table 1 from astro-ph (LateX) by JXP [AODM]
     Taken from the Zn/H and Fe/H assuming *no* ionization corrections
    RA/DEC from the 'other' name 
    '''
    # Solar abundances
    eZn = 4.63
    eFe = 7.45
    sol = [eFe, eZn]
    #
    all_lls = []
    # Table 1
    tab_fil = xa_path + "/data/LLS/dessauges09.tb1.ascii"
    with open(tab_fil, 'r') as f:
        flines1 = f.readlines()
    # Trim the first few lines
    flines1 = flines1[3:]
    ion_dict = {}
    for iline in flines1:
        # Parse
        isplit = iline.split('&')
        # QSO
        if iline[0:2] == 'QS':
            # QSO, RA/DEC, zem
            qso = isplit[0][4:].strip()
            radec = xor.stod1(isplit[1].strip().replace('$', ''))
            zem = float(isplit[3].strip())
        # NHI, zabs
        zabs = float(isplit[4].strip())
        is2 = isplit[6].strip()
        NHI = float(is2[1:6])
        sigNHI = np.array([float(is2[10:14])] * 2)
        # name
        name = qso + 'z_{:.3f}'.format(zabs)
        lls = LLSSystem(name=name,
                        RA=radec[0],
                        Dec=radec[1],
                        zem=zem,
                        zabs=zabs,
                        NHI=NHI,
                        sigNHI=sigNHI)
        # ADOM Columns
        ion_dict = {}
        for kk, ion in enumerate(['Fe II', 'Zn II']):
            Zion = xai.name_ion(ion)
            is2 = isplit[7 + kk].strip()
            if is2[0:2] == '$>':
                ion_dict[ion] = dict(sig_clm=0.,
                                     flg_clm=2,
                                     Z=Zion[0],
                                     ion=Zion[1])
                ion_dict[ion]['clm'] = float(is2[2:7]) + NHI - 12 + sol[kk]
            elif is2[0:2] == '$<':
                ion_dict[ion] = dict(sig_clm=0.,
                                     flg_clm=3,
                                     Z=Zion[0],
                                     ion=Zion[1])
                ion_dict[ion]['clm'] = float(is2[2:7]) + NHI - 12 + sol[kk]
            elif is2[0:2] == '..':
                pass
            else:
                ion_dict[ion] = dict(flg_clm=1, Z=Zion[0], ion=Zion[1])
                ion_dict[ion]['clm'] = float(is2[1:6]) + NHI - 12 + sol[kk]
                ion_dict[ion]['sig_clm'] = float(is2[10:14])
        #xdb.set_trace()
        # Finish
        lls._ionclms = IonClms(idict=ion_dict)
        lls.Refs.append('DZ09')
        all_lls.append(lls)

    # Return SLLS only
    fin_slls = [ills for ills in all_lls if ills.NHI < 20.3]
    return fin_slls
Exemplo n.º 9
0
def meiring09():
    '''Meiring et al. 2009, MNRAS, 393, 1513
    SLLS with Magellan
    Abundances from Table 3 from astro-ph (LateX) by JXP [AODM]
    RA/DEC from Table 1
    '''
    all_lls = []
    # Table 1
    tab_fil = xa_path + "/data/LLS/meiring09.tb1.ascii"
    with open(tab_fil, 'r') as f:
        flines1 = f.readlines()
    # Grab RA/DEC
    qso_dict = {}
    for iline in flines1:
        if iline[0:3] in [' QS', '\hl', '$\\c', ' J2', '   ']:
            continue
        # Parse
        isplit = iline.split('&')
        #xdb.set_trace()
        if '$' in isplit[3].strip():
            isplit[3] = '-' + (isplit[3].strip())[3:]
        radec = xor.stod1((isplit[2], isplit[3]))
        # zem
        zem = float(isplit[5].strip())
        # Save
        qso_dict[isplit[0].strip()] = dict(RA=radec[0], Dec=radec[1], zem=zem)

    # Abundances (AODM)
    # Table 3
    tab_fil = xa_path + "/data/LLS/meiring09.tb3.ascii"
    with open(tab_fil, 'r') as f:
        flines3 = f.readlines()
    #
    ion_dict = {}
    for iline in flines3:
        if iline[0:2] in ['\h', '  ']:
            continue
        # Parse
        isplit = iline.split('&')
        # Ions
        if iline[0:2] == 'QS':
            ioncs = []
            Zions = []
            for iis in isplit[3:-1]:  # Skipping HI
                # Parse
                #is2 = iis.split('\\')
                #ip2 = is2[2].find('}')
                ionc = iis.strip()
                # Zion
                Zion = xai.name_ion(ionc)
                # Append
                ioncs.append(ionc)
                Zions.append(Zion)
            continue
        if iline[0] == 'Q':
            # QSO
            qso = isplit[0].strip()
            if qso[-1] in ['A', 'B', 'C']:
                qso = qso[0:-1]
            # zabs and name
            zabs = float(isplit[1].strip())
            qso_dict[qso]['name'] = qso + 'z_{:.3f}'.format(zabs)
            qso_dict[qso]['zabs'] = zabs
            # NHI
            is2 = isplit[2].strip()
            if is2[0] == '$':
                qso_dict[qso]['NHI'] = 99.99  # THROW OUT Q1436-0051B
                qso_dict[qso]['sigNHI'] = np.array([0., 0.])
            else:
                qso_dict[qso]['NHI'] = float(is2[0:5])
                qso_dict[qso]['sigNHI'] = np.array([float(is2[10:])] * 2)
            #if qso_dict[qso]['NHI'] >= 20.3:
            #    print('Uh oh.  DLA')
            # Generate LLS
            lls = LLSSystem(**qso_dict[qso])
            continue
        else:
            # ADOM Columns
            ion_dict = {}
            for kk, iis in enumerate(isplit[3:-1]):
                is2 = iis.strip()
                if is2[0:3] == '$>$':
                    ion_dict[ioncs[kk]] = dict(sig_clm=0.,
                                               flg_clm=2,
                                               Z=Zions[kk][0],
                                               ion=Zions[kk][1])
                    ion_dict[ioncs[kk]]['clm'] = float(is2[3:])
                elif is2[0:3] == '$<$':
                    ion_dict[ioncs[kk]] = dict(sig_clm=0.,
                                               flg_clm=3,
                                               Z=Zions[kk][0],
                                               ion=Zions[kk][1])
                    ion_dict[ioncs[kk]]['clm'] = float(is2[3:])
                elif len(is2) == 0:
                    pass
                else:
                    ion_dict[ioncs[kk]] = dict(flg_clm=1,
                                               Z=Zions[kk][0],
                                               ion=Zions[kk][1])
                    ion_dict[ioncs[kk]]['clm'] = float(is2[0:5])
                    ion_dict[ioncs[kk]]['sig_clm'] = float(is2[10:])
            # Finish
            lls._ionclms = IonClms(idict=ion_dict)
            lls.Refs.append('Mei09')
            all_lls.append(lls)

    # Return SLLS only
    fin_slls = [ills for ills in all_lls if ills.NHI < 20.3]
    return fin_slls
Exemplo n.º 10
0
def peroux06b():
    '''Peroux, C. et al. 2006b, A&A, 450, 53
    SDSS J1323-0021
    Metal rich
    Metal columns copied by JXP from Table 1 
    Total NHI from damping wings
    '''
    # Setup
    radec = xor.stod1('J132323.78-002155.2')  # SDSS Name
    lls = LLSSystem(name='SDSSJ1323-0021_z0.716',
                    RA=radec[0],
                    Dec=radec[1],
                    zem=1.390,
                    zabs=0.716,
                    vlim=[-200., 200.] * u.km / u.s,
                    NHI=20.21,
                    sigNHI=np.array([0.20, 0.20]))
    # Parse table file
    tab_fil = xa_path + "/data/LLS/peroux06b.tb1.ascii"
    with open(tab_fil, 'r') as f:
        flines = f.readlines()
    ion_dict = {}
    for iline in flines:
        isplit = iline.split('\t')
        if len(isplit[0]) == 0:
            # Grab ions and init
            ions = isplit[3:10]
            for ion in ions:
                Zion = xai.name_ion(ion)
                ion_dict[ion] = dict(clm=0.,
                                     sig_clm=0.,
                                     flg_clm=1,
                                     Z=Zion[0],
                                     ion=Zion[1])
            continue
        # Column or sigma?
        if isplit[0][0] == 'N':  # Column
            for kk, iis in enumerate(isplit[3:10]):
                ion = ions[kk]
                if iis[0] == '>':
                    ion_dict[ion]['flg_clm'] = 2
                    ion_dict[ion]['clm'] += float(iis[1:])
                elif iis[0] == '<':
                    pass
                elif iis[0] == '.':
                    pass
                else:
                    ion_dict[ion]['clm'] += float(iis)
        else:  # Sigma
            for kk, iis in enumerate(isplit[3:10]):
                ion = ions[kk]
                if iis[0] == '.':
                    pass
                else:
                    ion_dict[ion]['sig_clm'] += float(iis)**2
    # Convert to log
    for ion in ions:
        N = ion_dict[ion]['clm']
        sig = np.sqrt(ion_dict[ion]['sig_clm'])
        #
        ion_dict[ion]['clm'] = np.log10(N)
        if ion_dict[ion]['flg_clm'] == 2:
            ion_dict[ion]['sig_clm'] = 0.
        else:
            ion_dict[ion]['sig_clm'] = sig / N / np.log(10)
    # Finish
    lls._ionclms = IonClms(idict=ion_dict)
    lls.Refs.append('Prx06b')
    return lls
Exemplo n.º 11
0
def tripp2005():
    '''Tripp, T. et al. 2005, ApJ, 2005, 619, 714
    PG 1216+069 (LLS in Virgo)
    HST/STIS, FUSE
    Metal columns parsed from Tables 2 and 3
    Total NHI from damping wings
    M/H from O/H
    '''
    # Grab ASCII files from ApJ
    tab_fils = [
        xa_path + "/data/LLS/tripp2005.tb3.ascii",
        xa_path + "/data/LLS/tripp2005.tb2.ascii"
    ]
    urls = [
        'http://iopscience.iop.org/0004-637X/619/2/714/fulltext/60797.tb3.txt',
        'http://iopscience.iop.org/0004-637X/619/2/714/fulltext/60797.tb2.txt'
    ]
    for jj, tab_fil in enumerate(tab_fils):
        chk_fil = glob.glob(tab_fil)
        if len(chk_fil) > 0:
            tab_fil = chk_fil[0]
        else:
            url = urls[jj]
            print('LLSSurvey: Grabbing table file from {:s}'.format(url))
            f = urllib2.urlopen(url)
            with open(tab_fil, "wb") as code:
                code.write(f.read())
    # Setup
    radec = xor.stod1('J121920.9320+063838.476')  # SIMBAD
    lls = LLSSystem(name='PG1216+069_z0.006',
                    RA=radec[0],
                    Dec=radec[1],
                    zem=0.3313,
                    zabs=0.00632,
                    vlim=[-100., 100.] * u.km / u.s,
                    NHI=19.32,
                    MH=-1.6,
                    sigNHI=np.array([0.03, 0.03]))
    #lls.mk_subsys(2)

    # Columns
    # Start with Table 3 (VPFIT)
    with open(tab_fils[0], 'r') as f:
        flines3 = f.readlines()
    ion_dict = {}
    for iline in flines3:
        if (len(iline.strip()) == 0):
            continue
        isplit = iline.split('\t')
        # Ion
        flg = 2
        if (len(isplit[0].strip()) > 0):  # & (isplit[0][0] not in ['1','2']):
            ipos = isplit[0].find('1')
            ionc = isplit[0][0:ipos - 1].strip()
            try:
                Zion = xai.name_ion(ionc)
            except KeyError:
                xdb.set_trace()
            flg = 1
        # Column
        csplit = isplit[3].split(' ')
        clm = float(csplit[0])
        sig = float(csplit[2])
        if flg == 1:
            ion_dict[ionc] = dict(clm=clm,
                                  sig_clm=sig,
                                  flg_clm=1,
                                  Z=Zion[0],
                                  ion=Zion[1])
        else:  # Add it in
            tmp_dict = dict(clm=clm,
                            sig_clm=sig,
                            flg_clm=1,
                            Z=Zion[0],
                            ion=Zion[1])
            logN, siglogN = xiai.sum_logN(ion_dict[ionc], tmp_dict)
            ion_dict[ionc]['clm'] = logN
            ion_dict[ionc]['sig_clm'] = siglogN
    ions = ion_dict.keys()

    # Now Table 2 for the extras
    with open(tab_fils[1], 'r') as f:
        flines2 = f.readlines()
    # Trim the first 10 lines
    flines2 = flines2[10:]
    # Loop
    for iline in flines2:
        isplit = iline.split('\t')
        #
        ionc = isplit[0].strip()
        if (len(ionc) == 0) or (ionc in ions):
            continue
        #
        Zion = xai.name_ion(ionc)
        ion_dict[ionc] = dict(Z=Zion[0], ion=Zion[1], sig_clm=0.)
        if isplit[4][0] == '<':
            ion_dict[ionc]['clm'] = float(isplit[4][1:])
            ion_dict[ionc]['flg_clm'] = 3
        else:
            raise ValueError('Should not get here')

    # Finish
    lls._ionclms = IonClms(idict=ion_dict)
    lls.Refs.append('Tri05')
    return lls
Exemplo n.º 12
0
def battisti12():
    '''Battisti, A. et al. 2012, ApJ, 744, 93
    HST/COS
    QSO info from Table 1
    Metal columns parsed from Table 3
    NHI from Lya
    '''
    all_lls = []
    # Grab ASCII files from ApJ
    tab_fils = [
        xa_path + "/data/LLS/battisti12.tb1.ascii",
        xa_path + "/data/LLS/battisti12.tb3.ascii"
    ]
    urls = [
        'http://iopscience.iop.org/0004-637X/744/2/93/suppdata/apj413924t1_ascii.txt',
        'http://iopscience.iop.org/0004-637X/744/2/93/suppdata/apj413924t3_ascii.txt'
    ]
    for jj, tab_fil in enumerate(tab_fils):
        chk_fil = glob.glob(tab_fil)
        if len(chk_fil) > 0:
            tab_fil = chk_fil[0]
        else:
            url = urls[jj]
            print('LLSSurvey: Grabbing table file from {:s}'.format(url))
            f = urllib2.urlopen(url)
            with open(tab_fil, "wb") as code:
                code.write(f.read())
    # QSO info
    with open(tab_fils[0], 'r') as f:
        flines1 = f.readlines()
    # Grab RA/DEC
    all_idict = []
    for iline in flines1:
        if iline[0:2] != 'SD':
            continue
        # Parse
        isplit = iline.split('\t')
        name = isplit[0].split(' ')[1]
        radec = xor.stod1(name)
        zem = float(isplit[1].strip())
        zabs = float(isplit[2].strip())
        NHI = float(isplit[3].strip()[0:4])
        sigNHI = np.array([float(isplit[3].strip()[11:])] * 2)
        # Save
        lls = LLSSystem(name=name,
                        RA=radec[0],
                        Dec=radec[1],
                        zem=zem,
                        zabs=zabs,
                        NHI=NHI,
                        sigNHI=sigNHI)
        #
        all_lls.append(lls)
        all_idict.append({})

    # Abundances
    with open(tab_fils[1], 'r') as f:
        flines3 = f.readlines()
    flines3 = flines3[5:]
    ion = None
    for iline in flines3:
        if ion == 'Ni II':
            break
        isplit = iline.split('\t')
        if isplit[0] == 'C II*':  # Skipping CII*
            continue
        # ion
        ipos = -1
        while (isplit[0][ipos] not in ['I', 'V']):
            ipos -= 1
        ion = isplit[0][0:ipos + 1 + len(isplit[0])]
        Zion = xai.name_ion(ion)
        # Loop on systems
        for kk, iis in enumerate(isplit[1:-1]):
            if iis.strip()[0] == '.':
                continue
            all_idict[kk][ion] = dict(Z=Zion[0], ion=Zion[1], sig_clm=0.)
            if iis[0] == '>':
                all_idict[kk][ion]['flg_clm'] = 2
                all_idict[kk][ion]['clm'] = float(iis[1:6])
            elif iis[0] == '<':
                all_idict[kk][ion]['flg_clm'] = 3
                all_idict[kk][ion]['clm'] = float(iis[1:])
            else:
                all_idict[kk][ion]['flg_clm'] = 1
                all_idict[kk][ion]['clm'] = float(iis[0:5])
                all_idict[kk][ion]['sig_clm'] = float(iis[-4:])

    # Return SLLS only
    for kk, lls in enumerate(all_lls):
        try:
            lls._ionclms = IonClms(idict=all_idict[kk])
        except ValueError:
            xdb.set_trace()
        lls.Refs.append('Bat12')
    fin_slls = [ills for ills in all_lls if ills.NHI < 20.3]
    return fin_slls
Exemplo n.º 13
0
def jenkins2005():
    '''Jenkins, E. et al. 2005, ApJ, 2005, 623, 767
    PHL 1811
    HST/STIS, FUSE
    Metals parsed from Table 1
      OI taken from text
      Had to input error on columns by hand (JXP)
    Total NHI from Lyman series. see Fig 3
    M/H from O/H
    '''
    # Grab ASCII file from ApJ
    tab_fil = xa_path + "/data/LLS/jenkins2005.tb1.ascii"
    chk_fil = glob.glob(tab_fil)
    if len(chk_fil) > 0:
        tab_fil = chk_fil[0]
    else:
        url = 'http://iopscience.iop.org/0004-637X/623/2/767/fulltext/61520.tb1.txt'
        print('LLSSurvey: Grabbing table file from {:s}'.format(url))
        f = urllib2.urlopen(url)
        with open(tab_fil, "wb") as code:
            code.write(f.read())
    # Setup
    radec = xor.stod1('J215501.5152-092224.688')  # SIMBAD
    lls = LLSSystem(name='PHL1811_z0.081',
                    RA=radec[0],
                    Dec=radec[1],
                    zem=0.192,
                    zabs=0.080923,
                    vlim=[-100., 100.] * u.km / u.s,
                    NHI=17.98,
                    MH=-0.19,
                    sigNHI=np.array([0.05, 0.05]))

    # AbsLines
    ism = LineList('ISM')
    Nsig = {
        'C IV': 0.4,
        'N II': 0.4,
        'Si II': 0.05,
        'Si IV': 0.25,
        'S II': 0.2,
        'Fe II': 0.12,
        'H I': 0.05,
        'S III': 0.06
    }

    # Parse Table
    with open(tab_fil, 'r') as f:
        flines = f.readlines()
    ion_dict = {}
    for iline in flines:
        iline = iline.strip()
        if (len(iline) == 0):
            continue
        # Split on tabs
        isplit = iline.split('\t')
        # Offset?
        ioff = 0
        if isplit[0][0] in ['1', '2']:
            ioff = -1
        # Catch bad lines
        if (isplit[1 + ioff][0:6]
                in ['1442.0', '1443.7',
                    '1120.9']):  # Skip goofy CII line and CII*
            continue
        if len(isplit[2 + ioff]) == 0:
            continue
        # Ion
        if (len(isplit[0].strip()) > 0) & (isplit[0][0] not in ['1', '2']):
            ionc = isplit[0].strip()
            try:
                Zion = xai.name_ion(ionc)
            except KeyError:
                xdb.set_trace()
        # Generate the Line
        try:
            newline = AbsLine(float(isplit[2 + ioff]) * u.AA,
                              linelist=ism,
                              closest=True)
        except ValueError:
            xdb.set_trace()
        newline.attrib['z'] = lls.zabs
        # Spectrum
        newline.analy['datafile'] = 'STIS' if 'S' in isplit[1] else 'FUSE'
        # EW
        try:
            EWvals = isplit[4 + ioff].split(' ')
        except IndexError:
            xdb.set_trace()
        newline.attrib['EW'] = float(EWvals[0]) * u.AA / 1e3
        newline.attrib['EWsig'] = float(EWvals[2]) * u.AA / 1e3
        newline.attrib['flgEW'] = 1
        if len(isplit) < (5 + ioff + 1):
            continue
        # Colm?
        #xdb.set_trace()
        if (len(isplit[5 + ioff].strip()) > 0) & (isplit[5 + ioff].strip() !=
                                                  '\\ldots'):
            if isplit[5 + ioff][0] == '\\':
                ipos = isplit[5 + ioff].find(' ')
                newline.attrib['N'] = float(isplit[5 + ioff][ipos + 1:])
                newline.attrib['flagN'] = 2
            elif isplit[5 + ioff][0] == '<':
                ipos = 0
                newline.attrib['N'] = float(isplit[5 + ioff][ipos + 1:])
                newline.attrib['flagN'] = 3
            elif isplit[5 + ioff][0] == '1':
                try:
                    newline.attrib['N'] = float(isplit[5 + ioff][0:5])
                except ValueError:
                    xdb.set_trace()
                newline.attrib['flagN'] = 1
                try:
                    newline.attrib['Nsig'] = Nsig[ionc]
                except KeyError:
                    print('No error for {:s}'.format(ionc))
            else:
                raise ValueError('Bad character')
            # ion_dict
            ion_dict[ionc] = dict(clm=newline.attrib['N'],
                                  sig_clm=newline.attrib['Nsig'],
                                  flg_clm=newline.attrib['flagN'],
                                  Z=Zion[0],
                                  ion=Zion[1])
        # Append
        lls.lines.append(newline)
    # Fix NI, OI
    ion_dict['O I']['clm'] = 14.47
    ion_dict['O I']['sig_clm'] = 0.05
    ion_dict['N I']['flg_clm'] = 3
    lls._ionclms = IonClms(idict=ion_dict)

    lls.Refs.append('Jen05')
    # Return
    return lls