Esempio n. 1
0
    def read_probs(self):

        # The reg expresion to compile
        regexp_point = re.compile(r"arange\("
                                  r"(?P<z1>[0-9]+.[0-9]+),"
                                  r"(?P<z2>[0-9]+.[0-9]+),"
                                  r"(?P<dz>[0-9]+.[0-9]+)\)")
        t0 = time.time()
        sout.write("# Reading probs from :%s... " % self.probsfile)

        # probability arrays
        probs = []
        for line in open(self.probsfile).readlines():

            fields = line.split()
            if fields[0][0] == "#":
                point = regexp_point.search(line)
                # Extract the information if a point was selected
                if point:
                    z1 = float(point.group('z1'))
                    z2 = float(point.group('z2'))
                    dz = float(point.group('dz'))
                    zx = np.arange(z1, z2, dz)
                continue
            ID = fields[0]
            probs.append(np.asarray(list(map(float, fields[1:]))))

        # Transform the list into an N array
        p_z = np.asarray(probs)

        # select same galaxies as in catalogs we just read
        self.p_z = p_z[self.idx_cat][:]
        self.zx = zx
        sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t0))

        t1 = time.time()
        # Get the 1-sigma z1, z2 limits for each galaxy
        # Cumulatibe P(<z) function for each selected galaxy
        self.Psum = np.cumsum(self.p_z, axis=1)
        sout.write("# Getting +/- 1sigma (z1,z2) limits for each galaxy ")
        self.z1 = self.ra * 0.0
        self.z2 = self.ra * 0.0

        # One by one in the list
        for i in range(len(self.ra)):
            i1 = np.where(self.Psum[i, :] >= 0.159)[0][0]
            i2 = np.where(self.Psum[i, :] > 0.842)[0][0]
            self.z1[i] = self.zx[i1]
            self.z2[i] = self.zx[i2]

        sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t1))
        return
Esempio n. 2
0
    def iter_loop(self, field, mag, N=1):

        # Make the list of artificial galaxies, same for all fields
        self.mag = mag

        # Loop repetirions
        for i in range(N):
            t1 = time.time()
            # pass up the iterarion number
            self.iter = i + 1
            iter = format_iter(self.iter)
            self.GaList = '/tmp/gal_ell_m%.2f_rh%.1f_%s.dist' % (mag, 3.0,
                                                                 iter)
            #self.make_gallist(mag, sseed=i + 1)

            # Create the fake image
            self.mkobjects_homegrown(field)
            # Run SExtractor on it
            self.SEx(field)
            # Match and store the catalog
            self.match_cats(field)

            # Merge them all in one file
            self.merge_matched(field)
            print("# %s " % extras.elapsed_time_str(t1))
            print("# ------\n")
        return
Esempio n. 3
0
    def get_absmags(self):

        # Distance modulus, dlum and dangular
        self.dlum = self.cset.dlum(self.z_ph)
        self.dang = self.cset.dang(self.z_ph)
        self.DM = 25.0 + 5.0 * np.log10(self.dlum)

        t0 = time.time()
        # Get the absolute magnitudes, *** not including evolution ***, only Kcorr
        # We use a BPZ E's template for Kcorr
        #sout.write("# Computing absolute magnitudes interpolating Kcorr ")
        #k = Kcorr_fit(sed='El_Benitez2003')

        # Alternatibely we can get both the kcorr and the evol from
        # the *.color file from BC03 *.ised file
        sout.write(
            "# Computing absolute magnitudes interpolating konly from BC03 model \n"
        )
        k, ev = KEfit(self.evolfile)

        self.Mg = self.g - self.DM - k['g'](self.z_ph)
        self.Mr = self.r - self.DM - k['r'](self.z_ph)
        self.Mi = self.i - self.DM - k['i'](self.z_ph)

        sout.write("# Computing evolution ev(z) for each galaxy ")
        self.ev_g = ev['g'](self.z_ph)
        self.ev_r = ev['r'](self.z_ph)
        self.ev_i = ev['i'](self.z_ph)

        # Also get the luminosities in Msun
        # taken from http://www.ucolick.org/~cnaw/sun.html
        self.Msun = {}
        self.Msun['g'] = 5.11
        self.Msun['r'] = 4.65
        self.Msun['i'] = 4.54

        # Mags k-corrected to z=0.25 as done in Reyes el al 2009
        #Mg = self.g - self.DM  -  k['g'](self.z_ph) + k['g'](0.25)
        #Mr = self.r - self.DM  -  k['r'](self.z_ph) + k['r'](0.25)
        #Mi = self.i - self.DM  -  k['i'](self.z_ph) + k['i'](0.25)

        # Mags k-corrected
        Mg = self.g - self.DM - k['g'](self.z_ph)
        Mr = self.r - self.DM - k['r'](self.z_ph)
        Mi = self.i - self.DM - k['i'](self.z_ph)

        self.Lg = 10.0**(-0.4 * (Mg - self.Msun['g']))
        self.Lr = 10.0**(-0.4 * (Mr - self.Msun['r']))
        self.Li = 10.0**(-0.4 * (Mi - self.Msun['i']))
        self.Lg_err = self.Lg * self.g_err / 1.0857
        self.Lr_err = self.Lr * self.r_err / 1.0857
        self.Li_err = self.Li * self.i_err / 1.0857

        # Pass it up to the class
        self.kcorr = k
        self.evf = ev
        sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t0))
        return
