Beispiel #1
0
    def rotate(self, imap, **kwargs):
        rotated = MapRotator.rotate(self, imap, **kwargs)

        if self.downsample:
            from enlib import resample
            return enmap.ndmap(
                resample.resample_fft(rotated, self.shape_final),
                self.wcs_final)
        else:
            return rotated
Beispiel #2
0
def sim(cseed, kseed, skip_kappa_verif=False):

    if not (vonly):
        unlensed = parray_sim.get_unlensed_cmb(seed=seedroot + cseed,
                                               scalar=False)
        kappa = aio.kappa_from_config(Config,
                                      kappa_section,
                                      parray_sim,
                                      seed=seedroot + kseed)
        lensed = parray_sim.get_lensed(unlensed,
                                       order=lens_order,
                                       mode="spline",
                                       border="cyclic")

        luteb, dummy = sverif_cmb.add_power("unlensed", unlensed)
        llteb, dummy = sverif_cmb.add_power("lensed", lensed)
        if not (skip_kappa_verif):
            lk, dummy = sverif_kappa.add_power("kappa", kappa)

    cname = fout_dir + "lensed_covseed_" + str(
        args.covseed).zfill(3) + "_cmbseed_" + str(cseed).zfill(
            5) + "_kseed_" + str(kseed).zfill(5) + ".hdf"
    kname = fout_dir + "kappa_covseed_" + str(
        args.covseed).zfill(3) + "_kseed_" + str(kseed).zfill(5) + ".hdf"

    if vonly:
        dlensed = enmap.read_map(cname)
        dkappa = enmap.read_map(kname)
    else:
        dlensed = lensed if abs(pixratio - 1.) < 1.e-3 else enmap.ndmap(
            resample.resample_fft(lensed, shape_dat), wcs_dat)
        dkappa = kappa if abs(pixratio - 1.) < 1.e-3 else enmap.ndmap(
            resample.resample_fft(kappa, shape_dat[-2:]), wcs_dat)
        dlensed.write(cname)
        dkappa.write(kname)

    dllteb, dummy = sverif_dcmb.add_power("dlensed", dlensed)
    if not (skip_kappa_verif):
        dlk, dummy = sverif_dkappa.add_power("dkappa", dkappa)
Beispiel #3
0
mass = 2.e14
fkappa = lens_func(fmodrmap)
phi, _ = lensing.kappa_to_phi(fkappa, fmodlmap, return_fphi=True)
grad_phi = enmap.grad(phi)
pos = enmap.posmap(fshape, fwcs) + grad_phi
alpha_pix = enmap.sky2pix(fshape, fwcs, pos, safe=False)

lmax = cmodlmap.max()
ells = np.arange(0, lmax, 1)
cls = theory.uCl('TT', ells)
ps = cls.reshape((1, 1, ells.size))
mg = maps.MapGen(cshape, cwcs, ps)
unlensed = mg.get_map()

hunlensed = enmap.enmap(resample.resample_fft(unlensed.copy(), fshape), fwcs)
hlensed = enlensing.displace_map(hunlensed,
                                 alpha_pix,
                                 order=lens_order,
                                 mode=mode)
lensed = enmap.enmap(resample.resample_fft(hlensed, cshape), cwcs)

rkappa = lens_func(rmodrmap)
phi, _ = lensing.kappa_to_phi(rkappa, rmodlmap, return_fphi=True)
grad_phi = enmap.grad(phi)
pos = enmap.posmap(rshape, rwcs) + grad_phi
ralpha_pix = enmap.sky2pix(rshape, rwcs, pos, safe=False)

