px = 0.5 dell = 10 bin_edges = np.arange(kmin, kmax, dell) + dell theory = loadTheorySpectraFromCAMB(cambRoot, unlensedEqualsLensed=False, useTotal=False, lpad=9000) lmap = lm.makeEmptyCEATemplate(raSizeDeg=deg, decSizeDeg=deg, pixScaleXarcmin=px, pixScaleYarcmin=px) myNls = NlGenerator(lmap, theory, bin_edges, gradCut=gradCut) ellkk = np.arange(2, 9000, 1) Clkk = theory.gCl("kk", ellkk) pl = Plotter(scaleY='log', scaleX='log') sns = [] snsM = [] overdensity = 500. critical = True atClusterZ = True kellmax = 8000 outDir = "/gpfs01/astro/www/msyriac/plots/" for beam in beamrange: beamX = beam beamY = beam print beam
doCurl=False, TOnly=True, halo=True, gradCut=10000, verbose=True) # CHECK THAT NORM MATCHES HU/OK data2d = qest.AL['TT'] modLMap = qest.N.modLMap bin_edges = np.arange(2, kellmax, 10) centers, Nlbinned = binInAnnuli(data2d, modLMap, bin_edges) huFile = '/astro/u/msyriac/repos/cmb-lensing-projections/data/NoiseCurvesKK/hu_tt.csv' huell, hunl = np.loadtxt(huFile, unpack=True, delimiter=',') pl = Plotter(scaleY='log', scaleX='log') pl.add(ellkk, 4. * Clkk / 2. / np.pi) pl.add(centers, 4. * Nlbinned / 2. / np.pi) #,ls="none",marker="o") pl.add(huell, hunl, ls='--') #,ls="none",marker="o") pl.done("testbin.png") passMap = bigMap[:, :] * window[:, :] passMap = passMap - passMap.mean() if k == 0: pl = Plotter() pl.plot2d(passMap) pl.done("bigmap.png") print "Reconstructing", i, " ..." qest.updateTEB_X(passMap.astype(float) / 2.7255e6)
def main(argv): # Read some parameters from the ini file config = ConfigParser.SafeConfigParser() config.read("input/general.ini") fileRoot = config.get('sims', 'root_location') + config.get( 'sims', 'sim_root') savePath = config.get('sims', 'root_location') + "output/" istart = config.getint('sims', 'istart') iend = config.getint('sims', 'iend') widthArcmin = config.getfloat('cutouts', 'widthArcmin') pixScaleArcmin = config.getfloat('sims', 'pixScaleArcmin') npixx = int(widthArcmin / pixScaleArcmin / 2.) npixy = int(widthArcmin / pixScaleArcmin / 2.) stackTot = 0. # stack on lensed cmb + sz stackSZ = 0. # stack on sz stackDx = 0. # stack on deflection_x stackDy = 0. # stack on deflection_y stackKappa = 0. # stack on kappa = div.Deflection / 2 stackAlt = 0. # stack on kappa = div.Deflection / 2 calculated with FFTs stackEst = 0. # stack on kappa reconstruction totnum = 0 # total number of stamps read skip = 0 # number skipped because stamp falls outside edges for i in range(istart, iend + 1): froot = fileRoot + str(i).zfill(3) # read catalog of clusters and make a selection on mass catFile = froot + ".txt" xcens, ycens, m200s = np.loadtxt(catFile, unpack=True, usecols=[1, 2, 6]) selection = m200s > 1.e14 # open cmb map imgFile = froot + "_tSZ_MOD.fits" print "Loading fits file ", i, "with ", len( xcens[selection]), " clusters ..." hd = pyfits.open(imgFile) # open kappa reconstruction and apply a dumb correction to the pixel scale lmap = lm.liteMapFromFits(savePath + "kappa" + str(i).zfill(3) + ".fits") px = np.abs(lmap.x1-lmap.x0)/lmap.Nx*np.pi/180.\ *np.cos(np.pi/180.*0.5*(lmap.y0+lmap.y1))*180./np.pi*60. lmap.pixScaleX = px / 180. * np.pi / 60. print "pixel scale arcminutes X , ", lmap.pixScaleX * 180. * 60. / np.pi print "pixel scale arcminutes X , ", lmap.pixScaleY * 180. * 60. / np.pi tot = hd[0].data sz = hd[6].data + hd[7].data unl = hd[3].data dx = hd[8].data * np.pi / 180. / 60. dy = hd[9].data * np.pi / 180. / 60. pl = Plotter() pl.plot2d(dx) pl.done("dx.png") pl = Plotter() pl.plot2d(dy) pl.done("dy.png") kappa = 0.5 * (np.gradient(dx, axis=0) + np.gradient(dy, axis=1)) pl = Plotter() pl.plot2d(kappa) pl.done("rkappa.png") diffmap = tot - sz - unl #alt kappa import orphics.analysis.flatMaps as fmaps lxMap, lyMap, modLMap, thetaMap, lx, ly = fmaps.getFTAttributesFromLiteMap( lmap) win = fmaps.initializeCosineWindow(lmap, lenApod=100, pad=10) Ny = lmap.Ny kgradx = lx * fft2(dy * win) * 1j kgrady = ly.reshape((Ny, 1)) * fft2(dx * win) * 1j altkappa = 0.5 * ifft2(kgradx + kgrady).real saveMap = lmap.copy() saveMap.data = altkappa saveMap.writeFits(savePath + "inputKappa" + str(i).zfill(3) + ".fits", overWrite=True) pl = Plotter() pl.plot2d(altkappa) pl.done("fkappa.png") if i == 0: pl = Plotter() pl.plot2d(diffmap * win) pl.done("diff.png") #sys.exit() bigY, bigX = tot.shape print "Map area ", bigX * bigY * pixScaleArcmin * pixScaleArcmin / 60. / 60., " sq. deg." doRandom = False if doRandom: xlbound = xcens[selection].min() xrbound = xcens[selection].max() ylbound = ycens[selection].min() yrbound = ycens[selection].max() for xcen, ycen, m200 in zip(xcens[selection], ycens[selection], m200s[selection]): totnum += 1 if doRandom: xcen = np.random.randint(xlbound, xrbound) ycen = np.random.randint(ylbound, yrbound) else: xcen = int(xcen) ycen = int(ycen) if ycen - npixy < 0 or xcen - npixx < 0 or ycen + npixy > ( bigY - 1) or xcen + npixx > (bigX - 1): skip += 1 continue cutOutTot = tot[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutSZ = sz[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutDx = dx[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutDy = dy[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutKappa = kappa[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutAlt = altkappa[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] cutOutEst = lmap.data[(ycen - npixy):(ycen + npixy), (xcen - npixx):(xcen + npixx)] stackTot += cutOutTot stackSZ += cutOutSZ stackDx += cutOutDx stackDy += cutOutDy stackKappa += cutOutKappa stackAlt += cutOutAlt stackEst += cutOutEst print "Percentage near bounds = ", skip * 100. / totnum, " %" if doRandom: rs = "R" else: rs = "" N = totnum - skip stackD = np.sqrt(stackDx**2. + stackDy**2.) pl = Plotter() pl.plot2d(stackD / N) pl.done("plots/stackD" + rs + ".png") pl = Plotter() pl.plot2d(stackKappa / N) pl.done("plots/stackK" + rs + ".png") pl = Plotter() pl.plot2d(stackAlt / N) pl.done("plots/stackA" + rs + ".png") pl = Plotter() pl.plot2d(stackTot / N) pl.done("plots/stackTot" + rs + ".png") pl = Plotter() pl.plot2d(stackSZ / N) pl.done("plots/stackSZ" + rs + ".png") pl = Plotter() pl.plot2d(stackEst / N) pl.done("plots/stackE" + rs + ".png")
tellminX, tellmaxX, pellminX, pellmaxX, beamY=beamY, noiseTY=noiseTY, noisePY=noisePY, tellminY=tellminY, tellmaxY=tellmaxY, pellminY=pellminY, pellmaxY=pellmaxY) ls, Nls = myNls.getNl(polComb=polComb, halo=halo) ellkk = np.arange(2, 9000, 1) Clkk = theory.gCl("kk", ellkk) pl = Plotter(scaleY='log', scaleX='log') pl.add(ellkk, 4. * Clkk / 2. / np.pi) pl.add(ls, 4. * Nls / 2. / np.pi, label="act,act") beamX = 7.0 noiseTX = 30. noisePX = np.sqrt(2.) * noiseTX tellminX = 2 tellmaxX = 3000 myNls.updateNoise(beamX, noiseTX, noisePX, tellminX, tellmaxX, pellminX,
def getDLnMCMB(ells,Nls,clusterCosmology,log10Moverh,z,concentration,arcStamp,pxStamp,arc_upto,bin_width,expectedSN,Nclusters=1000,numSims=30,saveId=None,numPoints=1000,nsigma=8.,overdensity=500.,critical=True,atClusterZ=True): import flipper.liteMap as lm if saveId is not None: from orphics.tools.output import Plotter M = 10.**log10Moverh cc = clusterCosmology stepfilter_ellmax = max(ells) lmap = lm.makeEmptyCEATemplate(raSizeDeg=arcStamp/60., decSizeDeg=arcStamp/60.,pixScaleXarcmin=pxStamp,pixScaleYarcmin=pxStamp) xMap,yMap,modRMap,xx,xy = fmaps.getRealAttributes(lmap) lxMap,lyMap,modLMap,thetaMap,lx,ly = fmaps.getFTAttributesFromLiteMap(lmap) kappaMap,retR500 = NFWkappa(cc,M,concentration,z,modRMap*180.*60./np.pi,winAtLens,overdensity,critical,atClusterZ) finetheta = np.arange(0.01,arc_upto,0.01) finekappa,retR500 = NFWkappa(cc,M,concentration,z,finetheta,winAtLens,overdensity,critical,atClusterZ) kappaMap = fmaps.stepFunctionFilterLiteMap(kappaMap,modLMap,stepfilter_ellmax) generator = fmaps.GRFGen(lmap,ells,Nls) bin_edges = np.arange(0.,arc_upto,bin_width) binner = bin2D(modRMap*180.*60./np.pi, bin_edges) centers, thprof = binner.bin(kappaMap) if saveId is not None: pl = Plotter() pl.plot2d(kappaMap) pl.done("output/"+saveId+"kappa.png") expectedSNGauss = expectedSN*np.sqrt(numSims) sigma = 1./expectedSNGauss amplitudeRange = np.linspace(1.-nsigma*sigma,1.+nsigma*sigma,numPoints) lnLikes = 0. bigStamp = 0. for i in range(numSims): profiles,totstamp = getProfiles(generator,stepfilter_ellmax,kappaMap,binner,Nclusters) bigStamp += totstamp stats = getStats(profiles) if i==0 and (saveId is not None): pl = Plotter() pl.add(centers,thprof,lw=2,color='black') pl.add(finetheta,finekappa,lw=2,color='black',ls="--") pl.addErr(centers,stats['mean'],yerr=stats['errmean'],lw=2) pl._ax.set_ylim(-0.01,0.3) pl.done("output/"+saveId+"profile.png") pl = Plotter() pl.plot2d(totstamp) pl.done("output/"+saveId+"totstamp.png") Likes = getAmplitudeLikelihood(stats['mean'],stats['covmean'],amplitudeRange,thprof) lnLikes += np.log(Likes) width = amplitudeRange[1]-amplitudeRange[0] Likes = np.exp(lnLikes) Likes = Likes / (Likes.sum()*width) #normalize ampBest,ampErr = cfit(norm.pdf,amplitudeRange,Likes,p0=[1.0,0.5])[0] sn = ampBest/ampErr/np.sqrt(numSims) snAll = ampBest/ampErr if snAll<5.: print "WARNING: ", saveId, " run with mass ", M , " and redshift ", z , " has overall S/N<5. \ Consider re-running with a greater numSims, otherwise estimate of per Ncluster S/N will be noisy." if saveId is not None: Fit = np.array([np.exp(-0.5*(x-ampBest)**2./ampErr**2.) for x in amplitudeRange]) Fit = Fit / (Fit.sum()*width) #normalize pl = Plotter() pl.add(amplitudeRange,Likes,label="like") pl.add(amplitudeRange,Fit,label="fit") pl.legendOn(loc = 'lower left') pl.done("output/"+saveId+"like.png") pl = Plotter() pl.plot2d(bigStamp/numSims) pl.done("output/"+saveId+"bigstamp.png") np.savetxt("data/"+saveId+"_m"+str(log10Moverh)+"_z"+str(z)+".txt",np.array([log10Moverh,z,1./sn])) return 1./sn
import ConfigParser config = ConfigParser.SafeConfigParser() config.read("input/general.ini") savePath = config.get('sims', 'root_location') + "output/" N = 38 for i in range(1, N + 1): print i lmap = lm.liteMapFromFits(savePath + "kappa" + str(i).zfill(3) + ".fits") if i == 1: mf = lmap.data * 0. mf += lmap.data mf = mf / (N - 1) lmap = lm.liteMapFromFits(savePath + "kappa000.fits") from orphics.tools.output import Plotter pl = Plotter() pl.plot2d(mf) pl.done("mf.png") pl = Plotter() pl.plot2d(lmap.data - mf) pl.done("mfsub.png")