Fussing with the Garnett data products


In [1]:
# imports
import numpy as np

from pkg_resources import resource_filename

from astropy.table import Table, MaskedColumn

from specdb.cat_utils import match_ids

from dla_cnn import io as dla_io


read_sets: Using set file -- 
  /home/xavier/local/Python/linetools/linetools/lists/sets/llist_v1.2.ascii
Loading abundances from Asplund2009
Abundances are relative by number on a logarithmic scale with H=12
/home/xavier/local/Python/linetools/linetools/lists/linelist.py:402: RuntimeWarning: divide by zero encountered in log10
  self._extra_table['log(w*f)'] = np.log10(qm_strength)

Check original tables


In [2]:
g16_abs = dla_io.load_garnett16(orig=True)

In [3]:
g16_abs.keys()


Out[3]:
['THINGID',
 'SDSS',
 'Plate',
 'MJD',
 'Fiber',
 'RAdeg',
 'DEdeg',
 'z_QSO',
 'SNRSpec',
 'b_z_DLA',
 'B_z_DLA',
 'log.pnDLA',
 'log.pDLA',
 'log.pDnDLA',
 'log.pDDLA',
 'pnDLAD',
 'pDLAD',
 'z_DLA',
 'log.NHI',
 'flg_BAL',
 'SNR']

Convert MNRAS tables to something useful

Read

Table 1


In [4]:
tbl1_file = resource_filename('dla_cnn', 'catalogs/boss_dr12/MNRAS/table1.dat')

In [5]:
tbl1 = Table.read(tbl1_file, format='ascii')

In [6]:
tbl1[0:5]


Out[6]:
<Table length=5>
THINGIDSDSSPlateMJDFiberRAdegDEdegz_QSOSNRflg_BAL
int64str18int64int64int64float64float64float64float64int64
268514930000000.45+174625.46173562385280.001898317.77373912.30910.77950
245101352000000.66+145828.86177562685950.002756414.97467552.49793.50090
154279486000000.97+044947.24415558314640.00405244.82978061.61887.11021000
62145359000001.27-020159.74354558106780.005317-2.03327331.36046.19811000
66692618000001.37-011930.04354558106460.0057462-1.32500882.3288.25770

Table 2


In [7]:
tbl2_file = resource_filename('dla_cnn', 'catalogs/boss_dr12/MNRAS/table2.dat')

In [8]:
tbl2 = Table.read(tbl2_file, format='ascii')


WARNING: OverflowError converting to FloatType in column pDLAD, possibly resulting in degraded precision. [astropy.io.ascii.fastbasic]

In [9]:
tbl2[0:5]


Out[9]:
<Table length=5>
THINGIDzminzmaxlog.pnDLAlog.pDLAlog.pDnDLAlog.pDDLApnDLADpDLADz_DLAlog.NHI
int64float64float64float64float64float64float64float64float64float64float64
2685149301.96542.2989-0.03081-3.49537-1043.59-1042.560.9196610.08033892.21620.0077
2451013521.96612.4877-0.04589-3.10426-621.961-609.0725.37594e-050.9999461.99720.0544
666926181.95522.318-0.03247-3.44363-345.637-350.0970.9996180.0003815291.99720.0038
3741076231.93282.3666-0.03603-3.34124-1074.77-1079.590.9997030.0002969011.943820.0021
2374109362.5443.7018-0.10786-2.28033-579.993-588.6180.999982.04506e-052.800520.0045

In [10]:
len(tbl1), len(tbl2)


Out[10]:
(297301, 162858)

Match em up


In [11]:
match_ids?

In [12]:
rows = match_ids(tbl2['THINGID'], tbl1['THINGID'])

Add the columns


In [13]:
for key in tbl2.keys():
    if key == 'THINGID':
        continue
    # 
    print('adding column {:s}'.format(key))
    new_clm = MaskedColumn(-999.*np.ones_like(tbl1['RAdeg']))
    new_clm[rows] = tbl2[key]
    # Mask it
    msk = new_clm == -999.
    new_clm.mask[msk] = True
    # Add it
    tbl1.add_column(new_clm, name=key)


adding column zmin
INFO: Upgrading Table to masked Table. Use Table.filled() to convert to unmasked table. [astropy.table.table]
adding column zmax
adding column log.pnDLA
adding column log.pDLA
adding column log.pDnDLA
adding column log.pDDLA
adding column pnDLAD
adding column pDLAD
adding column z_DLA
adding column log.NHI

In [14]:
tbl1[0:5]


Out[14]:
<Table masked=True length=5>
THINGIDSDSSPlateMJDFiberRAdegDEdegz_QSOSNRflg_BALzminzmaxlog.pnDLAlog.pDLAlog.pDnDLAlog.pDDLApnDLADpDLADz_DLAlog.NHI
int64str18int64int64int64float64float64float64float64int64float64float64float64float64float64float64float64float64float64float64
268514930000000.45+174625.46173562385280.001898317.77373912.30910.779501.96542.2989-0.03081-3.49537-1043.59-1042.560.9196610.08033892.21620.0077
245101352000000.66+145828.86177562685950.002756414.97467552.49793.500901.96612.4877-0.04589-3.10426-621.961-609.0725.37594e-050.9999461.99720.0544
154279486000000.97+044947.24415558314640.00405244.82978061.61887.11021000--------------------
62145359000001.27-020159.74354558106780.005317-2.03327331.36046.19811000--------------------
66692618000001.37-011930.04354558106460.0057462-1.32500882.3288.257701.95522.318-0.03247-3.44363-345.637-350.0970.9996180.0003815291.99720.0038

Write


In [15]:
merged_file = resource_filename('dla_cnn', 'catalogs/boss_dr12/MNRAS/merged_g16.fits')

In [16]:
tbl1.write(merged_file)

In [ ]: