示例#1
0
def grab_meta():
    """ Grab UVES Dall'Aglio meta table

    Returns
    -------

    """
    #
    uvesdall_meta = Table.read(os.getenv('RAW_IGMSPEC')+'/UVES_Dall/uves_dall_summ.dat', format='ascii')
    nspec = len(uvesdall_meta)
    # DATE
    #datearr = [day.split('/') for day in list(uvesdall_meta['ObsDate'])]
    #ndate = ['20'+str(day[2])+'-'+str(day[0])+'-'+str(day[1]) for day in datearr]
    t = Time(uvesdall_meta['OBS-DATE'], out_subfmt='date')  # Fixes to YYYY-MM-DD
    uvesdall_meta.add_column(Column(t.iso, name='DATE-OBS'))
    # RA/DEC
    coord = SkyCoord(ra=uvesdall_meta['RA'], dec=uvesdall_meta['DEC'], unit=(u.hour,u.deg))
    rad = [icoord.ra.value for icoord in coord]
    decd = [icoord.dec.value for icoord in coord]
    uvesdall_meta.rename_column('RA', 'RA_STR')
    uvesdall_meta.rename_column('DEC', 'DEC_STR')
    uvesdall_meta['RA_GROUP'] = rad
    uvesdall_meta['DEC_GROUP'] = decd
    # Add zem
    igmsp = IgmSpec()
    ztbl = Table(igmsp.hdf['quasars'].value)
    zem, zsource = zem_from_radec(rad, decd, ztbl)
    badz = np.where(zem < 0.1)[0]
    for ibadz in badz:
        if uvesdall_meta['NAME'][ibadz] == 'HE2243-6031':
            zem[ibadz] = 3.005
            zsource[ibadz] = 'FOP13'  # Fumagalli+13
        elif uvesdall_meta['NAME'][ibadz] == 'HE1341-1020':
            zem[ibadz] = 2.137
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        elif uvesdall_meta['NAME'][ibadz] == 'Q0002-422':
            zem[ibadz] = 2.769
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        elif uvesdall_meta['NAME'][ibadz] == 'PKS2000-330':
            zem[ibadz] = 3.786
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        else:
            raise ValueError("Should not be here")

    uvesdall_meta['zem_GROUP'] = zem
    uvesdall_meta['sig_zem'] = [0.]*nspec
    uvesdall_meta['flag_zem'] = zsource
    #
    uvesdall_meta.add_column(Column([2000.]*nspec, name='EPOCH'))
    uvesdall_meta.add_column(Column(['VLT']*nspec, name='TELESCOPE'))
    uvesdall_meta.add_column(Column(['UVES']*nspec, name='INSTR'))
    uvesdall_meta.add_column(Column(['BOTH']*nspec, name='DISPERSER'))
    uvesdall_meta.add_column(Column([45000.]*nspec, name='R'))
    uvesdall_meta['STYPE'] = str('QSO')
    # Sort
    uvesdall_meta.sort('RA_GROUP')
    # Check
    assert chk_meta(uvesdall_meta, chk_cat_only=True)
    return uvesdall_meta
