예제 #1
0
def GMRrichness(ra=None,dec=None,photoz=None,cat=None,plot=True,err=True,rw=True,bcg=True,radius=1.):
    fra=cat.field('ra')
    fdec=cat.field('dec')
    imag=cat.field('model_counts')[:,3]
    gmr=cat.field('gmr')
    gmrerr=cat.field('gmr_err')
    depth=12
    h=es.htm.HTM(depth)
    srad=np.rad2deg(radius/Da(0,photoz))
    m1,m2,d12 = h.match(ra,dec,fra,fdec,srad,maxmatch=5000)
    cimag=imag[m2[0]]
    cgmr=gmr[m2[0]]
    r12=np.deg2rad(d12)*Da(0,photoz)
    if bcg is True:
        indices=(imag[m2]<=limi(photoz))*(imag[m2]>cimag)
    else:
        indices=(imag[m2]<=limi(photoz))
    ntot=len(m2[indices])
    if ntot <= 10:
        return 0, 0, 0
    alpha=np.array([0.5,0.5])
    mu=np.array([sts.scoreatpercentile(gmr[m2[indices]],per=70),sts.scoreatpercentile(gmr[m2[indices]],per=40)])
    sigma=np.array([0.04,0.3])
    if err is True:
        if rw is False:
            aic2=gmm.aic_ecgmm(gmr[m2[indices]],gmrerr[m2[indices]],alpha,mu,sigma)
            aic1=gmm.wstat(gmr[m2[indices]],gmrerr[m2[indices]])[3] 
        else:
            aic2,alpha,mu,sigma=rwgmm.aic2EM(gmr[m2[indices]],gmrerr[m2[indices]],r12[indices],alpha,mu,sigma)
            aic1=rwgmm.aic1EM(gmr[m2[indices]],gmrerr[m2[indices]],r12[indices])[0]
    else:
        aic2=gmm.aic_ecgmm(gmr[m2[indices]],aalpha=alpha,mmu=mu,ssigma=sigma)
        aic1=gmm.wstat(gmr[m2[indices]])[3] 
    if plot==True:
        pl.hist(gmr[m2[indices]],bins=30,normed=True,facecolor='green',alpha=0.3)
        pl.vlines(cgmr,0,3,color='green')
        x=np.arange(-1,5,0.01)
        srt=np.argsort(sigma)
        alpha=alpha[srt]
        mu=mu[srt]
        sigma=sigma[srt]
        z = gmrz(mu[0])
        t=gmm.ecgmmplot(x,alpha,mu,sigma)
        pl.xlabel('g - r')
        pl.figtext(0.61,0.85,r'$\alpha$: '+str(np.round(alpha,4)))
        pl.figtext(0.61,0.8,r'$\mu$: '+str(np.round(mu,4)))
        pl.figtext(0.61,0.75,r'$\sigma$: '+str(np.round(sigma,4)))
        pl.figtext(0.61,0.68,r'$Amplitude$: '+str(np.round(ntot*alpha[0],2)))
        pl.figtext(0.61,0.61,r'$AIC_1$: '+str(aic1))
        pl.figtext(0.61,0.54,r'$AIC_2$: '+str(aic2))
        pl.figtext(0.61,0.47,'Photoz: '+str(photoz))
        pl.figtext(0.61,0.4,'ridgeline Z: '+str(z))
        pl.title('Total # of galaxies: '+str(ntot))
    return ntot*alpha[0],aic1,aic2,cgmr,alpha,mu,sigma,z
예제 #2
0
def RMIrichness(ra=None,
                dec=None,
                photoz=None,
                cat=None,
                plot=True,
                err=True,
                rw=True,
                bcg=True):
    fra = cat.field('ra')
    fdec = cat.field('dec')
    imag = cat.field('imag')
    rmi = cat.field('model_mag')[:, 2] - cat.field('model_mag')[:, 3]
    rmierr = np.sqrt(
        cat.field('model_magerr')[:, 2]**2 +
        cat.field('model_magerr')[:, 3]**2)
    depth = 12
    h = es.htm.HTM(depth)
    srad = np.rad2deg(1. / Da(0, photoz))
    m1, m2, d12 = h.match(ra, dec, fra, fdec, srad, maxmatch=50000)
    r12 = np.deg2rad(d12) * Da(0, photoz)
    cimag = imag[m2[0]]
    crmi = rmi[m2[0]]
    if bcg is True:
        indices = (imag[m2] <= limi0_2(photoz)) * (imag[m2] > cimag)
    else:
        indices = (imag[m2] <= limi0_2(photoz))
    ntot = len(m2[indices])
    if ntot <= 10:
        return 'not enough galaxy brighter than 0.2 L*'
    alpha = np.array([0.5, 0.5])
    mu = np.array([
        sts.scoreatpercentile(rmi[m2[indices]], per=70),
        sts.scoreatpercentile(rmi[m2[indices]], per=40)
    ])
    sigma = np.array([0.04, 0.3])
    if err is True:
        if rw is False:
            aic2 = gmm.aic_ecgmm(rmi[m2[indices]], rmierr[m2[indices]], alpha,
                                 mu, sigma)
            aic1 = gmm.wstat(rmi[m2[indices]], rmierr[m2[indices]])[3]
        else:
            aic2, alpha, mu, sigma = rwgmm.aic2EM(rmi[m2[indices]],
                                                  rmierr[m2[indices]],
                                                  r12[indices], alpha, mu,
                                                  sigma)
            aic1 = rwgmm.aic1EM(rmi[m2[indices]], rmierr[m2[indices]],
                                r12[indices])[0]
    else:
        aic2 = gmm.aic_ecgmm(rmi[m2[indices]],
                             aalpha=alpha,
                             mmu=mu,
                             ssigma=sigma)
        aic1 = gmm.wstat(rmi[m2[indices]])[3]
    srt = np.argsort(sigma)
    alpha = alpha[srt]
    mu = mu[srt]
    sigma = sigma[srt]
    z = rmiz(mu[0])
    if plot == True:
        pl.figure(figsize=(12, 6))
        pl.subplot(1, 2, 1)
        hh = pl.hist(rmi[m2[indices]],
                     bins=50,
                     normed=True,
                     facecolor='green',
                     alpha=0.3,
                     range=[-1, 3])
        pl.vlines(crmi,
                  0,
                  hh[0].max() + 0.5,
                  color='red',
                  lw=2,
                  linestyle='dashed')
        pl.grid()
        x = np.arange(-1, 3, 0.01)
        t = gmm.ecgmmplot(x, alpha, mu, sigma)
        richness = ntot * alpha[0]
        pl.xlabel('r - i')
        pl.figtext(0.61, 0.85, 'Relative Weights: ' + str(np.round(alpha, 4)))
        pl.figtext(0.61, 0.8, 'Mean Colors: ' + str(np.round(mu, 4)))
        pl.figtext(0.61, 0.75, 'Mean Color Widths: ' + str(np.round(sigma, 4)))
        pl.figtext(0.61, 0.68, 'Richness: ' + str(np.round(richness, 2)))
        pl.figtext(0.61, 0.61, r'$AIC_1$: ' + str(aic1))
        pl.figtext(0.61, 0.54, r'$AIC_2$: ' + str(aic2))
        pl.figtext(0.61, 0.47, 'Test Photoz: ' + str(photoz))
        pl.figtext(0.61, 0.4, 'Ridgeline Photoz: ' + str(round(z, 3)))
        pl.figtext(0.61, 0.33,
                   'R200: ' + str(round(0.09 * richness**0.798, 2)) + ' Mpc')
        pl.figtext(
            0.61, 0.25, 'M200: ' + str(round(8.8 * (richness / 19.)**1.7, 2)) +
            'x10^13 Solar Mass')
        pl.title('Total # of galaxies: ' + str(ntot))
    return richness, aic1, aic2, crmi, alpha, mu, sigma, z
