Exemplo n.º 1
0
def rest_allspec_readin(version='DR7'):
    ''' Read in all All_in_One (AIO) files and make a gigantic AIO array
    '''

    # Read in the catalog
    objs_ori = absorber_readin(version)
    nobj = objs_ori.size

    # Read in master wavelength grid
    master_wave = (aio.allinone_wave_readin())[0]['WAVE']
    master_loglam = np.log10(master_wave)
    nwave = master_wave.size

    # Initialization, nobj second dimension because of NMF convention
    rest_allflux = np.zeros((nwave, nobj))
    rest_allivar = np.zeros((nwave, nobj))

    bands = _allinone_rest_bands
    for thisband in bands:
        data = allinone_rest_readin_band(thisband, version)
        index_wave = data['INDEX_WAVE']
        index_obj = data['INDEX_OBJ']
        rest_allflux[index_wave[0]:index_wave[1], index_obj] = data['FLUX']
        rest_allivar[index_wave[0]:index_wave[1], index_obj] = data['IVAR']

    return (master_wave, rest_allflux, rest_allivar)
Exemplo n.º 2
0
def rest_allspec_readin():

    # read in the elg catalog
    objs_ori = elg_readin()
    nobj = objs_ori.size
   
    # read in master wavelength grid
    master_wave = (aio.allinone_wave_readin())[0]['WAVE']
    master_loglam = np.log10(master_wave)
    nwave = master_wave.size

    # initialization, nobj second dimension because of NMF traditions
    rest_allflux = np.zeros((nwave, nobj))
    rest_allivar = np.zeros((nwave, nobj))

    bands = _allinone_rest_bands
    for thisband in bands:
        data = allinone_rest_readin_band(thisband)
        index_wave = data['INDEX_WAVE']
        index_obj = data['INDEX_OBJ']
        rest_allflux[index_wave[0]:index_wave[1], index_obj] = data['FLUX']
        rest_allivar[index_wave[0]:index_wave[1], index_obj] = data['IVAR']

    master_wave = master_wave*(1.+_zcorr)
    return (master_wave, rest_allflux, rest_allivar)
Exemplo n.º 3
0
def rest_allspec(version='DR7', overwrite=False):
    """Make the All_in_One (AIO) file in the rest frame
    Load and interpolate *ALL* Absorber spectra on to the same rest-frame wavelength grid
    """

    # Spectra directory
    path0 = join(datapath.nmf_path(), '107')
    if version == 'DR7':
        path = join(path0, 'Decompose')
    elif version == 'DR12':
        path = join(path0, 'Decompose_DR12')
    else:
        raise IOError(
            "Please check the data release version and the path to the decomposed spectroscopic data."
        )

    # Check All_in_One (AIO) output files
    bands = _allinone_rest_bands
    for thisband in bands:
        # Check outfiles
        outfile = allinone_rest_filename(thisband, version)
        if isfile(outfile) and not overwrite:
            print("File {0} exists. Use overwrite to overwrite it.".format(
                outfile))
            return -1

    # Read in the catalog
    objs_ori = absorber_readin(version)
    nobj = objs_ori.size

    # Make a temporary new catalog, universal
    objs_dtype = [('PLATE', 'i4'), ('MJD', 'i4'), ('FIBER', 'i4'),
                  ('RA', 'f8'), ('DEC', 'f8'), ('Z', 'f8')]
    objs = np.zeros(nobj, dtype=objs_dtype)

    # Assign the right values
    objs['PLATE'] = objs_ori['PLATE']
    objs['MJD'] = objs_ori['MJD']
    objs['FIBER'] = objs_ori['FIBER']
    objs['RA'] = objs_ori['RA']
    objs['DEC'] = objs_ori['DEC']
    objs['Z'] = objs_ori['ZABS']  # This is very important

    # Read in master wavelength grid
    master_wave = (aio.allinone_wave_readin())[0]['WAVE']
    master_loglam = np.log10(master_wave)
    nwave = master_wave.size

    # Initialization, nobj second dimension because of NMF convention
    rest_allflux = np.zeros((nwave, nobj))
    rest_allivar = np.zeros((nwave, nobj))
    # rest_allflux = np.zeros((nwave, 10)) # This is for testing
    # rest_allivar = np.zeros((nwave, 10))

    # Initialization of the progress bar
    pbar = ProgressBar(maxval=nobj).start()
    # for i in np.arange(10): # This is for testing
    for i in np.arange(nobj):
        # Progress bar
        pbar.update(i)
        tmpz = objs[i]['Z']

        # Useful wavelength range in the observer frame
        wave_pos = np.array([_minwave / (1. + tmpz), _maxwave / (1. + tmpz)])
        rest_loc = np.searchsorted(master_wave, wave_pos)
        tmp_loglam = master_loglam[rest_loc[0]:rest_loc[1]]

        # Read in and interpolate
        tmp_outflux, tmp_outivar = decompose_sdssspec.load_interp_spec(
            objs[i], tmp_loglam, path, rest=True)
        rest_allflux[rest_loc[0]:rest_loc[1], i] = tmp_outflux
        rest_allivar[rest_loc[0]:rest_loc[1], i] = tmp_outivar

    # Closing progress bar
    pbar.finish()
    # raise ValueError("Stop here")
    # Write out
    print "Now I am writing everything out..."
    allinone_rest_writeout(objs,
                           master_wave,
                           rest_allflux,
                           rest_allivar,
                           version,
                           overwrite=overwrite)