示例#2
0
def grab_meta(hdf, old=False):
    """ Grab SDSS meta Table

    Returns
    -------
    meta
    """
    from specdb.zem.utils import zem_from_radec
    #sdss_meta = Table.read(os.getenv('RAW_IGMSPEC')+'/SDSS/SDSS_DR7_qso.fits.gz')
    sdss_meta = Table.read(os.getenv('RAW_IGMSPEC') + '/SDSS/dr7qso.fit.gz')
    nspec = len(sdss_meta)
    # DATE
    #t = Time(list(sdss_meta['MJD'].data), format='mjd', out_subfmt='date')  # Fixes to YYYY-MM-DD
    t = Time(list(sdss_meta['SMJD'].data), format='mjd',
             out_subfmt='date')  # Fixes to YYYY-MM-DD
    sdss_meta.add_column(Column(t.iso, name='DATE-OBS'))
    # Add a few columns
    sdss_meta.add_column(Column([2000.] * nspec, name='EPOCH'))
    sdss_meta.add_column(Column([2000.] * nspec, name='R'))
    sdss_meta.add_column(Column(['SDSS'] * nspec, name='INSTR'))
    sdss_meta.add_column(Column(['BOTH'] * nspec, name='GRATING'))
    sdss_meta.add_column(Column(['SDSS 2.5-M'] * nspec, name='TELESCOPE'))
    # Rename
    if old:
        # Some of these were corrected by QPQ
        sdss_meta.rename_column('RAOBJ', 'RA')
        sdss_meta.rename_column('DECOBJ', 'DEC')
        sdss_meta.rename_column('Z_ERR', 'sig_zem')
        pdb.set_trace()
    else:
        sdss_meta.rename_column('z', 'zem_GROUP')
        sdss_meta['sig_zem'] = 0.
        sdss_meta['flag_zem'] = str('          ')
    # Fix zem
    zem, zsource = zem_from_radec(sdss_meta['RA'],
                                  sdss_meta['DEC'],
                                  hdf['quasars'].value,
                                  toler=1.0 * u.arcsec)
    gdz = zem > 0.
    sdss_meta['zem_GROUP'][gdz] = zem[gdz]
    sdss_meta['flag_zem'] = zsource
    sdss_meta['flag_zem'][~gdz] = str('SDSS-DR7')

    # Sort
    sdss_meta.sort('RA')
    # Rename
    sdss_meta.rename_column('RA', 'RA_GROUP')
    sdss_meta.rename_column('DEC', 'DEC_GROUP')
    # Add
    sdss_meta['STYPE'] = [str('QSO')] * nspec
    # Check
    assert chk_meta(sdss_meta, chk_cat_only=True)
    # Return
    return sdss_meta
示例#3
0
文件: sdss.py 项目: pyigm/igmspec
def grab_meta(hdf, old=False):
    """ Grab SDSS meta Table

    Returns
    -------
    meta
    """
    from specdb.zem.utils import zem_from_radec
    #sdss_meta = Table.read(os.getenv('RAW_IGMSPEC')+'/SDSS/SDSS_DR7_qso.fits.gz')
    sdss_meta = Table.read(os.getenv('RAW_IGMSPEC')+'/SDSS/dr7qso.fit.gz')
    nspec = len(sdss_meta)
    # DATE
    #t = Time(list(sdss_meta['MJD'].data), format='mjd', out_subfmt='date')  # Fixes to YYYY-MM-DD
    t = Time(list(sdss_meta['SMJD'].data), format='mjd', out_subfmt='date')  # Fixes to YYYY-MM-DD
    sdss_meta.add_column(Column(t.iso, name='DATE-OBS'))
    # Add a few columns
    sdss_meta.add_column(Column([2000.]*nspec, name='EPOCH'))
    sdss_meta.add_column(Column([2000.]*nspec, name='R'))
    sdss_meta.add_column(Column(['SDSS']*nspec, name='INSTR'))
    sdss_meta.add_column(Column(['BOTH']*nspec, name='GRATING'))
    sdss_meta.add_column(Column(['SDSS 2.5-M']*nspec, name='TELESCOPE'))
    # Rename
    if old:
        # Some of these were corrected by QPQ
        sdss_meta.rename_column('RAOBJ', 'RA')
        sdss_meta.rename_column('DECOBJ', 'DEC')
        sdss_meta.rename_column('Z_ERR', 'sig_zem')
        pdb.set_trace()
    else:
        sdss_meta.rename_column('z', 'zem_GROUP')
        sdss_meta['sig_zem'] = 0.
        sdss_meta['flag_zem'] = str('          ')
    # Fix zem
    zem, zsource = zem_from_radec(sdss_meta['RA'], sdss_meta['DEC'], hdf['quasars'].value, toler=1.0*u.arcsec)
    gdz = zem > 0.
    sdss_meta['zem_GROUP'][gdz] = zem[gdz]
    sdss_meta['flag_zem'] = zsource
    sdss_meta['flag_zem'][~gdz] = str('SDSS-DR7')

    # Sort
    sdss_meta.sort('RA')
    # Rename
    sdss_meta.rename_column('RA', 'RA_GROUP')
    sdss_meta.rename_column('DEC', 'DEC_GROUP')
    # Add
    sdss_meta['STYPE'] = [str('QSO')]*nspec
    # Check
    assert chk_meta(sdss_meta, chk_cat_only=True)
    # Return
    return sdss_meta