예제 #3
0
def gmbcgFinder(objID=None,
                ra=None,
                dec=None,
                photoz=None,
                color=None,
                colorErr=None,
                mag=None,
                bcgCandidateIdx=None):
    #--define some quantity to be returned ----
    BCGIdx = []
    BCGobjID = []
    BCGalpha0 = []
    BCGalpha1 = []
    BCGmu0 = []
    BCGmu1 = []
    BCGsigma0 = []
    BCGsigma1 = []
    BCGntot = []
    BCGamp = []
    BCGaic1 = []
    BCGaic2 = []
    #-----------------------------------------
    cra = ra[bcgCandidateIdx]
    cdec = dec[bcgCandidateIdx]
    cmag = mag[bcgCandidateIdx]
    cphotoz = photoz[bcgCandidateIdx]
    Ncandidates = len(cphotoz)
    ridgeZ = np.zeros(Ncandidates)
    depth = 10
    h = es.htm.HTM(depth)
    Cosmo = es.cosmology.Cosmo(h=0.7)
    DA = Cosmo.Da(0, cphotoz)
    srad = np.rad2deg(1. / DA)
    m1, m2, d12 = h.match(cra, cdec, ra, dec, srad, maxmatch=5000)
    r12 = np.deg2rad(d12) * DA[m1]
    indices = (mag[m2] <= limz(cphotoz[m1])) * (cmag[m1] < mag[m2])
    m1 = m1[indices]
    m2 = m2[indices]
    h, rev = es.stat.histogram(m1, binsize=1, rev=True)
    startTime = time.time()
    for i in range(h.size):
        if rev[i] < rev[i + 1]:
            print i
            indx = rev[rev[i]:rev[i + 1]]
            alpha = np.array([0.5, 0.5])
            mu = np.array([
                sts.scoreatpercentile(color[m2[indx]], per=70),
                sts.scoreatpercentile(color[m2[indx]], per=40)
            ])
            sigma = np.array([0.04, 0.3])
            aic2, alpha, mu, sigma = rwgmm.aic2EM(color[m2[indx]],
                                                  colorErr[m2[indx]],
                                                  r12[indx], alpha, mu, sigma)
            aic1 = rwgmm.aic1EM(color[m2[indx]], colorErr[m2[indx]],
                                r12[indx])[0]
            if aic2 < aic1:
                srt = np.argsort(sigma)
                BCGIdx.append(bcgCandidateIdx[m1[indx[0]]])
                BCGobjID.append(objID[bcgCandidateIdx[m1[indx[0]]]])
                BCGalpha0.append(alpha[srt[0]])
                BCGalpha1.append(alpha[srt[1]])
                BCGmu0.append(mu[srt[0]])
                BCGmu1.append(mu[srt[1]])
                BCGsigma0.append(sigma[srt[0]])
                BCGsigma1.append(sigma[srt[1]])
                BCGaic1.append(aic1)
                BCGaic2.append(aic2)
                BCGamp.append(len(indx) * alpha[srt[0]])
            else:
                BCGIdx.append(bcgCandidateIdx[m1[indx[0]]])
                BCGobjID.append(objID[bcgCandidateIdx[m1[indx[0]]]])
                BCGalpha0.append(-999)
                BCGalpha1.append(-999)
                BCGmu0.append(-999)
                BCGmu1.append(-999)
                BCGsigma0.append(-999)
                BCGsigma1.append(-999)
                BCGaic1.append(-999)
                BCGaic2.append(-999)
                BCGamp.append(-999)
        elif rev[i] == rev[i + 1]:
            indx = rev[rev[i]]
            BCGIdx.append(bcgCandidateIdx[m1[indx]])
            BCGobjID.append(objID[bcgCandidateIdx[m1[indx]]])
            BCGalpha0.append(-999)
            BCGalpha1.append(-999)
            BCGmu0.append(-999)
            BCGmu1.append(-999)
            BCGsigma0.append(-999)
            BCGsigma1.append(-999)
            BCGaic1.append(-999)
            BCGaic2.append(-999)
            BCGamp.append(-999)
    endTime = time.time()
    elapseTime = endTime - startTime
    print '---elapsed time: ' + str(elapseTime)
    return np.array(BCGIdx), np.array(BCGobjID), np.array(BCGalpha0), np.array(
        BCGalpha1), np.array(BCGmu0), np.array(BCGmu1), np.array(
            BCGsigma0), np.array(BCGsigma1), np.array(BCGaic1), np.array(
                BCGaic2), np.array(BCGamp)
