Esempio n. 1
0
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
Esempio n. 2
0
    def lrg_select(self, targets, truth, boss_std=None):
        """Select LRG targets."""
        from desitarget.cuts import isLRG_colors, isQSO_colors

        gflux, rflux, zflux, w1flux, w2flux = targets['FLUX_G'], targets['FLUX_R'], \
          targets['FLUX_Z'], targets['FLUX_W1'], targets['FLUX_W2']

        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)

        # Select LRG 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
        # LRGs, demand that the QSO contaminants are not also selected as LRGs.
        qso = isQSO_colors(gflux=gflux,
                           rflux=rflux,
                           zflux=zflux,
                           w1flux=w1flux,
                           w2flux=w2flux,
                           optical=False)  # Note optical=False!
        targets['DESI_TARGET'] |= (qso != 0) * (lrg == 0) * self.desi_mask.QSO
        targets['DESI_TARGET'] |= (qso !=
                                   0) * (lrg == 0) * self.desi_mask.QSO_SOUTH
        targets['OBSCONDITIONS'] |= (qso !=
                                     0) * (lrg == 0) * self.obsconditions.mask(
                                         self.desi_mask.QSO.obsconditions)
        targets['OBSCONDITIONS'] |= (qso != 0) * (
            lrg == 0) * self.obsconditions.mask(
                self.desi_mask.QSO_SOUTH.obsconditions)

        truth['CONTAM_TARGET'] |= (qso != 0) * (
            lrg == 0) * self.contam_mask.QSO_IS_LRG
        truth['CONTAM_TARGET'] |= (qso != 0) * (
            lrg == 0) * self.contam_mask.QSO_IS_GALAXY
        truth['CONTAM_TARGET'] |= (qso != 0) * (
            lrg == 0) * self.contam_mask.QSO_CONTAM
Esempio n. 3
0
    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))
Esempio n. 4
0
    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