示例#4
0
def grab_meta():
    """ Grab COS-Halos meta table
    Returns
    -------

    """
    from time import strptime
    from specdb.zem.utils import zem_from_radec
    from specdb.specdb import IgmSpec
    from specdb.defs import get_res_dicts
    Rdicts = get_res_dicts()
    igmsp = IgmSpec(db_file=os.getenv('SPECDB')+'/IGMspec_DB_v01.hdf5', skip_test=True)

    summ_file = os.getenv('RAW_IGMSPEC')+'/COS-Halos/cos_halos_obs.ascii'
    chalos_meta = Table.read(summ_file, format='ascii')
    # RA/DEC, DATE
    # Visits from this page: http://www.stsci.edu/cgi-bin/get-visit-status?id=11598&markupFormat=html
    visit_file = os.getenv('RAW_IGMSPEC')+'/COS-Halos/cos_halos_visits.ascii'
    ch_visits = Table.read(visit_file,format='ascii')
    ra = []
    dec = []
    datet = []
    for row in chalos_meta:
        coord = ltu.radec_to_coord(row['QSO'])
        ra.append(coord.ra.value)
        dec.append(coord.dec.value)
        #
        visit = row['Visit']
        mtv = np.where(ch_visits['Visit'] == visit)[0]
        if len(mtv) != 1:
            pdb.set_trace()
        else:
            chv = ch_visits['Start_UT'][mtv].data[0]
        icmma = chv.find(',')
        datet.append('{:s}-{:02d}-{:02d}'.format(
                chv[icmma+1:icmma+5], strptime(chv[:3],'%b').tm_mon,
                int(chv[3:icmma])))
    chalos_meta.add_column(Column(ra, name='RA'))
    chalos_meta.add_column(Column(dec, name='DEC'))
    chalos_meta.add_column(Column(datet, name='DATE-OBS'))
    # Others
    chalos_meta.add_column(Column(['      ']*len(chalos_meta), name='TELESCOPE')) # Padding
    chalos_meta.add_column(Column(['     ']*len(chalos_meta), name='INSTR')) # Padding for HIRES
    chalos_meta.add_column(Column(['G130M/G160M']*len(chalos_meta), name='DISPERSER'))
    chalos_meta.add_column(Column([20000.]*len(chalos_meta), name='R'))
    chalos_meta.add_column(Column([2000.]*len(chalos_meta), name='EPOCH'))
    chalos_meta['INSTR'] = 'COS' # Deals with padding
    chalos_meta['TELESCOPE'] = 'HST'
    # Myers for zem
    zem, zsource = zem_from_radec(chalos_meta['RA'], chalos_meta['DEC'], Table(igmsp.hdf['quasars'].value))
    badz = zem <= 0.
    if np.sum(badz) > 0:
        raise ValueError("Bad zem in COS-Halos")
    chalos_meta['zem'] = zem
    chalos_meta['sig_zem'] = 0.  # Need to add
    chalos_meta['flag_zem'] = zsource
    # HIRES
    hires_files = glob.glob(os.getenv('RAW_IGMSPEC')+'/COS-Halos/HIRES/J*f.fits.gz')
    hires_tab = chalos_meta[0:0]
    subnm = np.array([row['QSO'][4:9] for row in chalos_meta])
    signs = np.array([row['QSO'][14] for row in chalos_meta])
    for ifile in hires_files:
        print(ifile)
        fname = ifile.split('/')[-1]
        mt = np.where((subnm == fname[0:5]) & (signs == fname[5]))[0]
        if len(mt) != 1:
            pdb.set_trace()
        # Add row
        hires_tab.add_row(chalos_meta[mt[0]])
        hires_tab[-1]['INSTR'] = 'HIRES'
        hires_tab[-1]['TELESCOPE'] = 'Keck I'
        hires_tab[-1]['DISPERSER'] = 'Red'
        hires_tab[-1]['R'] = Rdicts['HIRES']['C1']
    # Combine
    chalos_meta = vstack([chalos_meta, hires_tab])
    chalos_meta['STYPE'] = str('QSO')
    # Rename
    chalos_meta.rename_column('RA', 'RA_GROUP')
    chalos_meta.rename_column('DEC', 'DEC_GROUP')
    chalos_meta.rename_column('zem', 'zem_GROUP')
    # Check
    assert chk_meta(chalos_meta, chk_cat_only=True)
    # Done
    return chalos_meta
