c = 3.2 cc = cutils.get_hdv_cc() # Set up lensing def lens_map(imap): return plensing.displace_map(imap, alpha, order=args.lens_order) # Map of distances from center modrmap = enmap.modrmap(shape, wcs) # The convergence ~ projected mass density kappa = lensing.nfw_kappa(massOverh, modrmap, cc, zL=z, concentration=c, overdensity=180., critical=False, atClusterZ=False) if rank == 0: enmap.write_map(f'{savedir}kappa.fits', kappa) # Deflection field alpha = lensing.alpha_from_kappa(kappa) # Fourier magnitude map modlmap = enmap.modlmap(shape, wcs) # Unlensed CMB theory theory = cosmology.default_theory() cltt2d = theory.uCl('TT', modlmap) clte2d = theory.uCl('TE', modlmap) clee2d = theory.uCl('EE', modlmap)
# 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) pos = posmap + grad_phi alpha_pix = enmap.sky2pix(shape,wcs,pos, safe=False) lens_order = 5 if rank==0: print("Starting sims...") # Stats Nsims = args.Nclusters Njobs = Nsims num_each,each_tasks = mpi.mpi_distribute(Njobs,numcores) if rank==0: print ("At most ", max(num_each) , " tasks...") my_tasks = each_tasks[rank]
modrmap = enmap.modrmap(shape, wcs) #kamps = np.linspace(0.01,0.8,40) amp_min = -0.3 amp_max = 0.5 # amp_min = 0.76 # amp_max = 0.84 kamps = np.linspace(amp_min, amp_max, 10) print(kamps) Ccovs = [] Cinvs = [] logdets = [] kappa = lensing.nfw_kappa(1e15, modrmap, cc) phi, _ = lensing.kappa_to_phi(kappa, modlmap, return_fphi=True) grad_phi = enmap.grad(phi) lens_order = 5 posmap = enmap.posmap(shape, wcs) for k, kamp in enumerate(kamps): pos = posmap + kamp * grad_phi alpha_pix = enmap.sky2pix(shape, wcs, pos, safe=False) Scov = lensing.lens_cov(Ucov, alpha_pix, lens_order=lens_order, kbeam=kbeam) # io.plot_img(np.nan_to_num((Scov-Ucov)*100./Ucov))
theory_file_root = "../alhazen/data/Aug6_highAcc_CDM" cc = counts.ClusterCosmology(skipCls=True) theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False, useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False) # Simulate lmax = int(bmodlmap.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(bshape,bwcs,ps) ng = maps.MapGen(bshape,bwcs,ps_noise) kamp_true = args.Amp kappa = lensing.nfw_kappa(kamp_true*1e15,bmodrmap,cc,overdensity=200.,critical=True,atClusterZ=True) phi,_ = lensing.kappa_to_phi(kappa,bmodlmap,return_fphi=True) grad_phi = enmap.grad(phi) posmap = enmap.posmap(bshape,bwcs) pos = posmap + grad_phi alpha_pix = enmap.sky2pix(bshape,bwcs,pos, safe=False) lens_order = 5 ### FG PROFS famps = np.linspace(fmin,fmax,fnum) fg = kappa * 50. fg_true = maps.filter_map(fg.copy()*ftrue,kbeam)
np.random.seed(2) # Theory theory_file_root = "../alhazen/data/Aug6_highAcc_CDM" cc = counts.ClusterCosmology(skipCls=True) theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root, unlensedEqualsLensed=False, useTotal=False, TCMB=2.7255e6, lpad=9000, get_dimensionless=False) lens_func = lambda x: lensing.nfw_kappa(mass, x, cc, zL=0.7, concentration=3.2, overdensity=200., critical=True, atClusterZ=True) #sigma = 1.0 * np.pi/180./60. #lens_func = lambda x: 0.2 * np.exp(-x**2./sigma**2./2.) rshape, rwcs = maps.rect_geometry(width_arcmin=5., px_res_arcmin=0.001) fshape, fwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.1) cshape, cwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.5) rmodrmap = enmap.modrmap(rshape, rwcs) fmodrmap = enmap.modrmap(fshape, fwcs) cmodrmap = enmap.modrmap(cshape, cwcs) rmodlmap = enmap.modlmap(rshape, rwcs) fmodlmap = enmap.modlmap(fshape, fwcs) cmodlmap = enmap.modlmap(cshape, cwcs)
get_dimensionless=False) # 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(oshape, owcs, ps_noise) kamp_true = args.Amp if args.hdv: kappa = lensing.nfw_kappa(kamp_true * 1e15, modrmap, cc, overdensity=180., critical=False, atClusterZ=False) else: 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) pos = posmap + grad_phi alpha_pix = enmap.sky2pix(shape, wcs, pos, safe=False)
print(As) params = {} params['As'] = As params['H0'] = h * 100. params['omch2'] = omch2 params['ombh2'] = ombh2 params['ns'] = ns params['mnu'] = 0. conc = 3.2 cc = counts.ClusterCosmology(params,skipCls=True,skipPower=True,skip_growth=True) z = 0.7 mass = 2e14 thetas = np.geomspace(0.1,10,1000) kappa = lensing.nfw_kappa(mass,thetas*utils.arcmin,cc,zL=z,concentration=conc,overdensity=180,critical=False,atClusterZ=False) hthetas,hkappa = np.loadtxt("data/hdv_unfiltered.csv",unpack=True,delimiter=',') pl = io.Plotter(xyscale='loglog', xlabel='$\\theta$ [arcmin]', ylabel='$\\kappa$') pl.add(thetas,kappa) pl.add(hthetas,hkappa,ls='--') pl.done('test_uhdv.png') pl = io.Plotter(xyscale='linlin', xlabel='$\\theta$ [arcmin]', ylabel='$\\kappa$') pl.add(hthetas,hkappa/maps.interp(thetas,kappa)(hthetas),ls='--') pl.hline(y=1) pl.done('test_uhdv_ratio.png') shape,wcs = enmap.geometry(pos=(0,0),shape=(512,512),res=0.2 * utils.arcmin,proj='plain') kmask = maps.mask_kspace(shape,wcs,lmax=8095)
Nsims = num_amps Njobs = Nsims num_each,each_tasks = mpi.mpi_distribute(Njobs,numcores) if rank==0: print ("At most ", max(num_each) , " tasks...") my_tasks = each_tasks[rank] # File I/O io.mkdir(GridName,comm) cov_name = lambda x: GridName+"/cov_"+str(x)+".npy" if rank==0: print("Rank 0 starting ...") for k,my_task in enumerate(my_tasks): kamp = kamps[my_task] kappa_template = lensing.nfw_kappa(kamp*1e15,bmodrmap,cc,overdensity=200.,critical=True,atClusterZ=True) phi,_ = lensing.kappa_to_phi(kappa_template,bmodlmap,return_fphi=True) grad_phi = enmap.grad(phi) pos = posmap + grad_phi alpha_pix = enmap.sky2pix(bshape,bwcs,pos, safe=False) def do_the_thing(): return lensing.lens_cov(Ucov,alpha_pix,lens_order=lens_order,kbeam=kbeam,bshape=shape) if rank==0: with bench.show("rank 0 lensing cov"): Scov = do_the_thing() else: Scov = do_the_thing()
lcltt2d = theory.lCl('TT', modlmap) # Define our NFW cluster mass = 2e14 c = 3.2 z = 0.7 #cc = counts.ClusterCosmology(skipCls=True,skipPower=True) cc = Cosmology() massOverh = mass / cc.h print(cc.h) # Generate its kappa kappa = lensing.nfw_kappa(massOverh, modrmap, cc, zL=z, concentration=c, overdensity=500., critical=True, atClusterZ=True) #io.plot_img(kappa) # Convert kappa to deflection alpha = lensing.alpha_from_kappa(kappa) # Change number of sims here nsims = 600 comm, rank, my_tasks = mpi.distribute(nsims) # Final beam to apply to kappa map ffwhm = None #2.0