def test_b_sign(self): """ We generate a random IQU map with geometry such that cdelt[0]<0 We transform this to TEB with map2harm and map2alm followed by scalar harm2map and alm2map and use these as reference T,E,B maps. We flip the original map along the RA direction. We transform this to TEB with map2harm and map2alm followed by scalar harm2map and alm2map and use these as comparison T,E,B maps. We compare these maps. """ ells,cltt,clee,clbb,clte = np.loadtxt(DATA_PREFIX+"cosmo2017_10K_acc3_lensedCls.dat",unpack=True) ps_cmb = np.zeros((3,3,ells.size)) ps_cmb[0,0] = cltt ps_cmb[1,1] = clee ps_cmb[2,2] = clbb ps_cmb[1,0] = clte ps_cmb[0,1] = clte np.random.seed(100) # Curved-sky is fine lmax = 1000 alm = curvedsky.rand_alm_healpy(ps_cmb,lmax=lmax) shape,iwcs = enmap.fullsky_geometry(res=np.deg2rad(10./60.)) wcs = enmap.empty(shape,iwcs)[...,::-1].wcs shape = (3,) + shape imap = curvedsky.alm2map(alm,enmap.empty(shape,wcs)) oalm = curvedsky.map2alm(imap.copy(),lmax=lmax) rmap = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0) imap2 = imap.copy()[...,::-1] oalm = curvedsky.map2alm(imap2.copy(),lmax=lmax) rmap2 = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0) assert np.all(np.isclose(rmap[0],rmap2[0])) assert np.all(np.isclose(rmap[1],rmap2[1])) assert np.all(np.isclose(rmap[2],rmap2[2])) # Flat-sky px = 2.0 N = 300 shape,iwcs = enmap.geometry(pos=(0,0),res=np.deg2rad(px/60.),shape=(300,300)) shape = (3,) + shape a = enmap.zeros(shape,iwcs) a = a[...,::-1] wcs = a.wcs seed = 100 imap = enmap.rand_map(shape,wcs,ps_cmb,seed=seed) kmap = enmap.map2harm(imap.copy()) rmap = enmap.harm2map(kmap,spin=0) # reference map imap = imap[...,::-1] kmap = enmap.map2harm(imap.copy()) rmap2 = enmap.harm2map(kmap,spin=0)[...,::-1] # comparison map assert np.all(np.isclose(rmap[0],rmap2[0])) assert np.all(np.isclose(rmap[1],rmap2[1],atol=1e0)) assert np.all(np.isclose(rmap[2],rmap2[2],atol=1e0))
def get_sim(cmb, task, expid): if expid == 'planck': nid = 1 fwhm = pfwhm nlevel = pnlevel elif expid == 'act': nid = 2 fwhm = afwhm nlevel = anlevel seed = (nid, task) npower = (nlevel * np.pi / 180. / 60.)**2. nmap = enmap.rand_map((1, ) + shape, wcs, np.ones(shape)[None, None] * npower, seed=seed) return maps.filter_map(cmb, maps.gauss_beam(modlmap, fwhm)) + nmap
def map_generate_random_noise(numerics, cosmology, wcs): #{{{ # generate pixel-space noise noise_per_pix = cosmology['noise_rms_muk_arcmin'] / \ (numerics['map_pixel_size'] * 60.0 * \ 180.0 / np.pi) noise_map = np.random.randn(numerics['map_height_pix'], \ numerics['map_width_pix']) * \ noise_per_pix # generate beam-convolved CMB beam_sigma = cosmology['beam_fwhm_arcmin'] * \ np.pi / 180.0 / 60.0 / \ np.sqrt(8.0 * np.log(2.0)) b_l = np.exp(-0.5 * (cosmology['cmb_ell'] * beam_sigma)**2) cmb_map = enmap.rand_map(noise_map.shape, wcs, \ cosmology['cmb_c_l'][None, None, :] * \ b_l[None, None, :] ** 2) return enmap.enmap(cmb_map + noise_map, wcs=wcs)
import numpy as np import matplotlib.pyplot as plt from pixell import enmap # map information shape, wcs = enmap.geometry(shape=(1024, 1024), res=np.deg2rad(0.5 / 60.), pos=(0, 0)) # create power spectrum information ells = np.arange(0, 6000, 1) ps = np.zeros(len(ells)) ps[2:] = 1 / ells[2:]**2.5 # don't want monopole/dipole # generate a realization imap = enmap.rand_map(shape, wcs, ps[np.newaxis, np.newaxis]) # plt.imshow(imap) mask = enmap.ones(imap.shape, imap.wcs) N_point_sources = 50 for i in range(N_point_sources): mask[np.random.randint(low=0, high=mask.shape[0]), np.random.randint(low=0, high=mask.shape[1])] = 0 # apodize the pixels to make fake sources point_source_map = 1 - nw.apod_C2(mask, 0.1) imap += point_source_map # add our sources to the map mask = nw.apod_C2(mask, 0.5) # apodize the mask # # plot our cool results
#mask = sints.get_act_mr3_crosslinked_mask("deep56") #dm = sints.ACTmr3(region=mask,pickupsub=False) # dm = sints.ACTmr3(pickupsub=False) # imap = enmap.pad(dm.get_coadd("s14","deep56","pa1_f150",srcfree=True,ncomp=None)[0],300) # shape,wcs = imap.shape,imap.wcs # shape,wcs = maps.rect_geometry(width_deg=20.,px_res_arcmin=0.5) # imap = enmap.rand_map(shape,wcs,np.ones((1,1,shape[0],shape[1]))) oshape, owcs = enmap.fullsky_geometry(res=np.deg2rad(0.5 / 60.)) Ny = oshape[-2:][0] deg = 5 npix = deg / (0.5 / 60.) shape, wcs = enmap.slice_geometry( oshape, owcs, np.s_[int(Ny // 2 - npix):int(Ny // 2 + npix), :]) imap = enmap.rand_map(shape, wcs, np.ones((1, 1, shape[0], shape[1]))) ta = tiling.TiledAnalysis(shape, wcs, comm) ta.initialize_output("out") for ext, ins in ta.tiles(): emap = ext(imap) emap = filter_map(emap) ta.update_output("out", emap, ins) outmap = ta.get_final_output("out") # print(comm.rank) # io.plot_img(outmap,"rank_%d" % comm.rank) if comm.rank == 0: fcmap = filter_map(imap) io.hplot(enmap.downgrade(imap, 8))
1. Unlensed CMB 2. SZ Point sources 3. a Planck-143 like 2 split system 4. a Planck-100 like 2 split system 5. an S16 pa2 like 2 split system 6. an S16 pa3 like 2 split system with uncorrelated 90 and 150 """ # Make the unlensed CMB realization theory = cosmology.default_theory() ells = np.arange(0, 8000, 1) cltt = theory.lCl('TT', ells) ps = cltt[None, None] cmb = enmap.rand_map(shape, wcs, ps, seed=(0, seed)) modlmap = cmb.modlmap() #io.plot_img(cmb,os.environ['WORK'] + '/tiling/cmbmap.png',lim=300) # Make the SZ cluster realization Nclusters = 800 amp_150_mean = 40 amp_150_sigma = 20 amps_150 = -np.abs( np.random.normal(amp_150_mean, amp_150_sigma, size=Nclusters)) def get_amps(freq): return amps_150 * szfg.ffunc(freq) / szfg.ffunc(150.)
feed_dict['tC_A_T_P_T'] = lcltt2d # Displace the unlensed map with deflection angle def lens_map(imap): lens_order = 5 return plensing.displace_map(imap, alpha, order=lens_order) s = stats.Stats(comm) for task in my_tasks: print(rank, task) # Make a CMB sim cmb = enmap.rand_map((1, ) + shape, wcs, cltt2d[None, None], seed=(0, task)) cmb = lens_map(cmb[0])[None] # do the lensing """ EXERCISE: do everything up to here at a higher resolution with geometry ushape,uwcs, which is defined for the same patch width but at resolution say 0.1 arcmin pixel width instead of 0.5 arcmin. px = 0.1 width = 120./60. oshape,owcs = maps.rect_geometry(width_deg=width,px_res_arcmin=px,proj='plain') Then downgrade to the original resolution defined on oshape,owcs (with 0.5 arcmin pixel width) using px = 0.5 width = 120./60.