lxMap, lyMap, modLMap, thetaMap, lx, ly = fmaps.getFTAttributesFromLiteMap( lensedTLm) beamTemplate = fmaps.makeTemplate(l, beamells, modLMap) fMaskCMB = fmaps.fourierMask(lx, ly, modLMap, lmin=cmbellmin, lmax=cmbellmax) fMask = fmaps.fourierMask(lx, ly, modLMap, lmin=kellmin, lmax=kellmax) ellNoise = np.arange(0, modLMap.max()) Ntt = ellNoise * 0. + whiteNoiseT Npp = ellNoise * 0. + whiteNoiseP Ntt[0] = 0. Npp[0] = 0. gGenT = fmaps.GRFGen(lensedTLm.copy(), ellNoise, Ntt, bufferFactor=1) gGenP1 = fmaps.GRFGen(lensedTLm.copy(), ellNoise, Npp, bufferFactor=1) gGenP2 = fmaps.GRFGen(lensedTLm.copy(), ellNoise, Npp, bufferFactor=1) if noiseT > 1.e-3: lensedTLm.data = lensedTLm.data + gGenT.getMap(stepFilterEll=None) if noiseP > 1.e-3: lensedQLm.data = lensedQLm.data + gGenP1.getMap(stepFilterEll=None) if noiseP > 1.e-3: lensedULm.data = lensedULm.data + gGenP2.getMap(stepFilterEll=None) # pl = Plotter() # pl.plot2d(lensedTLm.data) # pl.done("map.png") # sys.exit()
tht_fwhm = np.deg2rad(fwhm / 60.) l = np.arange(0., 10000.) beamells = np.exp(-(tht_fwhm**2.) * (l**2.) / (8. * np.log(2.))) beamTemplate = fmaps.makeTemplate(l, beamells, modLMap) noiseT = 0.1 noiseP = np.sqrt(2.) * noiseT whiteNoiseT = (np.pi / (180. * 60))**2. * noiseT**2. / TCMB**2. whiteNoiseP = (np.pi / (180. * 60))**2. * noiseP**2. / TCMB**2. ellNoise = np.arange(0, modLMap.max()) Ntt = ellNoise * 0. + np.nan_to_num(whiteNoiseT) Npp = ellNoise * 0. + np.nan_to_num(whiteNoiseP) Ntt[0] = 0. Npp[0] = 0. gGenT = fmaps.GRFGen(templateLM, ellNoise, Ntt, bufferFactor=1) gGenP1 = fmaps.GRFGen(templateLM, ellNoise, Npp, bufferFactor=1) gGenP2 = fmaps.GRFGen(templateLM, ellNoise, Npp, bufferFactor=1) theory = cc.theory fot = np.zeros((templateLM.Ny, templateLM.Nx)) + 0.j filt_noiseT = fot.copy() * 0. + np.nan_to_num( gGenT.power / beamTemplate[:, :]**2.) filt_noiseE = fot.copy() * 0. + np.nan_to_num( gGenP1.power / beamTemplate[:, :]**2.) filt_noiseB = fot.copy() * 0. + np.nan_to_num( gGenP2.power / beamTemplate[:, :]**2.) gradCut = 2000 cmbellmin = 20 cmbellmax = 8000
l = np.arange(0., 10000.) beamells = np.exp(-(tht_fwhm**2.) * (l**2.) / (8. * np.log(2.))) beamTemplate = fmaps.makeTemplate(l, beamells, modLMap) #print beamTemplate.shape noiseT = 42.0 noiseP = np.sqrt(2.) * noiseT whiteNoiseT = (np.pi / (180. * 60))**2. * noiseT**2. / TCMB**2. whiteNoiseP = (np.pi / (180. * 60))**2. * noiseP**2. / TCMB**2. ellNoise = np.arange(0, modLMap.max()) Ntt = ellNoise * 0. + np.nan_to_num(whiteNoiseT) Npp = ellNoise * 0. + np.nan_to_num(whiteNoiseP) Ntt[0] = 0. Npp[0] = 0. gGenT = fmaps.GRFGen(smap, ellNoise, Ntt, bufferFactor=1) gGenP1 = fmaps.GRFGen(smap, ellNoise, Npp, bufferFactor=1) gGenP2 = fmaps.GRFGen(smap, ellNoise, Npp, bufferFactor=1) theory = cc.theory fot = np.zeros((smap.Ny, smap.Nx)) + 0.j filt_noiseT = fot.copy() * 0. + np.nan_to_num( gGenT.power / beamTemplate[:, :]**2.) filt_noiseE = fot.copy() * 0. + np.nan_to_num( gGenP1.power / beamTemplate[:, :]**2.) filt_noiseB = fot.copy() * 0. + np.nan_to_num( gGenP2.power / beamTemplate[:, :]**2.) gradCut = 2000 cmbellmin = 20 cmbellmax = 4000
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