示例#5
0
def mk_meta(files, ztbl, fname=False, stype='QSO', skip_badz=False,
            mdict=None, parse_head=None, debug=False, chkz=False,
            mtbl_file=None,
            verbose=False, specdb=None, sdb_key=None, **kwargs):
    """ Generate a meta Table from an input list of files

    Parameters
    ----------
    files : list
      List of FITS files
    ztbl : Table
      Table of redshifts.  Must include RA, DEC, ZEM, ZEM_SOURCE
      Used for RA/DEC if fname=False;  then requires SPEC_FILE too
    fname : bool, optional
      Attempt to parse RA/DEC from the file name
      Format must be
      SDSSJ######(.##)+/-######(.#)[x]
        where x cannot be a #. or +/-
    stype : str, optional
      Description of object type (e.g. 'QSO', 'Galaxy', 'SN')
    specdb : SpecDB, optional
      Database object to grab ID values from
      Requires sdb_key
    sdb_key : str, optional
      ID key in SpecDB object
    skip_badz : bool, optional
      Skip spectra without a parseable redshift (using the Myers catalog)
    parse_head : dict, optional
      Parse header for meta info with this dict
    mdict : dict, optional
      Input meta data in dict form e.g.  mdict=dict(INSTR='ESI')
    chkz : bool, optional
      If any sources have no parseable redshift, hit a set_trace
    mtbl_file : str
      Filename of input meta table.  Current allowed extensions are _meta.ascii or _meta.fits
      and they must be readable by Table.read().  The values in this table will overwrite
      any others generated.  Table must include a SPEC_FILE column to link meta data

    Returns
    -------
    meta : Table
      Meta table
    """
    if specdb is not None:
        if sdb_key is None:
            raise IOError("Must specify sdb_key if you are passing in specdb")
    #
    coordlist = []
    snames = []
    for ifile in files:
        sname = ifile.split('/')[-1]
        snames.append(sname)
        if fname:
            # Starting index
            if 'SDSSJ' in ifile:
                i0 = ifile.find('SDSSJ')+4
            else:
                i0 = ifile.rfind('J')+1
            # Find end (ugly)
            for ii in range(i0+1,99999):
                if ifile[ii] in ('0','1','2','3','4','5','6','7','8','9',
                                 '.','+','-'):
                    continue
                else:
                    i1 = ii
                    break
            # Deal with .fits
            if ifile[i1-1] == '.':
                i1 -= 1
            # Get coord
            try:
                coord = ltu.radec_to_coord(ifile[i0:i1])
            except (UnboundLocalError, ValueError):
                pdb.set_trace()
        else:
            mt = np.where(ztbl['SPEC_FILE'] == sname)[0]
            if len(mt) != 1:
                raise IndexError("NO MATCH FOR {:s}".format(sname))
            coord = ltu.radec_to_coord((ztbl['RA'][mt],
                                        ztbl['DEC'][mt]))[0]
        coordlist.append(coord)
    ras = np.array([coord.ra.degree for coord in coordlist])
    decs= np.array([coord.dec.degree for coord in coordlist])
    coords = SkyCoord(ra=ras, dec=decs, unit='deg')

    # Generate maindb Table
    #maindb, tkeys = spbu.start_maindb(private=True)

    # Fill
    meta = Table()
    meta['RA_GROUP'] = coords.ra.deg
    meta['DEC_GROUP'] = coords.dec.deg
    meta['STYPE'] = [str(stype)]*len(meta)

    zem, zsource, ZQ = spzu.zem_from_radec(meta['RA_GROUP'], meta['DEC_GROUP'], 
                                           ztbl, **kwargs)
    badz = zem <= 0.
    if np.sum(badz) > 0:
        if skip_badz:
            warnings.warn("Skipping {:d} entries without a parseable redshift".format(
                np.sum(badz)))
            badz[:] = False  # Risky!
        else:
            if chkz:  # Turn this on to hit a stop instead of an Exception
                pdb.set_trace()
            else:
                raise ValueError("{:d} entries without a parseable redshift".format(
                    np.sum(badz)))
    meta['zem_GROUP'] = zem
    meta['sig_zem'] = 0.  # Need to add
    meta['flag_zem'] = zsource
    if ZQ is not None:
        meta['ZQ'] = ZQ

    # Cut?
    meta = meta[~badz]

    # specdb IDs
    if sdb_key is not None:
        meta[sdb_key] = [-9999]*len(meta)
        if sdb_key not in meta.keys():
            meta[sdb_key] = [-9999]*len(meta)
        c_igmsp = SkyCoord(ra=specdb.qcat.cat['RA'], dec=specdb.qcat.cat['DEC'], unit='deg')
        c_new = SkyCoord(ra=meta['RA_GROUP'], dec=meta['DEC_GROUP'], unit='deg')
        # Find new sources
        idx, d2d, d3d = match_coordinates_sky(c_new, c_igmsp, nthneighbor=1)
        cdict = defs.get_cat_dict()
        mtch = d2d < cdict['match_toler']
        meta[sdb_key][mtch] = specdb.qcat.cat[sdb_key][idx[mtch]]

    # Stack (primarily as a test)
    '''
    try:
        maindb = vstack([maindb,meta], join_type='exact')
    except:
        pdb.set_trace()
    '''

    # SPEC_FILE
    meta['SPEC_FILE'] = np.array(files)[~badz]
    root_names = np.array(snames)[~badz]

    # Try Header?
    if parse_head is not None:
        # Setup to store
        plist = {}
        for key in parse_head.keys():
            plist[key] = []
        # Loop on files
        for count, sfile in enumerate(meta['SPEC_FILE']):
            if verbose:
                print('Parsing {:s}'.format(sfile))
            try:
                head = fits.open(sfile)[0].header
            except FileNotFoundError:  # Try for compressed
                head = fits.open(sfile+'.gz')[0].header

            # Call it
            _ = spbu.parse_header(parse_head, head, mdict=mdict,
                              plist=plist, count=count)

            '''
            for key,item in parse_head.items():
                # R
                if key == 'R':
                    if parse_head[key] is True:
                        try:
                            plist[key].append(spbu.set_resolution(head))
                        except ValueError:
                            if mdict is not None:
                                try:
                                    plist[key].append(mdict['R'])
                                except KeyError:
                                    print("Key error!")
                                    pdb.set_trace()
                            else:
                                print('Bad inputs to set_resolution()')
                                pdb.set_trace()
                                plist[key].append(0.)
                    else:
                        raise ValueError("Set something else for R")
                elif key == 'DATE-OBS':
                    if 'MJD' in item:
                        tval = Time(head[item], format='mjd')
                        tval.format = 'iso'
                    else:
                        tval = Time(head[item].replace('/','-'), format='iso')
                    tval.out_submfit = 'date'
                    plist[key].append(tval.iso)
                else:
                    plist[key].append(head[item])

            # INSTRUMENT SPECIFIC
            try:
                instr = head['INSTRUME']
            except KeyError:
                instr = 'none'
            # LRIS
            if 'LRIS' in instr:
                # Init
                for skey in ['DISPERSER', 'INSTR', 'R']:
                    if skey not in plist.keys():
                        plist[skey] = []
                # Figure out detector
                try:
                    det = head['DETECTOR']
                except KeyError:
                    if 'BLUE' in instr:
                        det = 'LRIS-B'
                    else:
                        if head['OUTFILE'] == 'lred':
                            det = 'LRIS-R'
                        else:
                            det = 'LRIS-B'
                # Add
                if 'LRIS-R' in det:
                    if len(plist['DISPERSER']) == count:
                        plist['DISPERSER'].append(head['GRANAME'])
                    if len(plist['INSTR']) == count:
                        plist['INSTR'].append('LRISr')
                    else:
                        plist['INSTR'][-1] = 'LRISr'
                else:
                    if len(plist['DISPERSER']) == count:
                        plist['DISPERSER'].append(head['GRISNAME'])
                    if len(plist['INSTR']) == count:
                        plist['INSTR'].append('LRISb')
                    else:
                        plist['INSTR'][-1] = 'LRISb'
                # Resolution
                res = Rdicts[plist['INSTR'][-1]][plist['DISPERSER'][-1]]
                try:
                    sname = head['SLITNAME']
                except KeyError:
                    swidth = 1.
                else:
                    swidth = defs.slit_width(sname, LRIS=True)
                plist['R'].append(res/swidth)
            '''

        # Finish
        for key in plist.keys():
            try:
                meta[key] = plist[key]
            except:
                embed(header='338 of private')
    # mdict
    if mdict is not None:
        for key,item in mdict.items():
            meta[key] = [item]*len(meta)

    # EPOCH
    if 'EPOCH' not in meta.keys():
        warnings.warn("EPOCH not defined.  Filling with 2000.")
        meta['EPOCH'] = 2000.

    # GROUP ID
    meta['GROUP_ID'] = np.arange(len(meta)).astype(int)

    # Fill in empty columns with warning
    mkeys = meta.keys()
    req_clms = defs.get_req_clms(sdb_key=sdb_key)
    for clm in req_clms:
        if clm not in mkeys:
            if clm not in ['NPIX','WV_MIN','WV_MAX']:  # File in ingest_spec
                warnings.warn("Meta Column {:s} not defined.  Filling with DUMMY".format(clm))
                if clm == 'DATE-OBS':
                    meta[clm] = ['9999-1-1']*len(meta)
                else:
                    meta[clm] = ['DUMMY']*len(meta)

    # Input meta table
    if mtbl_file is not None:
        # Read
        if '_meta.ascii' in mtbl_file:
            imtbl = Table.read(mtbl_file, format='ascii')
        elif '_meta.fits' in mtbl_file:
            imtbl = Table.read(mtbl_file)
        else:
            raise IOError("Input meta table must have either an ascii or fits extension")
        # Check length
        if len(imtbl) != len(meta):
            raise IOError("Input meta table must have same length as self-generated one")
        # Check for SPEC_FILE
        if 'SPEC_FILE' not in imtbl.keys():
            raise ValueError("Input meta table must include SPEC_FILE column")
        # Loop to get indices
        idx = []
        for row in imtbl:
            imt = np.where(root_names == row['SPEC_FILE'])[0]
            if len(imt) == 0:
                print("No match to spec file {:s}.  Will ignore".format(row['SPEC_FILE']))
            elif len(imt) == 1:
                idx.append(imt[0])
            else:
                raise ValueError("Two entries with the same SPEC_FILE.  Something went wrong..")
        idx = np.array(idx)
        # Loop on keys
        for key in imtbl.keys():
            # Skip?
            if key in ['SPEC_FILE']:
                continue
            if key in meta.keys():
                pdb.set_trace()
            else:
                # Add Column
                meta.add_column(imtbl[key][idx])
    # Return
    if debug:
        meta[['RA_GROUP', 'DEC_GROUP', 'SPEC_FILE']].pprint(max_width=120)
        pdb.set_trace()
    return meta