hunlensed = enmap.enmap(resample.resample_fft(unlensed.copy(), rshape), rwcs)
enmap.write_map("unlensed_0.001arc.fits", hunlensed)
Beispiel #4
0
    # === ADD NOISE BEFORE DOWNSAMPLE
    # if rank==0: print "Beam convolving..."
    # olensed = enmap.ndmap(lensed.copy() if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed.copy(),shape_dat),wcs_dat)
    # flensed = fftfast.fft(lensed,axes=[-2,-1])
    # flensed *= parray_sim.lbeam
    # lensed = fftfast.ifft(flensed,axes=[-2,-1],normalize=True).real
    # if rank==0: print "Adding noise..."
    # noise = parray_sim.get_noise_sim(seed=index+20000)
    # lensed += noise
    # if rank==0: print "Downsampling..."
    # cmb = lensed if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed,shape_dat)

    # === ADD NOISE AFTER DOWNSAMPLE
    if rank == 0: print "Beam convolving..."
    olensed = enmap.ndmap(
        lensed.copy() if abs(pixratio - 1.) < 1.e-3 else resample.resample_fft(
            lensed.copy(), shape_dat), wcs_dat)
    flensed = fftfast.fft(olensed, axes=[-2, -1])
    flensed *= parray_dat.lbeam
    lensed = fftfast.ifft(flensed, axes=[-2, -1], normalize=True).real
    if rank == 0: print "Adding noise..."
    noise = parray_dat.get_noise_sim(seed=index + 20000)

    lcents, noise1d = lbinner_dat.bin(fmaps.get_simple_power_enmap(noise))
    mpibox.add_to_stats('noisett', noise1d)

    lensed += noise
    if rank == 0: print "Downsampling..."
    cmb = lensed

    cmb = enmap.ndmap(cmb, wcs_dat)
    if rank == 0: print "Calculating powers for diagnostics..."
posmap = enmap.posmap(gshape, gwcs)
pos = posmap + grad_phi
alpha_pix = enmap.sky2pix(gshape, gwcs, pos, safe=False)
kbeam = maps.gauss_beam(args.beam, gmodlmap)

mstats = stats.Stats()

for i in range(args.Nclusters):

    if (i + 1) % 100 == 0: print(i + 1)
    unlensed = mg.get_map()
    noise_map = ng.get_map()
    lensed = maps.filter_map(
        enlensing.displace_map(unlensed.copy(), alpha_pix, order=lens_order),
        kbeam)
    fdownsampled = enmap.enmap(resample.resample_fft(lensed, bshape), bwcs)
    stamp = fdownsampled + noise_map

    #cutout = lensed  + noise_map
    cutout = stamp[int(bshape[0] / 2. - shape[0] / 2.):int(bshape[0] / 2. +
                                                           shape[0] / 2.),
                   int(bshape[0] / 2. - shape[0] / 2.):int(bshape[0] / 2. +
                                                           shape[0] / 2.)]

    # print(cinvs[k].shape,cutout.shape)

    totlnlikes = []
    for k, kamp in enumerate(kamps):
        lnlike = maps.get_lnlike(cinvs[k], cutout) + logdets[k]
        totlnlike = lnlike  #+ lnprior[k]
        totlnlikes.append(totlnlike)
Beispiel #6
0
                    beam2d=okbeam,
                    kmask=tmask,
                    kmask_K=kmask,
                    pol=False,
                    grad_cut=2000,
                    unlensed_equals_lensed=False)

for i, task in enumerate(my_tasks):
    if (i + 1) % 10 == 0 and rank == 0: print(i + 1)

    # Sim
    unlensed = mg.get_map()
    noise_map = ng.get_map()
    lensed = maps.filter_map(
        enlensing.displace_map(unlensed, alpha_pix, order=lens_order), kbeam)
    fdownsampled = enmap.enmap(resample.resample_fft(lensed, oshape), owcs)
    stamp = fdownsampled + noise_map

    # Bayesian
    cutout = stamp[int(oshape[0] / 2. - bshape[0] / 2.):int(oshape[0] / 2. +
                                                            bshape[0] / 2.),
                   int(oshape[0] / 2. - bshape[0] / 2.):int(oshape[0] / 2. +
                                                            bshape[0] / 2.)]

    totlnlikes = []
    for k, kamp in enumerate(bkamps):
        lnlike = maps.get_lnlike(cinvs[k], cutout) + logdets[k]
        totlnlike = lnlike  #+ lnprior[k]
        totlnlikes.append(totlnlike)
    nlnlikes = -0.5 * np.array(totlnlikes)
    mstats.add_to_stats("totlikes", nlnlikes)
