def typesel(f, type, south=True, ebvfac=1., Rv=3.1): if ebvfac == 1. and Rv == 3.1: gflux = f['FLUX_G'] / f['MW_TRANSMISSION_G'] rflux = f['FLUX_R'] / f['MW_TRANSMISSION_R'] zflux = f['FLUX_Z'] / f['MW_TRANSMISSION_Z'] w1flux = f['FLUX_W1'] / f['MW_TRANSMISSION_W1'] zfiberflux = f['FIBERFLUX_Z'] / f['MW_TRANSMISSION_Z'] else: Rg = 3.214 * ebvfac Rr = 2.165 * ebvfac Rz = 1.211 * ebvfac Rw1 = 0.184 * ebvfac if Rv < 3.1: #linear interpolation from Schlafly 2011 table Rg = (3.739 - 3.273) * (3.1 - Rv) * ebvfac + Rg Rr = (2.113 - 2.176) * (3.1 - Rv) * ebvfac + Rr Rz = (1.175 - 1.217) * (3.1 - Rv) * ebvfac + Rz Rw1 = (-.1) * (Rv - 3.1) * ebvfac + Rw1 if Rv > 3.1: #linear interpolation from Schlafly 2011 table Rg = (3.006 - 3.273) * (Rv - 3.1) * ebvfac + Rg Rr = (2.205 - 2.176) * (Rv - 3.1) * ebvfac + Rr Rz = (1.236 - 1.217) * (Rv - 3.1) * ebvfac + Rz Rw1 = (-.05) * (Rv - 3.1) * ebvfac + Rw1 print('ebvfac,Rv,Rg,Rr,Rz,Rw1') print(ebvfac, Rv, Rg, Rr, Rz, Rw1) wtg = 10**(-0.4 * Rg * f['EBV']) wtr = 10**(-0.4 * Rr * f['EBV']) wtz = 10**(-0.4 * Rz * f['EBV']) wtw = 10**(-0.4 * Rw1 * f['EBV']) gflux = f['FLUX_G'] / wtg rflux = f['FLUX_R'] / wtr zflux = f['FLUX_Z'] / wtz w1flux = f['FLUX_W1'] / wtw zfiberflux = f['FIBERFLUX_Z'] / wtz if type == 'LRG': w = cuts.isLRG_colors(gflux, rflux, zflux, w1flux, zfiberflux, south=south) if type == 'ELG': w = cuts.isELG_colors(gflux, rflux, zflux, w1flux, zfiberflux, south=south) return w
def test_single_cuts(self): """Test cuts of individual target classes """ targets = Table.read(self.sweepfiles[0]) flux = cuts.unextinct_fluxes(targets) gflux = flux['GFLUX'] rflux = flux['RFLUX'] zflux = flux['ZFLUX'] w1flux = flux['W1FLUX'] w2flux = flux['W2FLUX'] zfiberflux = flux['ZFIBERFLUX'] gfluxivar = targets['FLUX_IVAR_G'] rfluxivar = targets['FLUX_IVAR_R'] zfluxivar = targets['FLUX_IVAR_Z'] gsnr = targets['FLUX_G'] * np.sqrt(targets['FLUX_IVAR_G']) rsnr = targets['FLUX_R'] * np.sqrt(targets['FLUX_IVAR_R']) zsnr = targets['FLUX_Z'] * np.sqrt(targets['FLUX_IVAR_Z']) w1snr = targets['FLUX_W1'] * np.sqrt(targets['FLUX_IVAR_W1']) w2snr = targets['FLUX_W2'] * np.sqrt(targets['FLUX_IVAR_W2']) dchisq = targets['DCHISQ'] deltaChi2 = dchisq[..., 0] - dchisq[..., 1] gnobs, rnobs, znobs = targets['NOBS_G'], targets['NOBS_R'], targets[ 'NOBS_Z'] gallmask = targets['ALLMASK_G'] rallmask = targets['ALLMASK_R'] zallmask = targets['ALLMASK_Z'] gfracflux = targets['FRACFLUX_G'] rfracflux = targets['FRACFLUX_R'] zfracflux = targets['FRACFLUX_Z'] gfracmasked = targets['FRACMASKED_G'] rfracmasked = targets['FRACMASKED_R'] zfracmasked = targets['FRACMASKED_Z'] gfracin = targets['FRACIN_G'] rfracin = targets['FRACIN_R'] zfracin = targets['FRACIN_Z'] maskbits = targets['MASKBITS'] gaiagmag = targets['GAIA_PHOT_G_MEAN_MAG'] Grr = gaiagmag - 22.5 + 2.5 * np.log10(targets['FLUX_R']) if 'BRICK_PRIMARY' in targets.colnames: primary = targets['BRICK_PRIMARY'] else: primary = np.ones_like(gflux, dtype='?') lrg1 = cuts.isLRG(primary=primary, gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, zfiberflux=zfiberflux, rflux_snr=rsnr, zflux_snr=zsnr, w1flux_snr=w1snr) lrg2 = cuts.isLRG(primary=None, gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, zfiberflux=zfiberflux, rflux_snr=rsnr, zflux_snr=zsnr, w1flux_snr=w1snr) self.assertTrue(np.all(lrg1 == lrg2)) # ADM also check that the color selections alone work. This tripped us up once # ADM with the mocks part of the code calling a non-existent LRG colors function. lrg1 = cuts.isLRG_colors(primary=primary, gflux=gflux, rflux=rflux, zflux=zflux, zfiberflux=zfiberflux, w1flux=w1flux, w2flux=w2flux) lrg2 = cuts.isLRG_colors(primary=None, gflux=gflux, rflux=rflux, zflux=zflux, zfiberflux=zfiberflux, w1flux=w1flux, w2flux=w2flux) self.assertTrue(np.all(lrg1 == lrg2)) elg1 = cuts.isELG(gflux=gflux, rflux=rflux, zflux=zflux, gsnr=gsnr, rsnr=rsnr, zsnr=zsnr, gnobs=gnobs, rnobs=rnobs, znobs=znobs, maskbits=maskbits, primary=primary) elg2 = cuts.isELG(gflux=gflux, rflux=rflux, zflux=zflux, gsnr=gsnr, rsnr=rsnr, zsnr=zsnr, gnobs=gnobs, rnobs=rnobs, znobs=znobs, maskbits=maskbits, primary=None) self.assertTrue(np.all(elg1 == elg2)) elg1 = cuts.isELG_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=primary) elg2 = cuts.isELG_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=None) self.assertTrue(np.all(elg1 == elg2)) for targtype in ["bright", "faint", "wise"]: bgs = [] for primary in [primary, None]: bgs.append( cuts.isBGS(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, gnobs=gnobs, rnobs=rnobs, znobs=znobs, gfracmasked=gfracmasked, rfracmasked=rfracmasked, zfracmasked=zfracmasked, gfracflux=gfracflux, rfracflux=rfracflux, zfracflux=zfracflux, gfracin=gfracin, rfracin=rfracin, zfracin=zfracin, gfluxivar=gfluxivar, rfluxivar=rfluxivar, zfluxivar=zfluxivar, maskbits=maskbits, Grr=Grr, w1snr=w1snr, gaiagmag=gaiagmag, primary=primary, targtype=targtype)) self.assertTrue(np.all(bgs[0] == bgs[1])) # ADM need to include RELEASE for quasar cuts, at least. release = targets['RELEASE'] # - Test that objtype and primary are optional psftype = targets['TYPE'] qso1 = cuts.isQSO_cuts(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, deltaChi2=deltaChi2, maskbits=maskbits, w1snr=w1snr, w2snr=w2snr, objtype=psftype, primary=primary, release=release) qso2 = cuts.isQSO_cuts(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, deltaChi2=deltaChi2, maskbits=maskbits, w1snr=w1snr, w2snr=w2snr, objtype=None, primary=None, release=release) self.assertTrue(np.all(qso1 == qso2)) # ADM also check that the color selections alone work. This tripped us up once # ADM with the mocks part of the code calling a non-existent LRG colors function. qso1 = cuts.isQSO_colors(gflux, rflux, zflux, w1flux, w2flux, optical=False) qso2 = cuts.isQSO_colors(gflux, rflux, zflux, w1flux, w2flux, optical=None) self.assertTrue(np.all(qso1 == qso2)) fstd1 = cuts.isSTD_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=None) fstd2 = cuts.isSTD_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=primary) self.assertTrue(np.all(fstd1 == fstd2))
def obiELGvspar( reg, par, vmin=None, vmax=None, nbin=10, obidir='/global/cscratch1/sd/adematti/legacysim/dr9/ebv1000shaper/', elgandlrgbits=[1, 5, 6, 7, 8, 9, 11, 12, 13]): from desitarget import cuts NS = None if reg == 'N': NS = 'north' south = False if reg == 'DS' or reg == 'DN': NS = 'south' south = True if NS == None: print( '!!!NS not set, you must have chose an invalid reg; should be N, DS, or DN!!!' ) return (None) print(NS) obif = fitsio.read(obidir + NS + '/file0_rs0_skip0/merged/matched_input.fits') print(len(obif)) obi_masked = masklc(obif, mb=elgandlrgbits) if reg != 'N': wr = sel_reg(obi_masked['ra'], obi_masked['dec'], reg) obi_masked = obi_masked[wr] gflux = obi_masked['flux_g'] / obi_masked['mw_transmission_g'] rflux = obi_masked['flux_r'] / obi_masked['mw_transmission_r'] zflux = obi_masked['flux_z'] / obi_masked['mw_transmission_z'] ws = cuts.isELG_colors(gflux, rflux, zflux, south=south) print(len(obi_masked[ws])) ws &= (obi_masked['ra'] * 0 == 0) print(len(obi_masked[ws])) obi_elg = obi_masked[ws] if vmin is None: vmin = np.min(rl[par]) if vmax is None: vmax = np.max(rl[par]) rh, bn = np.histogram(obi_masked[par], bins=nbin, range=(vmin, vmax)) dh, db = np.histogram(obi_elg[par], bins=bn) rf = len(obi_masked) / len(obi_elg) sv = dh / rh * rf ep = np.sqrt(dh) / rh * rf bc = [] for i in range(0, len(bn) - 1): bc.append((bn[i] + bn[i + 1]) / 2.) plt.errorbar(bc, sv - 1., ep, fmt='ko') plt.hist(obi_masked[par], bins=nbin, range=(vmin, vmax), weights=0.2 * np.ones(len(obi_masked)) / np.max(rh)) plt.ylim(-.3, .3) plt.xlabel(par) plt.ylabel('Ngal/<Ngal> - 1') plt.title('Obiwan ELGs in ' + reg + ' footprint') plt.show() wv = (obi_masked[par] > vmin) & (obi_masked[par] < vmax) frac = len(obi_masked[~wv]) / len(obi_masked) print('fraction of randoms not included in plot: ' + str(frac)) return bc, sv, ep