def test_unextinct_fluxes(self): targets = io.read_tractor(self.tractorfiles[0]) t1 = cuts.unextinct_fluxes(targets) self.assertTrue(isinstance(t1, np.ndarray)) t2 = cuts.unextinct_fluxes(Table(targets)) self.assertTrue(isinstance(t2, Table)) for col in ['GFLUX', 'RFLUX', 'ZFLUX', 'W1FLUX', 'W2FLUX']: self.assertIn(col, t1.dtype.names) self.assertIn(col, t2.dtype.names) self.assertTrue(np.all(t1[col] == t2[col]))
def test_unextinct_fluxes(self): targets = io.read_tractor(self.tractorfiles[0]) t1 = cuts.unextinct_fluxes(targets) self.assertTrue(isinstance(t1, np.ndarray)) t2 = cuts.unextinct_fluxes(Table(targets)) self.assertTrue(isinstance(t2, Table)) for col in ['GFLUX', 'RFLUX', 'ZFLUX', 'W1FLUX', 'W2FLUX', 'WFLUX']: self.assertIn(col, t1.dtype.names) self.assertIn(col, t2.dtype.names) self.assertTrue(np.all(t1[col] == t2[col]))
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 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))