Exemplo n.º 4
0
def rest_allspec(overwrite=False):
    """Load and interpolate *ALL* eBOSS ELG spectra
    on to the same rest-frame wavelength grid
    """

    path1 = join(datapath.sdss_path(), 'v5_7_6')
    path2 = join(datapath.sdss_path(), 'specDR12')

    # check output files
    bands = _allinone_rest_bands
    for thisband in bands:
        # check outfiles
        outfile = allinone_rest_filename(thisband)
        if isfile(outfile) and not overwrite:
           print "File {0} exists. Use overwrite to overwrite it.".format(outfile)
           return -1
        # print "Will write into these files: {0}".format(outfile)

    # read in the elg catalog
    objs_ori = elg_readin()
    nobj = objs_ori.size

    # make a temporary new catalog
    objs_dtype = [('PLATE', 'i4'),
                  ('MJD', 'i4'),
                  ('FIBER', 'i4'),
                  ('RA', 'f8'),
                  ('DEC', 'f8'),
                  ('Z', 'f8')]
    objs = np.zeros(nobj, dtype=objs_dtype)
    objs['PLATE'] = objs_ori['PLATE_1']
    objs['MJD'] = objs_ori['MJD']
    objs['FIBER'] = objs_ori['FIBERID_1']
    objs['RA'] = objs_ori['PLUG_RA']
    objs['DEC'] = objs_ori['PLUG_DEC']
    objs['Z'] = objs_ori['Z']

    # read in master wavelength grid
    master_wave = (aio.allinone_wave_readin())[0]['WAVE']
    master_loglam = np.log10(master_wave)
    nwave = master_wave.size

    # initialization, nobj second dimension because of NMF traditions
    rest_allflux = np.zeros((nwave, nobj))
    rest_allivar = np.zeros((nwave, nobj))
    #rest_allflux = np.zeros((nwave, 10))
    #rest_allivar = np.zeros((nwave, 10))

    # Progress bar
    pbar = ProgressBar(maxval=nobj).start()
    #for i in np.arange(10):
    for i in np.arange(nobj):
        # Progress bar
        pbar.update(i)

        tmpz = objs[i]['Z']

        # Wavelength
        wave_pos = np.array([3600./(1.+tmpz), 10400./(1.+tmpz)])
        rest_loc = np.searchsorted(master_wave, wave_pos)
        tmp_loglam = master_loglam[rest_loc[0]:rest_loc[1]]

        # read and interpolate
        try:
            tmp_outflux, tmp_outivar = sdssspec.load_interp_spec(objs[i], tmp_loglam, path1, rest=True)
            rest_allflux[rest_loc[0]:rest_loc[1],i] = tmp_outflux
            rest_allivar[rest_loc[0]:rest_loc[1],i] = tmp_outivar
        except (IndexError, TypeError, NameError, ValueError):
            try:
                tmp_outflux, tmp_outivar = sdssspec.load_interp_spec(objs[i], tmp_loglam, path2, rest=True)
                rest_allflux[rest_loc[0]:rest_loc[1],i] = tmp_outflux
                rest_allivar[rest_loc[0]:rest_loc[1],i] = tmp_outivar
            except (IndexError, TypeError, NameError, ValueError):
                print("Error reading plate {0} mjd {1} fiber {2}".format(objs[i]['PLATE'], objs[i]['MJD'], objs[i]['FIBER']))

        # output

    #Progress bar
    pbar.finish()

    # write out
    print "Now I am writing everything out..."
    allinone_rest_writeout(objs, master_wave, rest_allflux, rest_allivar, overwrite=overwrite)