예제 #4
0
def ZMYrichness(ra=None,
                dec=None,
                photoz=None,
                cat=None,
                plot=True,
                err=True,
                rw=True,
                bcg=True):
    fra = cat.field('ra')
    fdec = cat.field('dec')
    imag = cat.field('mag_z')
    zmy = cat.field('mag_z') - cat.field('mag_y')
    zmyerr = np.sqrt(cat.field('MAGERR_z')**2 + cat.field('MAGERR_y')**2)
    depth = 10
    h = es.htm.HTM(depth)
    srad = np.rad2deg(1. / Da(0, photoz))
    m1, m2, d12 = h.match(ra, dec, fra, fdec, srad, maxmatch=5000)
    cimag = imag[m2[0]]
    czmy = zmy[m2[0]]
    r12 = np.deg2rad(d12) * Da(0, photoz)
    if bcg is True:
        indices = (imag[m2] <= limi(photoz)) * (imag[m2] > cimag)
    else:
        indices = (imag[m2] <= limi(photoz))
    ntot = len(m2[indices])
    if ntot <= 10:
        return 0, 0, 0
    alpha = np.array([0.5, 0.5])
    mu = np.array([
        sts.scoreatpercentile(zmy[m2[indices]], per=70),
        sts.scoreatpercentile(zmy[m2[indices]], per=40)
    ])
    sigma = np.array([0.04, 0.3])
    if err is True:
        if rw is False:
            aic2 = gmm.aic_ecgmm(zmy[m2[indices]], zmyerr[m2[indices]], alpha,
                                 mu, sigma)
            aic1 = gmm.wstat(zmy[m2[indices]], zmyerr[m2[indices]])[3]
        else:
            aic2, alpha, mu, sigma = rwgmm.aic2EM(zmy[m2[indices]],
                                                  zmyerr[m2[indices]],
                                                  r12[indices], alpha, mu,
                                                  sigma)
            aic1 = rwgmm.aic1EM(zmy[m2[indices]], zmyerr[m2[indices]],
                                r12[indices])[0]
    else:
        aic2 = gmm.aic_ecgmm(zmy[m2[indices]],
                             aalpha=alpha,
                             mmu=mu,
                             ssigma=sigma)
        aic1 = gmm.wstat(zmy[m2[indices]])[3]
    if plot == True:
        pl.hist(zmy[m2[indices]],
                bins=30,
                normed=True,
                facecolor='green',
                alpha=0.3)
        pl.vlines(czmy, 0, 3, color='pink')
        x = np.arange(-1, 5, 0.01)
        srt = np.argsort(sigma)
        alpha = alpha[srt]
        mu = mu[srt]
        sigma = sigma[srt]
        t = gmm.ecgmmplot(x, alpha, mu, sigma)
        pl.xlabel('i - z')
        pl.figtext(0.61, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)))
        pl.figtext(0.61, 0.8, r'$\mu$: ' + str(np.round(mu, 4)))
        pl.figtext(0.61, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)))
        pl.figtext(0.61, 0.68,
                   r'$Amplitude$: ' + str(np.round(ntot * alpha[0], 2)))
        pl.figtext(0.61, 0.61, r'$AIC_1$: ' + str(aic1))
        pl.figtext(0.61, 0.54, r'$AIC_2$: ' + str(aic2))
        pl.figtext(0.61, 0.47, 'Photoz: ' + str(photoz))
        pl.title('Total # of galaxies: ' + str(ntot))
    return ntot * alpha[0], aic1, aic2