示例#6
0
def grab_meta():
    """ Grab COS-Halos meta table
    Returns
    -------

    """
    from time import strptime
    from specdb.zem.utils import zem_from_radec
    from specdb.specdb import IgmSpec
    from specdb.defs import get_res_dicts
    Rdicts = get_res_dicts()
    igmsp = IgmSpec(db_file=os.getenv('SPECDB') + '/IGMspec_DB_v01.hdf5',
                    skip_test=True)

    summ_file = os.getenv('RAW_IGMSPEC') + '/COS-Halos/cos_halos_obs.ascii'
    chalos_meta = Table.read(summ_file, format='ascii')
    # RA/DEC, DATE
    # Visits from this page: http://www.stsci.edu/cgi-bin/get-visit-status?id=11598&markupFormat=html
    visit_file = os.getenv('RAW_IGMSPEC') + '/COS-Halos/cos_halos_visits.ascii'
    ch_visits = Table.read(visit_file, format='ascii')
    ra = []
    dec = []
    datet = []
    for row in chalos_meta:
        coord = ltu.radec_to_coord(row['QSO'])
        ra.append(coord.ra.value)
        dec.append(coord.dec.value)
        #
        visit = row['Visit']
        mtv = np.where(ch_visits['Visit'] == visit)[0]
        if len(mtv) != 1:
            pdb.set_trace()
        else:
            chv = ch_visits['Start_UT'][mtv].data[0]
        icmma = chv.find(',')
        datet.append('{:s}-{:02d}-{:02d}'.format(
            chv[icmma + 1:icmma + 5],
            strptime(chv[:3], '%b').tm_mon, int(chv[3:icmma])))
    chalos_meta.add_column(Column(ra, name='RA'))
    chalos_meta.add_column(Column(dec, name='DEC'))
    chalos_meta.add_column(Column(datet, name='DATE-OBS'))
    # Others
    chalos_meta.add_column(
        Column(['      '] * len(chalos_meta), name='TELESCOPE'))  # Padding
    chalos_meta.add_column(Column(['     '] * len(chalos_meta),
                                  name='INSTR'))  # Padding for HIRES
    chalos_meta.add_column(
        Column(['G130M/G160M'] * len(chalos_meta), name='DISPERSER'))
    chalos_meta.add_column(Column([20000.] * len(chalos_meta), name='R'))
    chalos_meta.add_column(Column([2000.] * len(chalos_meta), name='EPOCH'))
    chalos_meta['INSTR'] = 'COS'  # Deals with padding
    chalos_meta['TELESCOPE'] = 'HST'
    # Myers for zem
    zem, zsource = zem_from_radec(chalos_meta['RA'], chalos_meta['DEC'],
                                  Table(igmsp.hdf['quasars'].value))
    badz = zem <= 0.
    if np.sum(badz) > 0:
        raise ValueError("Bad zem in COS-Halos")
    chalos_meta['zem'] = zem
    chalos_meta['sig_zem'] = 0.  # Need to add
    chalos_meta['flag_zem'] = zsource
    # HIRES
    hires_files = glob.glob(
        os.getenv('RAW_IGMSPEC') + '/COS-Halos/HIRES/J*f.fits.gz')
    hires_tab = chalos_meta[0:0]
    subnm = np.array([row['QSO'][4:9] for row in chalos_meta])
    signs = np.array([row['QSO'][14] for row in chalos_meta])
    for ifile in hires_files:
        print(ifile)
        fname = ifile.split('/')[-1]
        mt = np.where((subnm == fname[0:5]) & (signs == fname[5]))[0]
        if len(mt) != 1:
            pdb.set_trace()
        # Add row
        hires_tab.add_row(chalos_meta[mt[0]])
        hires_tab[-1]['INSTR'] = 'HIRES'
        hires_tab[-1]['TELESCOPE'] = 'Keck I'
        hires_tab[-1]['DISPERSER'] = 'Red'
        hires_tab[-1]['R'] = Rdicts['HIRES']['C1']
    # Combine
    chalos_meta = vstack([chalos_meta, hires_tab])
    chalos_meta['STYPE'] = str('QSO')
    # Rename
    chalos_meta.rename_column('RA', 'RA_GROUP')
    chalos_meta.rename_column('DEC', 'DEC_GROUP')
    chalos_meta.rename_column('zem', 'zem_GROUP')
    # Check
    assert chk_meta(chalos_meta, chk_cat_only=True)
    # Done
    return chalos_meta