Esempio n. 4
0
def main():
    from glob import glob

    t0 = time.time()

    # Initialize the function
    m1 = 20
    m2 = 25
    dm = 0.2
    Ngal = 100
    N = 10
    filters = ['g', 'r', 'i', 'z']

    for filt in filters:

        # The fields to be used
        data_dir = '/home/boada/Projects/planckClusters/data/proc2_small/'
        files = glob('{}PSZ*/PSZ*{}.fits'.format(data_dir, filt),
                     recursive=True)
        fields = [f.split('/')[-2] for f in files]

        #fields = ['PSZ2_G189.79-37.25', 'PSZ2_G044.83+10.02',
        #           'PSZ2_G065.35-08.01', 'PSZ2_G047.53+08.55',
        #           'PSZ1_G183.26+12.25']

        # Initialize the class
        sim = simgal(filter=filt, m1=m1, m2=m2, dm=dm, Ngal=Ngal, N=N)

        # start the async factory
        async_worker = AsyncFactory(sim.mag_loop, cb_func)

        for field in fields:
            # Do the mag loop m1, m2
            async_worker.call(field, m1, m2, dm=dm, N=N)
            #sim.mag_loop(field, m1, m2, dm=dm, N=4)
        async_worker.wait()

    print(extras.elapsed_time_str(t0))
    return
