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
def _ecgmm(c, e, alpha=[0.2,0.8], mu=[0.5,1.2], sigma=[0.5,0.05], flavour='BIC', bootstrap=False): """ Error-Corrected Gaussian Mixture Model (ECGMM) by Hao et al. (2009) Everything is coded in their script so here just execute it. Parameters ---------- c : float array galaxy colours e : float array galaxy colour uncertainties alpha : float array-like initial guess for the mixing of the Gaussian models mu : float array-like initial guess for the locations of the Gaussians sigma : float array-like initial guess for the widths of the Gaussians flavour : {'AIC', 'BIC'} which information criterion to use bootstrap : False or int whether to bootstrap the ECGMM and, if so, how many bootstrap samples to use """ if bootstrap is not False: gmm = ecgmmPy.bsecgmm(c, e, alpha, mu, sigma, nboot=100, InfoCriteria=flavour) elif flavour.upper() == 'AIC': gmm = ecgmmPy.aic_ecgmm(c, e, alpha, mu, sigma) elif flavour.upper() == 'BIC': gmm = ecgmmPy.bic_ecgmm(c, e, alpha, mu, sigma) return alpha, mu, sigma
def ecgmmRidgeZbin(z=None,color=None,colorErr=None,mag=None): #--define some quantity to be returned ---- ok = (color>=-1) * (color <= 5.) color = color[ok] colorErr = colorErr[ok] mag = mag[ok] z = z[ok] alpha0 = [] alpha1 = [] mu0 = [] mu1 = [] sigma0 = [] sigma1 = [] ntot = [] amp = [] aic1 = [] aic2 = [] zmd=[] #----------------------------------------- startTime=time.time() h,rev = es.stat.histogram(z,binsize=0.006,rev=True) for i in range(h.size): if rev[i] != rev[i+1]: indices = rev[rev[i]:rev[i+1]] zmed = np.mean(z[indices]) ok = mag[indices] <= limz(zmed) indices = indices[ok] alpha=np.array([0.5,0.5]) mu=np.array([sts.scoreatpercentile(color[indices],per=70),sts.scoreatpercentile(color[indices],per=40)]) sigma=np.array([0.04,0.3]) a2 = gmm.aic_ecgmm(color[indices],colorErr[indices],alpha,mu,sigma) a1 = gmm.wstat(color[indices],colorErr[indices])[2] if a2 < a1: srt=np.argsort(sigma) alpha0.append(alpha[srt[0]]) alpha1.append(alpha[srt[1]]) mu0.append(mu[srt[0]]) mu1.append(mu[srt[1]]) sigma0.append(sigma[srt[0]]) sigma1.append(sigma[srt[1]]) aic1.append(a1) aic2.append(a2) amp.append(len(indices)*alpha[srt[0]]) zmd.append(zmed) print a2, a1 endTime=time.time() elapseTime=endTime-startTime print '---elapsed time: ' + str(elapseTime) return np.array(alpha0),np.array(alpha1),np.array(mu0),np.array(mu1),np.array(sigma0),np.array(sigma1),np.array(aic1),np.array(aic2),np.array(amp),np.array(zmd)
def IMZrichness(ra, dec, photoz, cat, plot=True): fra = cat.field('ra') fdec = cat.field('dec') imag = cat.field('model_counts')[:, 3] imz = cat.field('imz') imzerr = cat.field('imz_err') depth = 12 h = es.htm.HTM(depth) srad = np.rad2deg(1. / es.cosmology.Da(0, photoz, h=0.7) / (1 + photoz)) m1, m2, d12 = h.match(ra, dec, fra, fdec, srad, maxmatch=5000) indices = (imag[m2] <= limi(photoz)) ntot = len(m2[indices]) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(imz[m2[indices]], per=70), sts.scoreatpercentile(imz[m2[indices]], per=40) ]) sigma = np.array([0.04, 0.3]) aic2 = gmm.aic_ecgmm(imz[m2[indices]], imzerr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(imz[m2[indices]], imzerr[m2[indices]])[3] if plot == True: pl.hist(imz[m2[indices]], bins=30, normed=True, histtype='step') 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'$Ngals$: ' + str(np.round(ntot * alpha[0]))) 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]
def ecgmmRidge(ra_c=None, dec_c=None, photoz_c=None, r200_c=None, ra=None, dec=None, color=None, colorErr=None, mag=None, candidateIdx=None): #--define some quantity to be returned ---- rac = ra_c[candidateIdx] decc = dec_c[candidateIdx] photozc = photoz_c[candidateIdx] r200c = r200_c[candidateIdx] ok = (color >= -1) * (color <= 5.) * abs(colorErr) < 0.5 color = color[ok] colorErr = colorErr[ok] mag = mag[ok] ra = ra[ok] dec = dec[ok] BCGalpha0 = [] BCGalpha1 = [] BCGmu0 = [] BCGmu1 = [] BCGsigma0 = [] BCGsigma1 = [] BCGntot = [] BCGamp = [] BCGaic1 = [] BCGaic2 = [] BCGphotoz = [] #----------------------------------------- Ncandidates = len(photozc) ridgeZ = np.zeros(Ncandidates) depth = 10 h = es.htm.HTM(depth) Cosmo = es.cosmology.Cosmo(h=0.7) DA = Cosmo.Da(0, photozc) srad = np.rad2deg(r200c / DA) m1, m2, d12 = h.match(rac, decc, ra, dec, srad, maxmatch=5000) r12 = np.deg2rad(d12) * DA[m1] indices = (mag[m2] <= limz(photozc[m1])) # no bcg assumed 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 = gmm.aic_ecgmm(color[m2[indx]], colorErr[m2[indx]], alpha, mu, sigma) aic1 = gmm.wstat(color[m2[indx]], colorErr[m2[indx]])[2] print aic2, aic1 if aic2 < aic1: srt = np.argsort(sigma) 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]]) BCGphotoz.append(photozc[m1[indx[0]]]) endTime = time.time() elapseTime = endTime - startTime print '---elapsed time: ' + str(elapseTime) return 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), np.array(BCGphotoz)
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
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
def redsker(b, idx, err=True): depth = 12 h = es.htm.HTM(depth) ra = b.field('ra') dec = b.field('dec') photoz = b.field('z') central = b.field('central') gmr = b.field('omag')[:, 0] - b.field('omag')[:, 1] rmi = b.field('omag')[:, 1] - b.field('omag')[:, 2] imz = b.field('omag')[:, 2] - b.field('omag')[:, 3] gmz = b.field('omag')[:, 0] - b.field('omag')[:, 3] rmz = b.field('omag')[:, 1] - b.field('omag')[:, 3] gmi = b.field('omag')[:, 0] - b.field('omag')[:, 2] num = len(ra) if err: gmrerr = b.field('omagerr')[:, 0] - b.field('omagerr')[:, 1] rmierr = b.field('omagerr')[:, 1] - b.field('omagerr')[:, 2] imzerr = b.field('omagerr')[:, 2] - b.field('omagerr')[:, 3] gmzerr = b.field('omagerr')[:, 0] - b.field('omagerr')[:, 3] rmzerr = b.field('omagerr')[:, 1] - b.field('omagerr')[:, 3] gmierr = b.field('omagerr')[:, 0] - b.field('omagerr')[:, 2] else: gmrerr = np.zeros(num) rmierr = np.zeros(num) imzerr = np.zeros(num) gmzerr = np.zeros(num) rmzerr = np.zeros(num) gmierr = np.zeros(num) iamag = b.field('amag')[:, 2] imag = b.field('omag')[:, 2] srad = np.rad2deg(1. / es.cosmology.Da(0, photoz[idx], h=0.7) / (1 + photoz[idx])) m1, m2, d12 = h.match(ra[idx], dec[idx], ra, dec, srad, maxmatch=5000) indices = (imag[m2] <= limi(photoz[idx])) * (imag[m2] > imag[m1]) #indices=(iamag[m2]<=-20)*(iamag[m2]>iamag[m1]) ntot = len(m2[indices]) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(gmr[m2[indices]], per=80), sts.scoreatpercentile(gmr[m2[indices]], per=30) ]) sigma = np.array([0.04, 0.3]) aic2 = gmm.aic_ecgmm(gmr[m2[indices]], gmrerr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(gmr[m2[indices]], gmrerr[m2[indices]])[3] fig = pl.figure(figsize=(15, 8)) ax = fig.add_subplot(2, 3, 1) pl.hist(gmr[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('g - r') pl.title('M200: ' + str(b[idx].field('m200'))) pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(rmi[m2[indices]], per=80), sts.scoreatpercentile(rmi[m2[indices]], per=30) ]) sigma = np.array([0.04, 0.3]) aic2 = gmm.aic_ecgmm(rmi[m2[indices]], rmierr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(rmi[m2[indices]], rmierr[m2[indices]])[3] ax = fig.add_subplot(2, 3, 2) pl.hist(rmi[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('r - i') pl.title('photoz: ' + str(photoz[idx])) pl.xlim(-0.2, 2.5) pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(imz[m2[indices]], per=60), sts.scoreatpercentile(imz[m2[indices]], per=30) ]) sigma = np.array([0.02, 0.3]) aic2 = gmm.aic_ecgmm(imz[m2[indices]], imzerr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(imz[m2[indices]], imzerr[m2[indices]])[3] ax = fig.add_subplot(2, 3, 3) pl.hist(imz[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('i - z') pl.title('Ntot: ' + str(ntot)) pl.xlim(-0.2, 2.5) pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(gmz[m2[indices]], per=60), sts.scoreatpercentile(gmz[m2[indices]], per=30) ]) sigma = np.array([0.02, 0.3]) aic2 = gmm.aic_ecgmm(gmz[m2[indices]], gmzerr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(gmz[m2[indices]], gmzerr[m2[indices]])[3] ax = fig.add_subplot(2, 3, 4) pl.hist(gmz[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('g - z') pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(rmz[m2[indices]], per=60), sts.scoreatpercentile(rmz[m2[indices]], per=30) ]) sigma = np.array([0.02, 0.3]) aic2 = gmm.aic_ecgmm(rmz[m2[indices]], rmzerr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(rmz[m2[indices]], rmzerr[m2[indices]])[3] ax = fig.add_subplot(2, 3, 5) pl.hist(rmz[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('r - z') pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) alpha = np.array([0.5, 0.5]) mu = np.array([ sts.scoreatpercentile(gmi[m2[indices]], per=60), sts.scoreatpercentile(gmi[m2[indices]], per=30) ]) sigma = np.array([0.02, 0.3]) aic2 = gmm.aic_ecgmm(gmi[m2[indices]], gmierr[m2[indices]], alpha, mu, sigma) aic1 = gmm.wstat(gmi[m2[indices]], gmierr[m2[indices]])[3] ax = fig.add_subplot(2, 3, 6) pl.hist(gmi[m2[indices]], bins=30, normed=True, histtype='step') x = np.arange(-1, 5, 0.01) t = gmm.ecgmmplot(x, alpha, mu, sigma) pl.xlabel('g - i') pl.text(0.1, 0.85, r'$\alpha$: ' + str(np.round(alpha, 4)), transform=ax.transAxes) pl.text(0.1, 0.8, r'$\mu$: ' + str(np.round(mu, 4)), transform=ax.transAxes) pl.text(0.1, 0.75, r'$\sigma$: ' + str(np.round(sigma, 4)), transform=ax.transAxes) pl.text(0.1, 0.68, r'$Ngals$: ' + str(np.round(ntot * alpha[0])), transform=ax.transAxes) pl.text(0.1, 0.6, r'$AIC$: ' + str(np.round(aic1)) + ', ' + str(np.round(aic2)), transform=ax.transAxes) return ('Plot is done!')
def ecgmmRidge(ra_c=None, dec_c=None,photoz_c=None,r200_c=None,ra=None, dec=None,color=None,colorErr=None,mag=None,candidateIdx=None): #--define some quantity to be returned ---- rac = ra_c[candidateIdx] decc = dec_c[candidateIdx] photozc = photoz_c[candidateIdx] r200c = r200_c[candidateIdx] ok = (color>=-1) * (color <= 5.)*abs(colorErr) < 0.5 color = color[ok] colorErr = colorErr[ok] mag = mag[ok] ra = ra[ok] dec = dec[ok] BCGalpha0 = [] BCGalpha1 = [] BCGmu0 = [] BCGmu1 = [] BCGsigma0 = [] BCGsigma1 = [] BCGntot = [] BCGamp = [] BCGaic1 = [] BCGaic2 = [] BCGphotoz=[] #----------------------------------------- Ncandidates = len(photozc) ridgeZ = np.zeros(Ncandidates) depth = 10 h=es.htm.HTM(depth) Cosmo = es.cosmology.Cosmo(h=0.7) DA=Cosmo.Da(0,photozc) srad=np.rad2deg(r200c/DA) m1,m2,d12 = h.match(rac,decc,ra,dec,srad,maxmatch=5000) r12=np.deg2rad(d12)*DA[m1] indices=(mag[m2]<=limz(photozc[m1])) # no bcg assumed 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 = gmm.aic_ecgmm(color[m2[indx]],colorErr[m2[indx]],alpha,mu,sigma) aic1 = gmm.wstat(color[m2[indx]],colorErr[m2[indx]])[2] print aic2, aic1 if aic2 < aic1: srt=np.argsort(sigma) 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]]) BCGphotoz.append(photozc[m1[indx[0]]]) endTime=time.time() elapseTime=endTime-startTime print '---elapsed time: ' + str(elapseTime) return 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),np.array(BCGphotoz)