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'] wflux = flux['WFLUX'] primary = targets['BRICK_PRIMARY'] lrg1 = cuts.isLRG(rflux, zflux, w1flux, primary=None) lrg2 = cuts.isLRG(rflux, zflux, w1flux, primary=primary) self.assertTrue(np.all(lrg1==lrg2)) elg1 = cuts.isELG(gflux, rflux, zflux, primary=primary) elg2 = cuts.isELG(gflux, rflux, zflux, primary=None) self.assertTrue(np.all(elg1==elg2)) psftype = targets['TYPE'] bgs1 = cuts.isBGS(rflux, type=psftype, primary=primary) bgs2 = cuts.isBGS(rflux, type=None, primary=None) self.assertTrue(np.all(bgs1==bgs2)) qso1 = cuts.isQSO(gflux, rflux, zflux, wflux, type=psftype, primary=primary) qso2 = cuts.isQSO(gflux, rflux, zflux, wflux, type=None, primary=None) self.assertTrue(np.all(qso1==qso2)) fstd1 = cuts.isFSTD_colors(gflux, rflux, zflux, primary=None) fstd2 = cuts.isFSTD_colors(gflux, rflux, zflux, primary=primary) self.assertTrue(np.all(fstd1==fstd2))
def qso_select(self, targets, truth, boss_std=None): """Select QSO targets and contaminants.""" from desitarget.cuts import isQSO_colors, isELG gflux, rflux, zflux, w1flux, w2flux = targets['FLUX_G'], targets['FLUX_R'], \ targets['FLUX_Z'], targets['FLUX_W1'], targets['FLUX_W2'] qso = isQSO_colors(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, optical=True) targets['DESI_TARGET'] |= (qso != 0) * self.desi_mask.QSO targets['DESI_TARGET'] |= (qso != 0) * self.desi_mask.QSO_SOUTH targets['OBSCONDITIONS'] |= (qso != 0) * self.obsconditions.mask( self.desi_mask.QSO.obsconditions) targets['OBSCONDITIONS'] |= (qso != 0) * self.obsconditions.mask( self.desi_mask.QSO_SOUTH.obsconditions) # Select QSO contaminants for ELG targets. There'd be no morphology cut # and we're missing the WISE colors, so the density won't be right. elg = isELG(gflux=gflux, rflux=rflux, zflux=zflux) targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG_SOUTH targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG.obsconditions) targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG_SOUTH.obsconditions) truth['CONTAM_TARGET'] |= (elg != 0) * self.contam_mask.ELG_IS_QSO truth['CONTAM_TARGET'] |= (elg != 0) * self.contam_mask.ELG_CONTAM
def elg_select(self, targets, truth, boss_std=None): """Select ELG targets and contaminants.""" from desitarget.cuts import isELG, isQSO_colors gflux, rflux, zflux, w1flux, w2flux = targets['FLUX_G'], targets['FLUX_R'], \ targets['FLUX_Z'], targets['FLUX_W1'], targets['FLUX_W2'] elg = isELG(gflux=gflux, rflux=rflux, zflux=zflux) targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG_SOUTH targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG.obsconditions) targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG_SOUTH.obsconditions) # Select ELG contaminants for QSO targets. There should be a morphology # cut here, too, so we're going to overestimate the number of # contaminants. To make sure we don't reduce the number density of true # ELGs, demand that the QSO contaminants are not also selected as ELGs. qso = isQSO_colors(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, optical=False) # Note optical=False! targets['DESI_TARGET'] |= (qso != 0) * (elg == 0) * self.desi_mask.QSO targets['DESI_TARGET'] |= (qso != 0) * (elg == 0) * self.desi_mask.QSO_SOUTH targets['OBSCONDITIONS'] |= (qso != 0) * (elg == 0) * self.obsconditions.mask( self.desi_mask.QSO.obsconditions) targets['OBSCONDITIONS'] |= (qso != 0) * ( elg == 0) * self.obsconditions.mask( self.desi_mask.QSO_SOUTH.obsconditions) truth['CONTAM_TARGET'] |= (qso != 0) * ( elg == 0) * self.contam_mask.QSO_IS_ELG truth['CONTAM_TARGET'] |= (qso != 0) * ( elg == 0) * self.contam_mask.QSO_IS_GALAXY truth['CONTAM_TARGET'] |= (qso != 0) * ( elg == 0) * self.contam_mask.QSO_CONTAM
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 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'] gfluxivar = targets['FLUX_IVAR_G'] 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] 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, gflux_ivar=gfluxivar, rflux_snr=rsnr, zflux_snr=zsnr, w1flux_snr=w1snr) lrg2 = cuts.isLRG(primary=None, gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, gflux_ivar=gfluxivar, rflux_snr=rsnr, zflux_snr=zsnr, w1flux_snr=w1snr) self.assertTrue(np.all(lrg1 == lrg2)) elg1 = cuts.isELG(gflux=gflux, rflux=rflux, zflux=zflux, primary=primary) elg2 = cuts.isELG(gflux=gflux, rflux=rflux, zflux=zflux, primary=None) self.assertTrue(np.all(elg1 == elg2)) # @moustakas - Leaving off objtype will result in different samples! psftype = targets['TYPE'] bgs1 = cuts.isBGS_bright(rflux=rflux, objtype=psftype, primary=primary) bgs2 = cuts.isBGS_bright(rflux=rflux, objtype=psftype, primary=None) self.assertTrue(np.all(bgs1 == bgs2)) bgs1 = cuts.isBGS_faint(rflux=rflux, objtype=psftype, primary=primary) bgs2 = cuts.isBGS_faint(rflux=rflux, objtype=psftype, primary=None) self.assertTrue(np.all(bgs1 == bgs2)) #- Test that objtype and primary are optional qso1 = cuts.isQSO_cuts(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, deltaChi2=deltaChi2, w1snr=w1snr, w2snr=w2snr, objtype=psftype, primary=primary) qso2 = cuts.isQSO_cuts(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, deltaChi2=deltaChi2, w1snr=w1snr, w2snr=w2snr, objtype=None, primary=None) self.assertTrue(np.all(qso1 == qso2)) fstd1 = cuts.isFSTD_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=None) fstd2 = cuts.isFSTD_colors(gflux=gflux, rflux=rflux, zflux=zflux, primary=primary) self.assertTrue(np.all(fstd1 == fstd2))
def _star_select(self, targets, truth): """Select stellar (faint and bright) contaminants for the extragalactic targets. """ from desitarget.cuts import isBGS_faint, isELG, isLRG_colors, isQSO_colors gflux, rflux, zflux, w1flux, w2flux = targets['FLUX_G'], targets['FLUX_R'], \ targets['FLUX_Z'], targets['FLUX_W1'], targets['FLUX_W2'] # Select stellar contaminants for BGS_FAINT targets. bgs_faint = isBGS_faint(rflux=rflux) targets['BGS_TARGET'] |= (bgs_faint != 0) * self.bgs_mask.BGS_FAINT targets['BGS_TARGET'] |= (bgs_faint != 0) * self.bgs_mask.BGS_FAINT_SOUTH targets['DESI_TARGET'] |= (bgs_faint != 0) * self.desi_mask.BGS_ANY targets['OBSCONDITIONS'] |= (bgs_faint != 0) * self.obsconditions.mask( self.bgs_mask.BGS_FAINT.obsconditions) targets['OBSCONDITIONS'] |= (bgs_faint != 0) * self.obsconditions.mask( self.bgs_mask.BGS_FAINT_SOUTH.obsconditions) targets['OBSCONDITIONS'] |= (bgs_faint != 0) * self.obsconditions.mask( self.desi_mask.BGS_ANY.obsconditions) truth['CONTAM_TARGET'] |= (bgs_faint != 0) * self.contam_mask.BGS_IS_STAR truth['CONTAM_TARGET'] |= (bgs_faint != 0) * self.contam_mask.BGS_CONTAM # Select stellar contaminants for ELG targets. elg = isELG(gflux=gflux, rflux=rflux, zflux=zflux) targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG targets['DESI_TARGET'] |= (elg != 0) * self.desi_mask.ELG_SOUTH targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG.obsconditions) targets['OBSCONDITIONS'] |= (elg != 0) * self.obsconditions.mask( self.desi_mask.ELG_SOUTH.obsconditions) truth['CONTAM_TARGET'] |= (elg != 0) * self.contam_mask.ELG_IS_STAR truth['CONTAM_TARGET'] |= (elg != 0) * self.contam_mask.ELG_CONTAM # Select stellar contaminants for LRG targets. lrg = isLRG_colors(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux) targets['DESI_TARGET'] |= (lrg != 0) * self.desi_mask.LRG targets['DESI_TARGET'] |= (lrg != 0) * self.desi_mask.LRG_SOUTH targets['OBSCONDITIONS'] |= (lrg != 0) * self.obsconditions.mask( self.desi_mask.LRG.obsconditions) targets['OBSCONDITIONS'] |= (lrg != 0) * self.obsconditions.mask( self.desi_mask.LRG_SOUTH.obsconditions) truth['CONTAM_TARGET'] |= (lrg != 0) * self.contam_mask.LRG_IS_STAR truth['CONTAM_TARGET'] |= (lrg != 0) * self.contam_mask.LRG_CONTAM # Select stellar contaminants for QSO targets. qso = isQSO_colors(gflux=gflux, rflux=rflux, zflux=zflux, w1flux=w1flux, w2flux=w2flux, optical=False) # Note optical=False! targets['DESI_TARGET'] |= (qso != 0) * self.desi_mask.QSO targets['DESI_TARGET'] |= (qso != 0) * self.desi_mask.QSO_SOUTH targets['OBSCONDITIONS'] |= (qso != 0) * self.obsconditions.mask( self.desi_mask.QSO.obsconditions) targets['OBSCONDITIONS'] |= (qso != 0) * self.obsconditions.mask( self.desi_mask.QSO_SOUTH.obsconditions) truth['CONTAM_TARGET'] |= (qso != 0) * self.contam_mask.QSO_IS_STAR truth['CONTAM_TARGET'] |= (qso != 0) * self.contam_mask.QSO_CONTAM