Esempio n. 5
0
def read_cat(self):
    t1 = time.time()

    cols = (1, 2, 23, 27, 26, 28, 29, 30, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16,
            17, 18, 19, 20, 21, 22, 31, 32, 33, 34, 35, 36)

    sout.write("# Reading cols:%s\n# Reading cats from: %s... \n" %
               (cols, self.catsfile))
    (ra, dec, z_b, odds, t_b, z_ml, t_ml, chi, g, g_err, r, r_err, i, i_err, z,
     z_err, g_bpz, g_berr, r_bpz, r_berr, i_bpz, i_berr, z_bpz, z_berr,
     class_star, a_image, b_image, theta, x_image,
     y_image) = tableio.get_data(self.catsfile, cols=cols)

    (id) = tableio.get_str(self.catsfile, cols=(0, ))

    ############################################
    # Choose the photo-z to use, ml or bayesian
    ############################################
    sout.write("# Will use %s redshifts\n" % self.zuse)
    if self.zuse == "ML":
        z_ph = z_ml
        # t = t_ml
    elif self.zuse == "ZB":
        z_ph = z_b
        # t = t_b

    i_lim = self.maglim
    odds_lim = 0.80  # not currently used
    star_lim = self.starlim

    # Clean up according to BPZ
    sout.write("# Avoiding magnitudes -99 and 99 in BPZ \n")
    g_mask = numpy.where(lor(g_bpz == 99, g_bpz == -99), 0, 1)
    r_mask = numpy.where(lor(r_bpz == 99, r_bpz == -99), 0, 1)
    i_mask = numpy.where(lor(i_bpz == 99, i_bpz == -99), 0, 1)
    z_mask = numpy.where(lor(z_bpz == 99, z_bpz == -99), 0, 1)
    bpz_mask = g_mask * r_mask * i_mask * z_mask

    # Clean up to avoid 99 values and very faint i_mag values
    sout.write("# Avoiding magnitudes 99 in MAG_AUTO \n")
    #g_mask = numpy.where( g >= 99,    0 , 1)
    #r_mask = numpy.where( r >= 99,    0 , 1)
    #i_mask = numpy.where( i >= i_lim, 0 , 1)
    #z_mask = numpy.where( z >= 99,    0 , 1)
    sout.write("# Avoiding magnitudes i > %s in MAG_AUTO \n" % i_lim)

    # Clean by class_star
    sout.write("# Avoiding CLASS_STAR > %s \n" % star_lim)
    mask_star = numpy.where(class_star > star_lim, 0, 1)

    # Clean up by odds
    #sout.write( "# Avoiding ODDS < %s in BPZ \n" % odds_lim)
    odds_mask = numpy.where(odds > odds_lim, 1, 0)
    odds_mask = 1

    # Avoid z> zlim objects too.
    #sout.write( "# Avoiding objects with z > %s " % self.zlim)
    zp_mask = numpy.where(z_ph > self.zlim, 0, 1)
    zp_mask = 1

    # Clean up by BPZ type
    # sout.write('# Avoiding objects with type > %s' % t)
    tp_mask = 1

    # The final 'good' mask
    mask_good = bpz_mask * odds_mask * mask_star * zp_mask * tp_mask
    idx = numpy.where(mask_good == 1)

    # Make ids a Char String in numarray
    self.id = nstr.array(id)[idx]

    # Only keep the 'good' one, avoid -99 and 99 values in BPZ mags
    self.ra = ra[idx]
    self.dec = dec[idx]
    self.z_b = z_b[idx]
    self.odds = odds[idx]

    self.z_ml = z_ml[idx]
    self.t_ml = t_ml[idx]
    self.t_b = t_b[idx]
    self.t_ml = t_ml[idx]
    self.chi = chi[idx]

    ############################################
    # Choose the photo-z to use, ml or bayesian
    ############################################
    if self.zuse == "ML":
        self.z_ph = self.z_ml
        self.type = self.t_ml
    elif self.zuse == "ZB":
        self.z_ph = self.z_b
        self.type = self.t_b

    self.g = g[idx]
    self.r = r[idx]
    self.i = i[idx]
    self.z = z[idx]
    self.g_err = g_err[idx]
    self.r_err = r_err[idx]
    self.i_err = i_err[idx]
    self.z_err = z_err[idx]

    self.g_bpz = g_bpz[idx]
    self.r_bpz = r_bpz[idx]
    self.i_bpz = i_bpz[idx]
    self.z_bpz = z_bpz[idx]
    self.g_berr = g_berr[idx]
    self.r_berr = r_berr[idx]
    self.i_berr = i_berr[idx]
    self.z_berr = z_berr[idx]

    self.class_star = class_star[idx]
    self.a_image = a_image[idx]
    self.b_image = b_image[idx]
    self.theta = theta[idx]
    self.x_image = x_image[idx]
    self.y_image = y_image[idx]

    # Color of selected galaxies
    self.gr = self.g_bpz - self.r_bpz
    self.ri = self.r_bpz - self.i_bpz
    self.iz = self.i_bpz - self.z_bpz

    # Min and and max values in RA/DEC
    self.ramin = self.ra.min()
    self.ramax = self.ra.max()
    self.decmin = self.dec.min()
    self.decmax = self.dec.max()

    self.idx_cat = idx

    sout.write(" \tDone: %s\n" % extras.elapsed_time_str(t1))
    return