Beispiel #7
0
 unlensed = parray_sim.get_unlensed_cmb(seed=index)
 if random and simulated_kappa:
     lensed = unlensed
 else:
     if rank == 0: print("Lensing...")
     #lensed = lensing.lens_map_flat_pix(unlensed.copy(), alpha_pix.copy(),order=lens_order)
     lensed = lensing.lens_map(unlensed.copy(),
                               grad_phi,
                               order=lens_order,
                               mode="spline",
                               border="cyclic",
                               trans=False,
                               deriv=False,
                               h=1e-7)
 if rank == 0: print("Downsampling...")
 cmb = lensed if abs(pixratio - 1.) < 1.e-3 else resample.resample_fft(
     lensed, shape_dat)
 cmb = enmap.ndmap(cmb, wcs_dat)
 if not (cluster):
     if rank == 0: print("Calculating powers for diagnostics...")
     #pxwindow =  fmaps.pixel_window_function(modlmap_dat,angmap_dat,px_dat,px_dat)
     hutt2d = fmaps.get_simple_power_enmap(unlensed * taper) / w2
     hltt2d = fmaps.get_simple_power_enmap(lensed * taper) / w2
     utt2d = fmaps.get_simple_power_enmap(
         enmap.ndmap(
             unlensed * taper if abs(pixratio - 1.) < 1.e-3 else
             resample.resample_fft(unlensed * taper, shape_dat),
             wcs_dat)) / w2
     ltt2d = fmaps.get_simple_power_enmap(cmb * taper) / w2
     ccents, utt = lbinner_dat.bin(utt2d)
     ccents, ltt = lbinner_dat.bin(ltt2d)
     ccents, hutt = lbinner_sim.bin(hutt2d)
Beispiel #8
0
    if k==0:

        from alhazen.halos import nfw_kappa
        kappa = nfw_kappa(cluster_mass,parray_sim.modrmap,cc)
        #kappa = parray_sim.get_grf_kappa(seed=1)
        phi, fphi = lt.kappa_to_phi(kappa,parray_sim.modlmap,return_fphi=True)
        grad_phi = enmap.grad(phi)
            

    if rank==0: print(("Generating unlensed CMB for ", k, "..."))
    unlensed = parray_sim.get_unlensed_cmb(seed=index)
    if rank==0: print("Lensing...")
    lensed = unlensed if nolens else lensing.lens_map(unlensed.copy(), grad_phi, order=lens_order, mode="spline", border="cyclic", trans=False, deriv=False, h=1e-7)
    #lensed = lensing.lens_map_flat(unlensed.copy(), phi, order=lens_order)
    if rank==0: print("Downsampling...")
    cmb = lensed if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed,shape_dat)
    cmb = enmap.ndmap(cmb,wcs_dat)
    if rank==0: print("Adding noise...")
    flensed = fftfast.fft(cmb,axes=[-2,-1])
    flensed *= parray_dat.lbeam
    lensedt = fftfast.ifft(flensed,axes=[-2,-1],normalize=True).real
    noise = parray_dat.get_noise_sim(seed=index+10000000)
    lensedt += noise
    cmb = lensedt
        

    
    if rank==0: print("Filtering and binning input kappa...")
    dkappa = enmap.ndmap(fmaps.filter_map(kappa,kappa*0.+1.,parray_sim.modlmap,lowPass=kellmax,highPass=kellmin),wcs_sim)
    dkappa = dkappa if abs(pixratio-1.)<1.e-3 else enmap.ndmap(resample.resample_fft(dkappa,shape_dat),wcs_dat)
    cents,kappa1d = binner_dat.bin(dkappa)