fibermap['SPECTROID'] = fiberpos['SPECTROGRAPH'][0:nspec] fibermap['TARGETID'] = np.random.randint(sys.maxint, size=nspec) fibermap['TARGETCAT'] = np.zeros(nspec, dtype='|S20') fibermap['LAMBDAREF'] = np.ones(nspec, dtype=np.float32)*5400 fibermap['TARGET_MASK0'] = np.zeros(nspec, dtype='i8') fibermap['RA_TARGET'] = ra fibermap['DEC_TARGET'] = dec fibermap['X_TARGET'] = x fibermap['Y_TARGET'] = y fibermap['X_FVCOBS'] = fibermap['X_TARGET'] fibermap['Y_FVCOBS'] = fibermap['Y_TARGET'] fibermap['X_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['Y_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['RA_OBS'] = fibermap['RA_TARGET'] fibermap['DEC_OBS'] = fibermap['DEC_TARGET'] fibermap['BRICKNAME'] = brick.brickname(ra, dec) return fibermap, truth #------------------------------------------------------------------------- #- Currently unused, but keep around for now def sample_nz(objtype, n): """ Given `objtype` = 'LRG', 'ELG', 'QSO', 'STAR', 'STD' return array of `n` redshifts that properly sample n(z) from $DESIMODEL/data/targets/nz*.dat """ #- TODO: should this be in desimodel instead? #- Stars are at redshift 0 for now. Could consider a velocity dispersion.
def get_targets(nspec, tileid=None): """ Returns: fibermap truth table TODO (@moustakas): Deal with the random seed correctly. TODO: document this better """ if tileid is None: tile_ra, tile_dec = 0.0, 0.0 else: tile_ra, tile_dec = io.get_tile_radec(tileid) # - Get distribution of target types true_objtype, target_objtype = sample_objtype(nspec) # - Get DESI wavelength coverage wavemin = desimodel.io.load_throughput("b").wavemin wavemax = desimodel.io.load_throughput("z").wavemax dw = 0.2 wave = np.arange(round(wavemin, 1), wavemax, dw) nwave = len(wave) truth = dict() truth["FLUX"] = np.zeros((nspec, len(wave))) truth["REDSHIFT"] = np.zeros(nspec, dtype="f4") truth["TEMPLATEID"] = np.zeros(nspec, dtype="i4") truth["OIIFLUX"] = np.zeros(nspec, dtype="f4") truth["D4000"] = np.zeros(nspec, dtype="f4") truth["OBJTYPE"] = np.zeros(nspec, dtype="S10") # - Note: unlike other elements, first index of WAVE isn't spectrum index truth["WAVE"] = wave fibermap = empty_fibermap(nspec) for objtype in set(true_objtype): ii = np.where(true_objtype == objtype)[0] nobj = len(ii) fibermap["OBJTYPE"][ii] = target_objtype[ii] truth["OBJTYPE"][ii] = true_objtype[ii] # Simulate spectra if objtype == "SKY": continue elif objtype == "ELG": from desisim.templates import ELG elg = ELG(nmodel=nobj, wave=wave) simflux, wave1, meta = elg.make_templates() elif objtype == "LRG": from desisim.templates import LRG lrg = LRG(nmodel=nobj, wave=wave) simflux, wave1, meta = lrg.make_templates() elif objtype == "QSO": from desisim.templates import QSO qso = QSO(nmodel=nobj, wave=wave) simflux, wave1, meta = qso.make_templates() # For a "bad" QSO simulate a normal star without color cuts, which isn't # right. We need to apply the QSO color-cuts to the normal stars to pull # out the correct population of contaminating stars. elif objtype == "QSO_BAD": from desisim.templates import STAR star = STAR(nmodel=nobj, wave=wave) simflux, wave1, meta = star.make_templates() elif objtype == "STD": from desisim.templates import STAR star = STAR(nmodel=nobj, wave=wave, FSTD=True) simflux, wave1, meta = star.make_templates() truth["FLUX"][ii] = simflux truth["TEMPLATEID"][ii] = meta["TEMPLATEID"] truth["REDSHIFT"][ii] = meta["REDSHIFT"] # Pack in the photometry. TODO: Include WISE. magg = meta["GMAG"] magr = meta["RMAG"] magz = meta["ZMAG"] fibermap["MAG"][ii, 0:3] = np.vstack([magg, magr, magz]).T fibermap["FILTER"][ii, 0:3] = ["DECAM_G", "DECAM_R", "DECAM_Z"] if objtype == "ELG": truth["OIIFLUX"][ii] = meta["OIIFLUX"] truth["D4000"][ii] = meta["D4000"] if objtype == "LRG": truth["D4000"][ii] = meta["D4000"] # - Load fiber -> positioner mapping and tile information fiberpos = desimodel.io.load_fiberpos() # - Where are these targets? Centered on positioners for now. x = fiberpos["X"][0:nspec] y = fiberpos["Y"][0:nspec] fp = FocalPlane(tile_ra, tile_dec) ra = np.zeros(nspec) dec = np.zeros(nspec) for i in range(nspec): ra[i], dec[i] = fp.xy2radec(x[i], y[i]) # - Fill in the rest of the fibermap structure fibermap["FIBER"] = np.arange(nspec, dtype="i4") fibermap["POSITIONER"] = fiberpos["POSITIONER"][0:nspec] fibermap["SPECTROID"] = fiberpos["SPECTROGRAPH"][0:nspec] fibermap["TARGETID"] = np.random.randint(sys.maxint, size=nspec) fibermap["TARGETCAT"] = np.zeros(nspec, dtype="|S20") fibermap["LAMBDAREF"] = np.ones(nspec, dtype=np.float32) * 5400 fibermap["TARGET_MASK0"] = np.zeros(nspec, dtype="i8") fibermap["RA_TARGET"] = ra fibermap["DEC_TARGET"] = dec fibermap["X_TARGET"] = x fibermap["Y_TARGET"] = y fibermap["X_FVCOBS"] = fibermap["X_TARGET"] fibermap["Y_FVCOBS"] = fibermap["Y_TARGET"] fibermap["X_FVCERR"] = np.zeros(nspec, dtype=np.float32) fibermap["Y_FVCERR"] = np.zeros(nspec, dtype=np.float32) fibermap["RA_OBS"] = fibermap["RA_TARGET"] fibermap["DEC_OBS"] = fibermap["DEC_TARGET"] fibermap["BRICKNAME"] = brick.brickname(ra, dec) return fibermap, truth
def get_targets(nspec, tileid=None): """ Returns: fibermap truth table TODO (@moustakas): Deal with the random seed correctly. TODO: document this better """ if tileid is None: tile_ra, tile_dec = 0.0, 0.0 else: tile_ra, tile_dec = io.get_tile_radec(tileid) #- Get distribution of target types true_objtype, target_objtype = sample_objtype(nspec) #- Get DESI wavelength coverage wavemin = desimodel.io.load_throughput('b').wavemin wavemax = desimodel.io.load_throughput('z').wavemax dw = 0.2 wave = np.arange(round(wavemin, 1), wavemax, dw) nwave = len(wave) truth = dict() truth['FLUX'] = np.zeros((nspec, len(wave))) truth['REDSHIFT'] = np.zeros(nspec, dtype='f4') truth['TEMPLATEID'] = np.zeros(nspec, dtype='i4') truth['OIIFLUX'] = np.zeros(nspec, dtype='f4') truth['D4000'] = np.zeros(nspec, dtype='f4') truth['VDISP'] = np.zeros(nspec, dtype='f4') truth['OBJTYPE'] = np.zeros(nspec, dtype='S10') #- Note: unlike other elements, first index of WAVE isn't spectrum index truth['WAVE'] = wave fibermap = empty_fibermap(nspec) for objtype in set(true_objtype): ii = np.where(true_objtype == objtype)[0] nobj = len(ii) fibermap['OBJTYPE'][ii] = target_objtype[ii] truth['OBJTYPE'][ii] = true_objtype[ii] # Simulate spectra if objtype == 'SKY': continue elif objtype == 'ELG': from desisim.templates import ELG elg = ELG(wave=wave) simflux, wave1, meta = elg.make_templates(nmodel=nobj) elif objtype == 'LRG': from desisim.templates import LRG lrg = LRG(wave=wave) simflux, wave1, meta = lrg.make_templates(nmodel=nobj) elif objtype == 'QSO': from desisim.templates import QSO qso = QSO(wave=wave) simflux, wave1, meta = qso.make_templates(nmodel=nobj) # For a "bad" QSO simulate a normal star without color cuts, which isn't # right. We need to apply the QSO color-cuts to the normal stars to pull # out the correct population of contaminating stars. elif objtype == 'QSO_BAD': from desisim.templates import STAR star = STAR(wave=wave) simflux, wave1, meta = star.make_templates(nmodel=nobj) elif objtype == 'STD': from desisim.templates import STAR star = STAR(wave=wave, FSTD=True) simflux, wave1, meta = star.make_templates(nmodel=nobj) truth['FLUX'][ii] = 1e17 * simflux truth['UNITS'] = '1e-17 erg/s/cm2/A' truth['TEMPLATEID'][ii] = meta['TEMPLATEID'] truth['REDSHIFT'][ii] = meta['REDSHIFT'] # Pack in the photometry. TODO: Include WISE. magg = meta['GMAG'] magr = meta['RMAG'] magz = meta['ZMAG'] fibermap['MAG'][ii, 0:3] = np.vstack([magg, magr, magz]).T fibermap['FILTER'][ii, 0:3] = ['DECAM_G', 'DECAM_R', 'DECAM_Z'] if objtype == 'ELG': truth['OIIFLUX'][ii] = meta['OIIFLUX'] truth['D4000'][ii] = meta['D4000'] truth['VDISP'][ii] = meta['VDISP'] if objtype == 'LRG': truth['D4000'][ii] = meta['D4000'] truth['VDISP'][ii] = meta['VDISP'] #- Load fiber -> positioner mapping and tile information fiberpos = desimodel.io.load_fiberpos() #- Where are these targets? Centered on positioners for now. x = fiberpos['X'][0:nspec] y = fiberpos['Y'][0:nspec] fp = FocalPlane(tile_ra, tile_dec) ra = np.zeros(nspec) dec = np.zeros(nspec) for i in range(nspec): ra[i], dec[i] = fp.xy2radec(x[i], y[i]) #- Fill in the rest of the fibermap structure fibermap['FIBER'] = np.arange(nspec, dtype='i4') fibermap['POSITIONER'] = fiberpos['POSITIONER'][0:nspec] fibermap['SPECTROID'] = fiberpos['SPECTROGRAPH'][0:nspec] fibermap['TARGETID'] = np.random.randint(sys.maxint, size=nspec) fibermap['TARGETCAT'] = np.zeros(nspec, dtype='|S20') fibermap['LAMBDAREF'] = np.ones(nspec, dtype=np.float32) * 5400 fibermap['TARGET_MASK0'] = np.zeros(nspec, dtype='i8') fibermap['RA_TARGET'] = ra fibermap['DEC_TARGET'] = dec fibermap['X_TARGET'] = x fibermap['Y_TARGET'] = y fibermap['X_FVCOBS'] = fibermap['X_TARGET'] fibermap['Y_FVCOBS'] = fibermap['Y_TARGET'] fibermap['X_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['Y_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['RA_OBS'] = fibermap['RA_TARGET'] fibermap['DEC_OBS'] = fibermap['DEC_TARGET'] fibermap['BRICKNAME'] = brick.brickname(ra, dec) return fibermap, truth
fibermap['SPECTROID'] = fiberpos['SPECTROGRAPH'][0:nspec] fibermap['TARGETID'] = np.random.randint(sys.maxint, size=nspec) fibermap['TARGETCAT'] = np.zeros(nspec, dtype='|S20') fibermap['LAMBDAREF'] = np.ones(nspec, dtype=np.float32) * 5400 fibermap['TARGET_MASK0'] = np.zeros(nspec, dtype='i8') fibermap['RA_TARGET'] = ra fibermap['DEC_TARGET'] = dec fibermap['X_TARGET'] = x fibermap['Y_TARGET'] = y fibermap['X_FVCOBS'] = fibermap['X_TARGET'] fibermap['Y_FVCOBS'] = fibermap['Y_TARGET'] fibermap['X_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['Y_FVCERR'] = np.zeros(nspec, dtype=np.float32) fibermap['RA_OBS'] = fibermap['RA_TARGET'] fibermap['DEC_OBS'] = fibermap['DEC_TARGET'] fibermap['BRICKNAME'] = brick.brickname(ra, dec) return fibermap, truth #------------------------------------------------------------------------- #- Currently unused, but keep around for now def sample_nz(objtype, n): """ Given `objtype` = 'LRG', 'ELG', 'QSO', 'STAR', 'STD' return array of `n` redshifts that properly sample n(z) from $DESIMODEL/data/targets/nz*.dat """ #- TODO: should this be in desimodel instead? #- Stars are at redshift 0 for now. Could consider a velocity dispersion.