Esempio n. 6
0
    def select_members_radius(self, i, Mi_lim=-20.25, radius=500.0, zo=None):

        # Width of the redshift shell
        dz = self.dz

        t0 = time.time()
        sout.write("# Selecting Cluster members... Ngal, N200, R200 \n")
        # Get the relevant info for ith BCG
        ra0 = self.ra[i]
        dec0 = self.dec[i]
        Mi_BCG = self.Mi[i]
        DM = self.DM[i]
        ID_BCG = self.id[i]
        if zo:
            print("Will use z:%.3f for cluster" % zo)
        else:
            zo = self.z_ph[i]
        # 1 - Select in position around ra0,dec0
        # Define radius in degress @ zo
        R = radius  # in kpc
        r = old_div(astrometry.kpc2arc(zo, R, self.cosmo),
                    3600.)  # in degrees.
        rcore = old_div(r, 2.0)
        dist = astrometry.circle_distance(ra0,
                                          dec0,
                                          self.ra,
                                          self.dec,
                                          units='deg')
        mask_R = np.where(dist <= r, 1, 0)
        mask_rcore = np.where(dist <= rcore, 1, 0)
        arcmin2Mpc = old_div(astrometry.arc2kpc(zo, 60.0, self.cosmo),
                             1000.0)  # scale between arcmin and Mpc

        # 2 - Select in redshift
        z1 = zo - dz
        z2 = zo + dz
        mask_z = np.where(land(self.z_ph >= z1, self.z_ph <= z2), 1, 0)

        # 3 - Select in brightness
        Mi_lim_zo = Mi_lim + self.evf['i'](zo) - self.evf['i'](0.1)
        mask_L1 = np.where(self.Mi <= Mi_lim_zo, 1, 0)  # Faint  cut > 0.4L*
        mask_L2 = np.where(self.Mi >= Mi_BCG, 1, 0)  # Bright cut < L_BCG

        # The final selection mask, position x redshift x Luminosity
        idx = np.where(mask_R * mask_L1 * mask_L2 * mask_z == 1)[0]
        idc = np.where(mask_rcore * mask_L1 * mask_L2 * mask_z == 1)[0]

        # Shot versions handles
        gr = self.gr
        ri = self.ri

        # Some simple 3-sigma clipping defined using r< rcore
        Nsigma = 3.0
        loop = 1
        converge = False
        while not converge:
            # The conditions to apply
            c1 = np.abs(gr[idc] -
                        gr[idc].mean()) > Nsigma * np.std(gr[idc], ddof=1)
            c2 = np.abs(ri[idc] -
                        ri[idc].mean()) > Nsigma * np.std(ri[idc], ddof=1)
            iclip = np.where(lor(c1,
                                 c2))[0]  # where any of the conditions fails
            if len(iclip) > 0:
                idc = np.delete(idc, iclip)  # Removed failed ones
                converge = False
            else:
                converge = True
            loop = loop + 1

            # Get the average redshift within the core:
            #z_cl    = self.z_ph[idc].mean()
            #z_clrms = self.z_ph[idc].std()

            # Compute the weighted average and rms
        dz = 0.5 * np.abs(self.z2[idc] - self.z1[idc])
        z_cl, z_clrms = aux.statsw(self.z_ph[idc], weight=old_div(1.0, dz))

        sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t0))

        # Or we can make a new mask where the condition's are true
        c1 = np.abs(self.gr -
                    gr[idc].mean()) > Nsigma * np.std(gr[idc], ddof=1)
        c2 = np.abs(self.ri -
                    ri[idc].mean()) > Nsigma * np.std(ri[idc], ddof=1)
        mask_cm = np.where(lor(c1, c2), 0, 1)  # where condition fails
        iRadius = np.where(mask_R * mask_L1 * mask_L2 * mask_z * mask_cm == 1)
        Ngal = len(iRadius[0])
        sout.write("# Total: %s objects selected in %s [kpc] around %s\n" %
                   (Ngal, radius, self.ID))

        # Pass up
        self.iRadius = iRadius
        self.arcmin2Mpc = arcmin2Mpc
        self.Lsum = self.Lr[iRadius].sum()
        self.Ngal = Ngal
        self.z_cl = z_cl
        self.z_clerr = z_clrms
        self.rdeg = r  # in degress
        self.idc = idc  # galaxies used for mean redshift
        self.ID_BCG = ID_BCG

        return z_cl, z_clrms