示例#7
0
def grab_meta():
    """ Grab UVES Dall'Aglio meta table

    Returns
    -------

    """
    #
    uvesdall_meta = Table.read(os.getenv('RAW_IGMSPEC') +
                               '/UVES_Dall/uves_dall_summ.dat',
                               format='ascii')
    nspec = len(uvesdall_meta)
    # DATE
    #datearr = [day.split('/') for day in list(uvesdall_meta['ObsDate'])]
    #ndate = ['20'+str(day[2])+'-'+str(day[0])+'-'+str(day[1]) for day in datearr]
    t = Time(uvesdall_meta['OBS-DATE'],
             out_subfmt='date')  # Fixes to YYYY-MM-DD
    uvesdall_meta.add_column(Column(t.iso, name='DATE-OBS'))
    # RA/DEC
    coord = SkyCoord(ra=uvesdall_meta['RA'],
                     dec=uvesdall_meta['DEC'],
                     unit=(u.hour, u.deg))
    rad = [icoord.ra.value for icoord in coord]
    decd = [icoord.dec.value for icoord in coord]
    uvesdall_meta.rename_column('RA', 'RA_STR')
    uvesdall_meta.rename_column('DEC', 'DEC_STR')
    uvesdall_meta['RA_GROUP'] = rad
    uvesdall_meta['DEC_GROUP'] = decd
    # Add zem
    igmsp = IgmSpec()
    ztbl = Table(igmsp.hdf['quasars'].value)
    zem, zsource = zem_from_radec(rad, decd, ztbl)
    badz = np.where(zem < 0.1)[0]
    for ibadz in badz:
        if uvesdall_meta['NAME'][ibadz] == 'HE2243-6031':
            zem[ibadz] = 3.005
            zsource[ibadz] = 'FOP13'  # Fumagalli+13
        elif uvesdall_meta['NAME'][ibadz] == 'HE1341-1020':
            zem[ibadz] = 2.137
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        elif uvesdall_meta['NAME'][ibadz] == 'Q0002-422':
            zem[ibadz] = 2.769
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        elif uvesdall_meta['NAME'][ibadz] == 'PKS2000-330':
            zem[ibadz] = 3.786
            zsource[ibadz] = 'Dall08'  # Dall'Aglio+08
        else:
            raise ValueError("Should not be here")

    uvesdall_meta['zem_GROUP'] = zem
    uvesdall_meta['sig_zem'] = [0.] * nspec
    uvesdall_meta['flag_zem'] = zsource
    #
    uvesdall_meta.add_column(Column([2000.] * nspec, name='EPOCH'))
    uvesdall_meta.add_column(Column(['VLT'] * nspec, name='TELESCOPE'))
    uvesdall_meta.add_column(Column(['UVES'] * nspec, name='INSTR'))
    uvesdall_meta.add_column(Column(['BOTH'] * nspec, name='DISPERSER'))
    uvesdall_meta.add_column(Column([45000.] * nspec, name='R'))
    uvesdall_meta['STYPE'] = str('QSO')
    # Sort
    uvesdall_meta.sort('RA_GROUP')
    # Check
    assert chk_meta(uvesdall_meta, chk_cat_only=True)
    return uvesdall_meta