예제 #5
0
def gmbcgFinder(objID=None,ra=None, dec=None, photoz=None,color=None,colorErr=None,mag=None,bcgCandidateIdx=None):
    #--define some quantity to be returned ----
    BCGIdx = []
    BCGobjID = []
    BCGalpha0 = []
    BCGalpha1 = []
    BCGmu0 = []
    BCGmu1 = []
    BCGsigma0 = []
    BCGsigma1 = []
    BCGntot = []
    BCGamp = []
    BCGaic1 = []
    BCGaic2 = []
    #-----------------------------------------
    cra = ra[bcgCandidateIdx]
    cdec = dec[bcgCandidateIdx]
    cmag = mag[bcgCandidateIdx]
    cphotoz = photoz[bcgCandidateIdx]
    Ncandidates = len(cphotoz)
    ridgeZ = np.zeros(Ncandidates)
    depth = 10
    h=es.htm.HTM(depth)
    Cosmo = es.cosmology.Cosmo(h=0.7)
    DA=Cosmo.Da(0,cphotoz)
    srad=np.rad2deg(1./DA)
    m1,m2,d12 = h.match(cra,cdec,ra,dec,srad,maxmatch=5000)
    r12=np.deg2rad(d12)*DA[m1]
    indices=(mag[m2]<=limz(cphotoz[m1]))*(cmag[m1] < mag[m2])
    m1 = m1[indices]
    m2 = m2[indices]
    h,rev = es.stat.histogram(m1, binsize=1, rev=True)
    startTime=time.time()
    for i in range(h.size):
        if rev[i] < rev[i+1]:
            print i
            indx = rev[ rev[i]:rev[i+1]]
            alpha=np.array([0.5,0.5])
            mu=np.array([sts.scoreatpercentile(color[m2[indx]],per=70),sts.scoreatpercentile(color[m2[indx]],per=40)])
            sigma=np.array([0.04,0.3])
            aic2,alpha,mu,sigma=rwgmm.aic2EM(color[m2[indx]],colorErr[m2[indx]],r12[indx],alpha,mu,sigma)
            aic1 = rwgmm.aic1EM(color[m2[indx]],colorErr[m2[indx]],r12[indx])[0]
            if aic2 < aic1:
                srt=np.argsort(sigma)
                BCGIdx.append(bcgCandidateIdx[m1[indx[0]]])
                BCGobjID.append(objID[bcgCandidateIdx[m1[indx[0]]]])
                BCGalpha0.append(alpha[srt[0]])
                BCGalpha1.append(alpha[srt[1]])
                BCGmu0.append(mu[srt[0]])
                BCGmu1.append(mu[srt[1]])
                BCGsigma0.append(sigma[srt[0]])
                BCGsigma1.append(sigma[srt[1]])
                BCGaic1.append(aic1)
                BCGaic2.append(aic2)
                BCGamp.append(len(indx)*alpha[srt[0]]) 
            else:
                BCGIdx.append(bcgCandidateIdx[m1[indx[0]]])
                BCGobjID.append(objID[bcgCandidateIdx[m1[indx[0]]]])
                BCGalpha0.append(-999)
                BCGalpha1.append(-999)
                BCGmu0.append(-999)
                BCGmu1.append(-999)
                BCGsigma0.append(-999)
                BCGsigma1.append(-999)
                BCGaic1.append(-999)
                BCGaic2.append(-999)
                BCGamp.append(-999)  
        elif rev[i] == rev[i+1]:
            indx = rev[ rev[i]]
            BCGIdx.append(bcgCandidateIdx[m1[indx]])
            BCGobjID.append(objID[bcgCandidateIdx[m1[indx]]])
            BCGalpha0.append(-999)
            BCGalpha1.append(-999)
            BCGmu0.append(-999)
            BCGmu1.append(-999)
            BCGsigma0.append(-999)
            BCGsigma1.append(-999)
            BCGaic1.append(-999)
            BCGaic2.append(-999)
            BCGamp.append(-999) 
    endTime=time.time()
    elapseTime=endTime-startTime
    print '---elapsed time: ' + str(elapseTime)
    return np.array(BCGIdx), np.array(BCGobjID),np.array(BCGalpha0),np.array(BCGalpha1),np.array(BCGmu0),np.array(BCGmu1),np.array(BCGsigma0),np.array(BCGsigma1),np.array(BCGaic1),np.array(BCGaic2),np.array(BCGamp)