Esempio n. 7
0
    def select_members(self, i, Mi_lim=-20.25):

        # Width of the redshift shell
        dz = self.dz

        t0 = time.time()
        sout.write("# Selecting Cluster members... Ngal, N200, R200 \n")
        # Get the relevant info for ith BCG
        zo = self.z_ph[i]
        ra0 = self.ra[i]
        dec0 = self.dec[i]
        Mi_BCG = self.Mi[i]
        DM = self.DM[i]
        ID_BCG = self.id[i]

        # 1 - Select in position around ra0,dec0
        # Define 1h^-1 Mpc radius in degress @ zo
        R1Mpc = 1000 * 1.0 / self.h  # in kpc
        r1Mpc = old_div(astrometry.kpc2arc(zo, R1Mpc, self.cosmo),
                        3600.)  # in degrees.
        rcore = old_div(r1Mpc, 2.0)
        dist = astrometry.circle_distance(ra0,
                                          dec0,
                                          self.ra,
                                          self.dec,
                                          units='deg')
        mask_R1Mpc = np.where(dist <= r1Mpc, 1, 0)
        mask_rcore = np.where(dist <= rcore, 1, 0)
        arcmin2Mpc = old_div(astrometry.arc2kpc(zo, 60.0, self.cosmo),
                             1000.0)  # scale between arcmin and Mpc

        # 2 - Select in redshift
        z1 = zo - dz
        z2 = zo + dz
        mask_z = np.where(land(self.z_ph >= z1, self.z_ph <= z2), 1, 0)

        # 3 - Select in brightness
        Mi_lim_zo = Mi_lim + self.evf['i'](zo) - self.evf['i'](0.1)
        mask_L1 = np.where(self.Mi <= Mi_lim_zo, 1, 0)  # Faint  cut > 0.4L*
        mask_L2 = np.where(self.Mi >= Mi_BCG, 1, 0)  # Bright cut < L_BCG

        # The final selection mask, position x redshift x Luminosity
        idx = np.where(mask_R1Mpc * mask_L1 * mask_L2 * mask_z == 1)
        idc = np.where(mask_rcore * mask_L1 * mask_L2 * mask_z == 1)

        # Shot versions handles
        gr = self.gr
        ri = self.ri

        # Some simple 3-sigma clipping defined using r< rcore
        Nsigma = 3.0
        loop = 1
        converge = False
        while not converge:
            # The conditions to apply
            c1 = np.abs(gr[idc] -
                        gr[idc].mean()) > Nsigma * np.std(gr[idc], ddof=1)
            c2 = np.abs(ri[idc] -
                        ri[idc].mean()) > Nsigma * np.std(ri[idc], ddof=1)
            iclip = np.where(lor(c1, c2))  # where any of the conditions fails
            if len(iclip[0]) > 0:
                idc = np.delete(idc, iclip[0])  # Removed failed ones
                converge = False
            else:
                converge = True
            loop = loop + 1

        sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t0))

        # Or we can make a new mask where the condition's are true
        c1 = np.abs(self.gr -
                    gr[idc].mean()) > Nsigma * np.std(gr[idc], ddof=1)
        c2 = np.abs(self.ri -
                    ri[idc].mean()) > Nsigma * np.std(ri[idc], ddof=1)
        mask_cm = np.where(lor(c1, c2), 0, 1)  # where condition fails
        iR1Mpc = np.where(mask_R1Mpc * mask_L1 * mask_L2 * mask_z *
                          mask_cm == 1)
        Ngal = len(iR1Mpc[0])
        sout.write("# Total: %s objects selected in 1h^-1Mpc around %s\n" %
                   (Ngal, self.ID))

        #############################################################################
        # We'll skip 200 measurement as they depend on the corrected values of Ngal
        # Now let's get R200 and N200
        R200 = 0.156 * (Ngal**0.6) / self.h  # In Mpc
        r200 = old_div(astrometry.kpc2arc(zo, R200 * 1000.0, self.cosmo),
                       3600.)  # in degrees.
        mask_r200 = np.where(dist <= r200, 1, 0)
        i200 = np.where(mask_r200 * mask_L1 * mask_L2 * mask_z * mask_cm == 1)
        N200 = len(i200[0])
        self.i200 = i200
        self.N200 = N200
        self.R200 = R200
        self.r200 = r200
        self.L200 = self.Lr[i200].sum()
        ############################################################################

        # And the value for all galaxies up NxR1Mpc -- change if required.
        mask_R = np.where(dist <= 10 * r1Mpc, 1, 0)
        iR = np.where(mask_R * mask_L1 * mask_L2 * mask_z * mask_cm == 1)

        # Pass up
        self.iR = iR
        self.iR1Mpc = iR1Mpc
        self.N1Mpc = Ngal
        self.r1Mpc = r1Mpc  # in degress
        self.dist2BCG = dist
        self.arcmin2Mpc = arcmin2Mpc

        # Sort indices radially for galaxies < N*R1Mpc, will be used later
        i = np.argsort(self.dist2BCG[iR])
        self.ix_radial = iR[0][i]

        # We want to keep i200 and iR1Mpc to write out members.
        return Ngal, N200, R200  # iR1Mpc,i200
