コード例 #1
0
def sheldon_run_to_healpix():
    allruns = sheldon_pofz_filelist()
    nrun = allruns.size

    nside = 2
    npixel = hp.nside2npix(nside)
    pixels = np.arange(npixel)

    # read it out
    pbar = ProgressBar(maxval=nrun).start()
    for i, thisrun in zip(np.arange(nrun),allruns):
        pbar.update(i)
        data = read_sheldon_pofz(thisrun['FILE'])
        theta = np.pi/2.-data['dec']/180.*np.pi
        phi = data['ra']/180.*np.pi
        run_pixels = hp.ang2pix(nside, theta, phi)
        for thispixel in pixels:
            outdata = data[run_pixels==thispixel]
            if outdata.size > 1:
               subpath = os.path.join(datapath.sdss_path(), 'PhotozWeight', 'Healpix', "{0:02d}".format(thispixel))
               if not os.path.exists(subpath): os.makedirs(subpath)
               outfile = os.path.join(subpath, 'sub_'+thisrun['FILE'])
               # print("Writing {0!r}".format(outfile))
               fits = fitsio.FITS(outfile, 'rw', clobber=True)
               fits.write(outdata)
               fits.close()
コード例 #2
0
def feiimgii_composite_filename(bootstrap=False, binoii=False):
    path = datapath.sdss_path()
    if bootstrap:
        if (not binoii): 
            return join(path, 'eBOSS', _bootstrap_compositefile)
        else:
            return join(path, 'eBOSS', 'OII_'+_bootstrap_compositefile)
    else:
        if (not binoii):
            return join(path, 'eBOSS', _compositefile)
        else:
            return join(path, 'eBOSS', 'OII_'+_compositefile)
コード例 #3
0
def sheldon_healpix_uniteruns():
    nside = 2
    npixel = hp.nside2npix(nside)
    pixels = np.arange(npixel)
    #pbar = ProgressBar(maxval=npixel).start()
    for thispixel in pixels:
        #pbar.update(thispixel)
        subpath = os.path.join(datapath.sdss_path(), 'PhotozWeight', 'Healpix', "{0:02d}".format(thispixel))
        print(subpath)
        if os.path.exists(subpath):
           # find all files
           allfiles = glob(subpath+"/*.fits.gz")
           # print(allfiles)
           outdata = np.asarray([])
           for thisfile in allfiles:
               thisdata = fitsio.read(thisfile)
               if outdata.size==0:
                  outdata = thisdata
               else:
                  outdata = np.r_[outdata,thisdata]
           outfile = subpath+"/allruns_pixel{0:02d}.fits".format(thispixel)
           fits = fitsio.FITS(outfile, 'rw', clobber=True)
           fits.write(outdata)
           fits.close()
コード例 #4
0
def elg_filename(vac=False):
    path = datapath.sdss_path()
    if (not vac):
        return join(path, 'eBOSS', _elgfile)
    else:
        return join(path, 'eBOSS', 'VAGC_'+_elgfile)
コード例 #5
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)
コード例 #6
0
def read_sheldon_pofz(basefile):
    filename = os.path.join(datapath.sdss_path(), 'PhotozWeight', basefile)
    return fitsio.read(filename)
コード例 #7
0
def sheldon_pofz_filelist():
    filename = os.path.join(datapath.sdss_path(), 'PhotozWeight/allruns.fits')
    return fitsio.read(filename)