Exemplo n.º 5
0
def rest_allspec(overwrite=False):
    """Load and interpolate *ALL* HST FOS/GHRS starburst spectra
    on to the same rest-frame wavelength grid
    """

    path = join(datapath.hstfos_path(), _subpath, 'corrected')

    # check output files
    bands = _allinone_rest_bands
    for thisband in bands:
        # check outfiles
        outfile = allinone_rest_filename(thisband)
        if isfile(outfile) and not overwrite:
           print "File {0} exists. Use overwrite to overwrite it.".format(outfile)
           return -1
        # print "Will write into these files: {0}".format(outfile)

    # read in the starburst catalog
    objs_ori = starburst_readin()
    nobj = objs_ori.size

    # make a temporary new catalog
    objs_dtype = [('RA', 'f8'),
                  ('DEC', 'f8'),
                  ('Z', 'f8'),
                  ('gal', 'S15')]
    objs = np.zeros(nobj, dtype=objs_dtype)
    objs['RA'] = 0.
    objs['DEC'] = 0.
    objs['Z'] = 0.
    objs['gal'] = objs_ori['gal']

    # read in master wavelength grid
    master_wave = (aio.allinone_wave_readin())[0]['WAVE']
    master_loglam = np.log10(master_wave)
    nwave = master_wave.size

    # initialization, nobj second dimension because of NMF traditions
    rest_allflux = np.zeros((nwave, nobj))
    rest_allivar = np.zeros((nwave, nobj))

    # Wavelength
    wave_pos = np.array([1000., 3300.])
    rest_loc = np.searchsorted(master_wave, wave_pos)
    newloglam = master_loglam[rest_loc[0]:rest_loc[1]]
    flux = np.zeros((objs.size, newloglam.size))
    ivar = np.zeros((objs.size, newloglam.size))

    pbar = ProgressBar(maxval=nobj).start()
    # Progress bar
    for (iobj, thisobj)  in zip(np.arange(objs.size), objs):
        pbar.update(iobj)
        thisdata = readspec_rest(thisobj)
        inloglam = np.log10(thisdata['wave'])
        influx = thisdata['flux']
        inivar = 1./np.power(thisdata['error'], 2)
        (rest_allflux[rest_loc[0]:rest_loc[1], iobj], rest_allivar[rest_loc[0]:rest_loc[1], iobj]) = specutils.interpol_spec(inloglam, influx, inivar, newloglam)

    #Progress bar
    pbar.finish()

    # write out
    print "Now I am writing everything out..."
    allinone_rest_writeout(objs, master_wave, rest_allflux, rest_allivar, overwrite=overwrite)