def cutout_rec(shape, wcs, feed_dict, cmask, kmask, map1_k, map2_k): """ cutout lensing reconstruction """ feed_dict['X'] = map1_k feed_dict['Y'] = map2_k # unnormalized lensing map in fourier space ukappa_k = s.unnormalized_quadratic_estimator(shape, wcs, feed_dict, "hu_ok", "TT", xmask=cmask, ymask=cmask) # normaliztion norm_k = s.A_l(shape, wcs, feed_dict, "hu_ok", "TT", xmask=cmask, ymask=cmask, kmask=kmask) # noise noise_2d = s.N_l_from_A_l_optimal(shape, wcs, norm_k) # normalized Fourier space CMB lensing convergence map kappa_k = norm_k * ukappa_k # real space CMB lensing convergence map kappa = enmap.ifft(kappa_k, normalize='phys') return kappa, noise_2d
def get_nlkk_single(estimator, modlmap, tnoise, enoise, bnoise, tmask, pmask, pols=['TT', 'TE', 'EE', 'EB', 'TB']): import symlens as s feed_dict = get_feed(lcltt, lclte, lclee, lclbb, tnoise, enoise, bnoise) alpha_estimator = estimator beta_estimator = estimator npols = len(pols) masks = {'T': tmask, 'E': pmask, 'B': pmask} bin_edges = np.arange(40, 2500, 40) binner = stats.bin2D(modlmap, bin_edges) cents = binner.centers nls = np.zeros((npols, npols, cents.size)) Als = [] for i in range(npols): a, b = pols[i] Als.append( s.A_l(shape, wcs, feed_dict, alpha_estimator, pols[i], xmask=masks[a], ymask=masks[b])) for i in range(npols): for j in range(i, npols): print(pols[i], 'x', pols[j]) alpha_XY = pols[i] beta_XY = pols[j] a, b = alpha_XY c, d = beta_XY if i == j: xmask = masks[a] ymask = masks[b] else: xmask = masks['T'] ymask = masks['T'] nl = s.N_l_cross(shape, wcs, feed_dict, alpha_estimator, alpha_XY, beta_estimator, beta_XY, xmask=xmask, ymask=ymask, Aalpha=Als[i], Abeta=Als[j], field_names_alpha=None, field_names_beta=None) cents, nl1d = binner.bin(nl) nls[i, j] = nl1d.copy() if i != j: nls[j, i] = nl1d.copy() ncoadd = get_mv(nls) return cents, nls, ncoadd
def test_shear(): from orphics import lensing, io, cosmology, maps deg = 20. px = 2.0 tellmin = 30 tellmax = 3500 kellmin = 10 kellmax = 3000 bin_width = 20 beam_arcmin = 1.4 noise_uk_arcmin = 7.0 theory = cosmology.default_theory(lpad=30000) shape, wcs = s.rect_geometry(width_deg=deg, px_res_arcmin=px) flsims = lensing.FlatLensingSims(shape, wcs, theory, beam_arcmin, noise_uk_arcmin) kbeam = flsims.kbeam modlmap = enmap.modlmap(shape, wcs) fc = maps.FourierCalc(shape, wcs) n2d = (noise_uk_arcmin * np.pi / 180. / 60.)**2. / flsims.kbeam**2. tmask = s.mask_kspace(shape, wcs, lmin=tellmin, lmax=tellmax) kmask = s.mask_kspace(shape, wcs, lmin=kellmin, lmax=kellmax) bin_edges = np.arange(kellmin, kellmax, bin_width) binner = s.bin2D(modlmap, bin_edges) i = 0 unlensed, kappa, lensed, beamed, noise_map, observed = flsims.get_sim( seed_cmb=(i, 1), seed_kappa=(i, 2), seed_noise=(i, 3), lens_order=5, return_intermediate=True) _, kmap, _ = fc.power2d(observed) pii2d, kinput, _ = fc.power2d(kappa) feed_dict = {} cltt = theory.lCl('TT', modlmap) feed_dict['uC_T_T'] = theory.lCl('TT', modlmap) feed_dict['tC_T_T'] = (cltt + n2d) feed_dict['X'] = kmap / kbeam feed_dict['Y'] = kmap / kbeam ells = np.arange(0, 10000, 1) ucltt = theory.lCl('TT', ells) feed_dict['duC_T_T'] = s.interp(ells, np.gradient(np.log(ucltt), np.log(ells)))(modlmap) sAl = s.A_l(shape, wcs, feed_dict, "shear", "TT", xmask=tmask, ymask=tmask) sNl = s.N_l(shape, wcs, feed_dict, "shear", "TT", xmask=tmask, ymask=tmask, Al=sAl) sukappa = s.unnormalized_quadratic_estimator(shape, wcs, feed_dict, "shear", "TT", xmask=tmask, ymask=tmask) snkappa = sAl * sukappa pir2d3 = fc.f2power(snkappa, kinput) cents, pir1d3 = binner.bin(pir2d3) cents, pii1d = binner.bin(pii2d) cents, prr1d = binner.bin(fc.f2power(snkappa, snkappa)) cents, Nlkk3 = binner.bin(sNl) pl = io.Plotter(xyscale='loglog') pl.add(ells, theory.gCl('kk', ells)) pl.add(cents, pii1d, color='k', lw=3) pl.add(cents, pir1d3, label='shear') pl.add(cents, prr1d) pl.add(cents, Nlkk3, ls=":") pl._ax.set_xlim(10, 3500) pl.done("ncomp.png")
def test_lens_recon(): from orphics import lensing, io, cosmology, maps from enlib import bench deg = 10. px = 2.0 tellmin = 100 tellmax = 3000 kellmin = 40 kellmax = 3000 grad_cut = None bin_width = 80 beam_arcmin = 0.01 noise_uk_arcmin = 0.01 theory = cosmology.default_theory(lpad=30000) shape, wcs = s.rect_geometry(width_deg=deg, px_res_arcmin=px) flsims = lensing.FlatLensingSims(shape, wcs, theory, beam_arcmin, noise_uk_arcmin) kbeam = flsims.kbeam modlmap = enmap.modlmap(shape, wcs) fc = maps.FourierCalc(shape, wcs) n2d = (noise_uk_arcmin * np.pi / 180. / 60.)**2. / flsims.kbeam**2. tmask = s.mask_kspace(shape, wcs, lmin=tellmin, lmax=tellmax) kmask = s.mask_kspace(shape, wcs, lmin=kellmin, lmax=kellmax) with bench.show("orphics init"): qest = lensing.qest(shape, wcs, theory, noise2d=n2d, kmask=tmask, kmask_K=kmask, pol=False, grad_cut=grad_cut, unlensed_equals_lensed=True, bigell=30000) bin_edges = np.arange(kellmin, kellmax, bin_width) binner = s.bin2D(modlmap, bin_edges) i = 0 unlensed, kappa, lensed, beamed, noise_map, observed = flsims.get_sim( seed_cmb=(i, 1), seed_kappa=(i, 2), seed_noise=(i, 3), lens_order=5, return_intermediate=True) kmap = enmap.fft(observed, normalize="phys") # _,kmap,_ = fc.power2d(observed) with bench.show("orphics"): kkappa = qest.kappa_from_map("TT", kmap / kbeam, alreadyFTed=True, returnFt=True) pir2d, kinput = fc.f1power(kappa, kkappa) pii2d = fc.f2power(kinput, kinput) prr2d = fc.f2power(kkappa, kkappa) cents, pir1d = binner.bin(pir2d) cents, pii1d = binner.bin(pii2d) cents, prr1d = binner.bin(prr2d) feed_dict = {} cltt = theory.lCl('TT', modlmap) feed_dict['uC_T_T'] = theory.lCl('TT', modlmap) feed_dict['tC_T_T'] = cltt + n2d feed_dict['X'] = kmap / kbeam feed_dict['Y'] = kmap / kbeam with bench.show("symlens init"): Al = s.A_l(shape, wcs, feed_dict, "hdv", "TT", xmask=tmask, ymask=tmask) Nl = s.N_l_from_A_l_optimal(shape, wcs, Al) with bench.show("symlens"): ukappa = s.unnormalized_quadratic_estimator(shape, wcs, feed_dict, "hdv", "TT", xmask=tmask, ymask=tmask) nkappa = Al * ukappa pir2d2 = fc.f2power(nkappa, kinput) cents, pir1d2 = binner.bin(pir2d2) cents, Nlkk = binner.bin(qest.N.Nlkk['TT']) cents, Nlkk2 = binner.bin(Nl) pl = io.Plotter(xyscale='linlog') pl.add(cents, pii1d, color='k', lw=3) pl.add(cents, pir1d, label='orphics') pl.add(cents, pir1d2, label='hdv symlens') pl.add(cents, Nlkk, ls="--", label='orphics') pl.add(cents, Nlkk2, ls="-.", label='symlens') pl.done("ncomp.png")