def rand_map_flat(shape, wcs, ps, lmax=None, lens=True, aberrate=True, beta=None, dir=None, seed=None, dtype=None, verbose=False, recenter=False, pad=0): """Simulate a random flat-sky map. The input spectrum should be [{phi,T,E,B},{phi,T,E,b},nl] of lens is True, and just [{T,E,B},{T,E,B},nl] otherwise.""" if dtype is None: dtype = np.float64 if dir is None: dir = aberration.dir_equ if beta is None: beta = aberration.beta ctype = np.result_type(dtype, 0j) if verbose: print "Generating unlensed cmb" # No position calculation necessary if we're not lensing or aberrating. if not lens and not aberrate: return enmap.rand_map(shape, wcs, ps, seed=seed) # Otherwise we must deal with various displacements if aberrate: pad += np.pi * beta * 1.2 pad_pix = int(pad / enmap.pixsize(shape, wcs)**0.5) if pad_pix > 0: if verbose: print "Padding" template = enmap.zeros(shape, wcs, np.int16) template, pslice = enmap.pad(template, pad_pix, return_slice=True) pshape, pwcs = template.shape, template.wcs else: pshape, pwcs = shape, wcs # Simulate (padded) lensing map if lens: maps = enmap.rand_map((ps.shape[0], ) + pshape[-2:], pwcs, ps) phi, unlensed = maps[0], maps[1:] if verbose: print "Lensing" m = lensing.lens_map_flat(unlensed, phi) else: m = enmap.rand_map((ps.shape[0], ) + pshape[-2:], pwcs, ps) # Then handle aberration if necessary if aberrate: if verbose: print "Computing aberration displacement" pos = m.posmap() pos = enmap.samewcs( aberration.remap(pos[1::-1], dir=dir, beta=beta, recenter=recenter), pos) amp = pos[3] pos = pos[1::-1] if verbose: print "Interpolating aberration" m = enmap.samewcs(m.at(pos, mask_nan=False), m) if verbose: print "Applying modulation" m *= amp if pad_pix > 0: if verbose: print "Unpadding" m = m[pslice] return m
cc = counts.ClusterCosmology(skipCls=True) theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False, useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False) # Geometry shape, wcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=args.pix,pol=False) modlmap = enmap.modlmap(shape,wcs) modrmap = enmap.modrmap(shape,wcs) # Binning bin_edges = np.arange(0.,20.0,args.pix*2) binner = stats.bin2D(modrmap*60.*180./np.pi,bin_edges) # Noise model noise_uK_rad = args.noise*np.pi/180./60. normfact = np.sqrt(np.prod(enmap.pixsize(shape,wcs))) kbeam = maps.gauss_beam(args.beam,modlmap) # Simulate lmax = int(modlmap.max()+1) ells = np.arange(0,lmax,1) ps = theory.uCl('TT',ells).reshape((1,1,lmax)) ~ps_noise = np.array([(noise_uK_rad)**2.]*ells.size).reshape((1,1,ells.size)) mg = maps.MapGen(shape,wcs,ps) ng = maps.MapGen(shape,wcs,ps_noise) kamp_true = args.Amp kappa = lensing.nfw_kappa(kamp_true*1e15,modrmap,cc,overdensity=200.,critical=True,atClusterZ=True) phi,_ = lensing.kappa_to_phi(kappa,modlmap,return_fphi=True) grad_phi = enmap.grad(phi) posmap = enmap.posmap(shape,wcs)