Esempio n. 8
0
    def get_BCG_candidates(self, Mr_limit=-22.71, p_lim=1e-4):

        t0 = time.time()
        sout.write("# Computing p_BCG probabilities... ")

        # The Abs mag limit @ z=0.1 in the i-band
        Mi_limit = cosmology.reobs('El_Benitez2003',
                                   m=Mr_limit,
                                   oldfilter="r_MOSAICII",
                                   newfilter="i_MOSAICII")

        # Evaluate the genertic mask for BCG only onece
        if not self.BCG_probs:

            # We get the limit at the z_ph of each candidate, corrected by z=0.1
            Mr_BCG_limit = Mr_limit + self.ev_r - self.evf['r'](
                0.1)  #+ self.DM_factor
            Mi_BCG_limit = Mi_limit + self.ev_i - self.evf['i'](
                0.1)  #+ self.DM_factor
            # Evaluate the BCG Probability function, we get the limit for each object
            self.p = p_BCG(self.Mr, Mr_BCG_limit)
            self.BCG_probs = True

            i_lim = 25.0
            star_lim = 0.5
            mask_p = np.where(self.p >= p_lim, 1, 0)
            mask_g = np.where(self.g < i_lim + 5, 1, 0)
            mask_r = np.where(self.r < i_lim + 5, 1, 0)
            mask_i = np.where(self.i < i_lim, 1, 0)
            mask_t = np.where(self.type < 2.0, 1, 0)

            # Avoid freakishly bright objects, 2.5 mags brighter than the M_BCG_limit
            mask_br = np.where(self.Mr > Mr_BCG_limit - 3.5, 1, 0)
            mask_bi = np.where(self.Mi > Mi_BCG_limit - 3.5, 1, 0)

            # Put a more strict cut in class_star for bcg candidates
            sout.write("# Avoiding CLASS_STAR > %s in BGCs\n" % star_lim)
            mask_star = np.where(self.class_star <= star_lim, 1, 0)

            # Construct the final mask now
            self.mask_BCG = mask_t * mask_g * mask_r * mask_i * mask_br * mask_bi * mask_p
            self.BCG_masked = True
            sout.write(" \t Done: %s\n" % extras.elapsed_time_str(t0))

        # Select the candidates now
        idx = np.where(self.mask_BCG == 1)

        # And pass up to to class
        # The index number
        self.idx_BCG = idx
        self.ra_BCG = self.ra[idx]
        self.dec_BCG = self.dec[idx]
        self.p_BCG = self.p[idx]
        self.z_BCG = self.z_ph[idx]
        self.t_BCG = self.type[idx]
        self.N_BCG = len(idx[0])
        self.Mi_BCG = self.Mi[idx]
        self.Mr_BCG = self.Mr[idx]
        self.DM_BCG = self.DM[idx]  # distance modulus
        self.dang_BCG = self.dang[idx]  # distance modulus

        self.zml_BCG = self.z_ml[idx]
        self.tml_BCG = self.t_ml[idx]
        self.zb_BCG = self.z_b[idx]
        self.tb_BCG = self.t_b[idx]
        self.class_BCG = self.class_star[idx]
        self.a_BCG = self.a_image[idx]
        self.b_BCG = self.b_image[idx]
        self.theta_BCG = self.theta[idx]
        self.x_BCG = self.x_image[idx]
        self.x_BCG = self.x_image[idx]

        # r,i-band stuff
        self.r_BCG = self.r[idx]
        self.i_BCG = self.i[idx]

        # Get the 1-sigma intervals
        self.z1_BCG = self.z1[idx]
        self.z2_BCG = self.z2[idx]

        # The r-band Luminosity of the BCGs
        self.LBCG = self.Lr[idx]

        # The distance to the candidate's position for each BCG, in arcmin
        sout.write("# Found %s BCG candidates\n" % self.N_BCG)

        return
Esempio n. 9
0
def get_BCG_candidates(self, Mr_limit=-22.71, p_lim=1e-4):

    t0 = time.time()
    sout.write("# Computing p_BCG probabilities...\n")

    # The Abs mag limit @ z=0.1 in the i-band
    Mi_limit = cosmology.reobs(
        'El_Benitez2003',
        m=Mr_limit,
        oldfilter="r_MOSAICII",
        newfilter="i_MOSAICII")

    # Evaluate the genertic mask for BCG only onece
    if not self.BCG_probs:

        # We get the limit at the z_ph of each candidate, corrected by z=0.1
        Mr_BCG_limit = Mr_limit + self.ev_r - self.evf['r'](
            0.1)  # + self.DM_factor
        Mi_BCG_limit = Mi_limit + self.ev_i - self.evf['i'](
            0.1)  # + self.DM_factor

        # Evaluate the BCG Probability function, we
        # get the limit for each object
        self.p = p_BCG(self.Mr, Mr_BCG_limit)

        self.BCG_probs = True

        i_lim = 25.0
        star_lim = self.starlim
        p_lim = max(self.p) * 0.8
        sout.write("\tAvoiding BCG_prob < %.3f in BGCs\n" % p_lim)
        mask_p = numpy.where(self.p >= p_lim, 1, 0)
        mask_g = numpy.where(self.g < i_lim + 5, 1, 0)
        mask_r = numpy.where(self.r < i_lim + 2, 1, 0)
        mask_i = numpy.where(self.i < i_lim, 1, 0)
        mask_z = numpy.where(self.z < i_lim + 1, 1, 0)
        mask_t = numpy.where(self.type <= 2.0, 1, 0)

        # Avoid freakishly bright objects, 2.5 mags brighter than the
        # M_BCG_limit
        mask_br = numpy.where(self.Mr > Mr_BCG_limit - 2.5, 1, 0)
        mask_bi = numpy.where(self.Mi > Mi_BCG_limit - 2.5, 1, 0)

        # Put a more strict cut in class_star for bcg candidates
        sout.write("\tAvoiding CLASS_STAR > %s in BGCs\n" % star_lim)
        mask_star = numpy.where(self.class_star <= star_lim, 1, 0)

        # Construct the final mask now
        self.mask_BCG = (mask_t * mask_g * mask_r * mask_i * mask_z *
                         mask_br * mask_bi * mask_p * mask_star)

        self.BCG_masked = True

        # Model color only once
        #self.zx = numpy.arange(0.01, self.zlim, 0.01)
        self.gr_model = cosmology.color_z(
            sed='El_Benitez2003',
            filter_new='g_MOSAICII',
            filter_old='r_MOSAICII',
            z=self.zx,
            calibration='AB')
        self.ri_model = cosmology.color_z(
            sed='El_Benitez2003',
            filter_new='r_MOSAICII',
            filter_old='i_MOSAICII',
            z=self.zx,
            calibration='AB')
        self.iz_model = cosmology.color_z(
            sed='El_Benitez2003',
            filter_new='i_MOSAICII',
            filter_old='z_MOSAICII',
            z=self.zx,
            calibration='AB')

        sout.write(" \tDone: %s\n" % extras.elapsed_time_str(t0))

    # Select the candidates now
    idx = numpy.where(self.mask_BCG == 1)

    # And pass up to to class
    self.idx_BCG = idx
    self.id_BCG = self.id[idx]
    self.ra_BCG = self.ra[idx]
    self.dec_BCG = self.dec[idx]
    self.p_BCG = self.p[idx]
    self.z_BCG = self.z_ph[idx]
    self.t_BCG = self.type[idx]
    self.N_BCG = len(idx[0])
    self.Mi_BCG = self.Mi[idx]
    self.Mr_BCG = self.Mr[idx]
    self.DM_BCG = self.DM[idx]  # distance modulus
    self.dang_BCG = self.dang[idx]  # distance modulus

    self.zml_BCG = self.z_ml[idx]
    self.tml_BCG = self.t_ml[idx]
    self.zb_BCG = self.z_b[idx]
    self.tb_BCG = self.t_b[idx]
    self.class_BCG = self.class_star[idx]
    self.a_BCG = self.a_image[idx]
    self.b_BCG = self.b_image[idx]
    self.theta_BCG = self.theta[idx]

    # r,i-band stuff
    self.r_BCG = self.r[idx]
    self.i_BCG = self.i[idx]

    # Get the 1-sigma intervals
    self.z1_BCG = self.z1[idx]
    self.z2_BCG = self.z2[idx]

    # The r-band Luminosity of the BCGs
    self.LBCG = self.Lr[idx]

    # The distance to the candidate's position for each BCG, in arcmin
    if self.N_BCG:
        sout.write(color("\tFound %s BCG candidates\n" % self.N_BCG, 36, 1))
    else:
        sout.write(color("\tFound %s BCG candidates\n" % self.N_BCG, 31, 5))
    return