Beispiel #1
0
def plot_powers(unlensed_map, lensed_map, modlmap, theory, lbinner_dat,
                out_dir):
    utt2d = fmaps.get_simple_power_enmap(unlensed_map)
    ltt2d = fmaps.get_simple_power_enmap(lensed_map)

    iutt2d = theory.uCl("TT", modlmap)
    iltt2d = theory.lCl("TT", modlmap)

    lb = lbinner_dat
    cents, utt = lb.bin(utt2d)
    cents, ltt = lb.bin(ltt2d)
    cents, iutt = lb.bin(iutt2d)
    cents, iltt = lb.bin(iltt2d)

    pl = oio.Plotter()
    pdiff = (utt - iutt) * 100. / iutt
    pl.add(cents, pdiff)
    pl.done(out_dir + "uclpdiff.png")

    pl = oio.Plotter()
    pdiff = (ltt - iltt) * 100. / iltt
    pl.add(cents, pdiff)
    pl.done(out_dir + "lclpdiff.png")
Beispiel #2
0
def debug():
    teb = enmap.ifft(enmap.map2harm(unlensed)).real
    lteb = enmap.ifft(klteb).real
    if pol:
        io.quickPlot2d(unlensed[0], out_dir + "tmap.png")
        io.quickPlot2d(unlensed[1], out_dir + "qmap.png")
        io.quickPlot2d(unlensed[2], out_dir + "umap.png")
        io.quickPlot2d(teb[1], out_dir + "emap.png")
        io.quickPlot2d(teb[2], out_dir + "bmap.png")
        io.quickPlot2d(lensed[0], out_dir + "ltmap.png")
        io.quickPlot2d(lensed[1], out_dir + "lqmap.png")
        io.quickPlot2d(lensed[2], out_dir + "lumap.png")
        io.quickPlot2d(lteb[1], out_dir + "lemap.png")
        io.quickPlot2d(lteb[2], out_dir + "lbmap.png")
    else:
        io.quickPlot2d(unlensed, out_dir + "tmap.png")
        io.quickPlot2d(lensed, out_dir + "ltmap.png")

    t = teb[0, :, :]
    e = teb[1, :, :]
    b = teb[2, :, :]
    nt = noise[0, :, :]
    ne = noise[1, :, :]
    nb = noise[2, :, :]
    ntt2d = np.nan_to_num(fmaps.get_simple_power_enmap(nt) / kbeam_sim**2.)
    nee2d = np.nan_to_num(fmaps.get_simple_power_enmap(ne) / kbeam_sim**2.)
    nbb2d = np.nan_to_num(fmaps.get_simple_power_enmap(nb) / kbeam_sim**2.)

    utt2d = fmaps.get_simple_power_enmap(t)
    uee2d = fmaps.get_simple_power_enmap(e)
    ute2d = fmaps.get_simple_power_enmap(enmap1=t, enmap2=e)
    ubb2d = fmaps.get_simple_power_enmap(b)
    debug_edges = np.arange(2, 12000, 80)
    dbinner = stats.bin2D(modlmap_sim, debug_edges)
    cents, utt = dbinner.bin(utt2d)
    cents, uee = dbinner.bin(uee2d)
    cents, ute = dbinner.bin(ute2d)
    cents, ntt = dbinner.bin(ntt2d)
    cents, nee = dbinner.bin(nee2d)
    cents, nbb = dbinner.bin(nbb2d)
    #cents, ubb = dbinner.bin(ubb2d)

    tl = lteb[0, :, :]
    el = lteb[1, :, :]
    bl = lteb[2, :, :]
    ltt2d = fmaps.get_simple_power_enmap(tl)
    lee2d = fmaps.get_simple_power_enmap(el)
    lte2d = fmaps.get_simple_power_enmap(enmap1=tl, enmap2=el)
    lbb2d = fmaps.get_simple_power_enmap(bl)
    cents, ltt = dbinner.bin(ltt2d)
    cents, lee = dbinner.bin(lee2d)
    cents, lte = dbinner.bin(lte2d)
    cents, lbb = dbinner.bin(lbb2d)

    lcltt, lclee, lclte, lclbb = (
        x for x in cmb.unpack_cmb_theory(theory, fine_ells, lensed=True))
    cltt, clee, clte, clbb = (
        x for x in cmb.unpack_cmb_theory(theory, fine_ells, lensed=False))

    pl = io.Plotter(scaleY='log', scaleX='log')
    pl.add(cents, utt * cents**2., color="C0", marker="o", ls="none")
    pl.add(cents, uee * cents**2., color="C1", marker="o", ls="none")
    #pl.add(cents,ubb*cents**2.,color="C2",ls="-")
    pl.add(fine_ells, cltt * fine_ells**2., color="C0", ls="--")
    pl.add(fine_ells, clee * fine_ells**2., color="C1", ls="--")
    #pl.add(fine_ells,clbb*fine_ells**2.,color="C2",ls="--")
    pl.done(out_dir + "ccomp.png")

    pl = io.Plotter(scaleX='log')
    pl.add(cents, ute * cents**2., color="C0", marker="o", ls="none")
    pl.add(fine_ells, clte * fine_ells**2., color="C0", ls="--")
    pl.done(out_dir + "ccompte.png")

    # sells,stt,see,sbb,ste = np.loadtxt("data/cl_lensed.dat",unpack=True)
    # stt *= 2.*np.pi/TCMB**2./sells/(sells+1.)
    # see *= 2.*np.pi/TCMB**2./sells/(sells+1.)
    # sbb *= 2.*np.pi/TCMB**2./sells/(sells+1.)

    pl = io.Plotter(scaleY='log')  #,scaleX='log')

    # pl.add(sells,stt*sells**2.,color="C0",ls="-")
    # pl.add(sells,see*sells**2.,color="C1",ls="-")
    # pl.add(sells,sbb*sells**2.,color="C2",ls="-")

    pl.add(cents, ltt * cents**2., color="C0", marker="o", ls="none")
    pl.add(cents, lee * cents**2., color="C1", marker="o", ls="none")
    pl.add(cents, lbb * cents**2., color="C2", marker="o", ls="none")
    pl.add(cents, ntt * cents**2., color="C0", ls="-.", alpha=0.4)
    pl.add(cents, nee * cents**2., color="C1", ls="-.", alpha=0.4)
    pl.add(cents, nbb * cents**2., color="C2", ls="-.", alpha=0.4)
    pl.add(fine_ells, lcltt * fine_ells**2., color="C0", ls="--")
    pl.add(fine_ells, lclee * fine_ells**2., color="C1", ls="--")
    pl.add(fine_ells, lclbb * fine_ells**2., color="C2", ls="--")
    pl.done(out_dir + "lccomp.png")

    pl = io.Plotter(scaleX='log')
    pl.add(cents, lte * cents**2., color="C0", ls="-")
    pl.add(fine_ells, lclte * fine_ells**2., color="C0", ls="--")
    pl.done(out_dir + "lccompte.png")
Beispiel #3
0
                               massOverh,
                               concentration,
                               zL,
                               modr_sim,
                               winAtLens,
                               overdensity=overdensity,
                               critical=critical,
                               atClusterZ=atClusterZ)
else:
    grad_cut = None

    clkk = theory.gCl("kk", fine_ells)
    clkk.resize((1, 1, clkk.size))
    kappa_map = enmap.rand_map(shape_sim[-2:], wcs_sim, cov=clkk, scalar=True)

    pkk = fmaps.get_simple_power_enmap(kappa_map)
    debug_edges = np.arange(2, 12000, 80)
    dbinner = stats.bin2D(modlmap_sim, debug_edges)
    cents, bclkk = dbinner.bin(pkk)
    clkk.resize((clkk.shape[-1]))
    pl = io.Plotter(scaleY='log', scaleX='log')
    pl.add(fine_ells, clkk)
    pl.add(cents, bclkk)
    pl.done(out_dir + "clkk.png")
phi, fphi = lt.kappa_to_phi(kappa_map, modlmap_sim, return_fphi=True)
io.quickPlot2d(kappa_map, out_dir + "kappa_map.png")
io.quickPlot2d(phi, out_dir + "phi.png")
alpha_pix = enmap.grad_pixf(fphi)

# === SIM AND RECON LOOP ===
Beispiel #4
0
w3 = np.mean(taper**3.)
w4 = np.mean(taper**4.)
if rank == 0:
    io.quickPlot2d(taper, out_dir + "taper.png")
    print(("w2 : ", w2))

px_dat = analysis_resolution

k = -1
for index in my_tasks:

    k += 1
    if rank == 0: print(("Rank ", rank, " doing cutout ", index))
    kappa = enmap.read_map(sigurd_kappa_file(index)) * taper
    cmb = enmap.read_map(sigurd_cmb_file(index))[0]  #/2.7255e6
    ltt2d = fmaps.get_simple_power_enmap(cmb * taper)

    ccents, ltt = lbinner_dat.bin(ltt2d) / w2
    mpibox.add_to_stats("lcl", ltt)

    if rank == 0: print("Reconstructing...")
    measured = cmb * taper
    fkmaps = fftfast.fft(measured, axes=[-2, -1])
    qest.updateTEB_X(fkmaps, alreadyFTed=True)
    qest.updateTEB_Y()
    with io.nostdout():
        rawkappa = qest.getKappa("TT").real

    kappa_recon = enmap.ndmap(rawkappa, wcs_dat) - mf
    if save_meanfield: mpibox.add_to_stack("meanfield", kappa_recon)
    #if save is not None: enmap.write_fits(save_func(index),kappa_recon)
Beispiel #5
0
                               zL,
                               modr_sim,
                               winAtLens,
                               overdensity=overdensity,
                               critical=critical,
                               atClusterZ=atClusterZ)
    #cents, nkprofile = binner.bin(kappa_map)

    model_mass = 2.e14
    model_uniform_kappa = 0.02  #02
else:
    clkk = theory.gCl("kk", fine_ells)
    clkk.resize((1, 1, clkk.size))
    kappa_map = enmap.rand_map(shape_sim[-2:], wcs_sim, cov=clkk, scalar=True)
    if debug:
        pkk = fmaps.get_simple_power_enmap(kappa_map)
        debug_edges = np.arange(kellmin, 8000, 80)
        dbinner = stats.bin2D(modlmap_sim, debug_edges)
        cents, bclkk = dbinner.bin(pkk)
        clkk.resize((clkk.shape[-1]))
        pl = io.Plotter(scaleY='log', scaleX='log')
        pl.add(fine_ells, clkk)
        pl.add(cents, bclkk)
        pl.done(out_dir + "clkk.png")
phi, fphi = lt.kappa_to_phi(kappa_map, modlmap_sim, return_fphi=True)
io.quickPlot2d(kappa_map, out_dir + "kappa_map.png")
io.quickPlot2d(phi, out_dir + "phi.png")
alpha_pix = enmap.grad_pixf(fphi)

# === EXPERIMENT ===
Beispiel #6
0
    imap = imap * taper
    phi = phi * taper
    if i == 0:
        io.quickPlot2d(phi, os.environ['WORK'] + "/web/plots/phimap.png")

    print("IQU to TEB...")
    teb = enmap.ifft(enmap.map2harm(imap)).real

    print("Powers...")

    t = teb[0, :, :]
    e = teb[1, :, :]
    b = teb[2, :, :]
    spec2d = {}
    spec2d['tt'] = np.nan_to_num(fmaps.get_simple_power_enmap(t)) / w2
    spec2d['ee'] = np.nan_to_num(fmaps.get_simple_power_enmap(e)) / w2
    spec2d['bb'] = np.nan_to_num(fmaps.get_simple_power_enmap(b)) / w2
    spec2d['te'] = np.nan_to_num(fmaps.get_simple_power_enmap(t,
                                                              enmap2=e)) / w2
    spec2d['pp'] = np.nan_to_num(
        fmaps.get_simple_power_enmap(phi)) / w2 * (modlmap *
                                                   (modlmap + 1.))**2. / 4.

    print("Binning...")

    for spec in ['tt', 'ee', 'te', 'bb', 'pp']:
        cents, clww = binner.bin(spec2d[spec])
        container[spec].append(clww)

    plot_stats(cents, container, ells, ells_pp, theory)
Beispiel #7
0
                           padX=int(pad_percent * min(Ny, Nx) / 100.))
w2 = np.mean(taper**2.)
w3 = np.mean(taper**3.)
w4 = np.mean(taper**4.)
if rank == 0:
    io.quickPlot2d(taper, out_dir + "taper.png")
    print(("w2 : ", w2))

px_dat = analysis_resolution

Nsims = 10
avg = 0.
for i in range(Nsims):
    print(i)
    cmb = parray_dat.get_unlensed_cmb(seed=i)
    ltt2d = fmaps.get_simple_power_enmap(cmb * taper)
    ccents, ltt = lbinner_dat.bin(ltt2d) / w2
    avg += ltt

ltt = avg / Nsims
iltt2d = theory.uCl("TT", parray_dat.modlmap)
ccents, iltt = lbinner_dat.bin(iltt2d)

pl = io.Plotter()

pdiff = (ltt - iltt) / iltt

pl.add(ccents + 50, pdiff, marker="o", ls="-")
pl.legendOn(labsize=10, loc="lower left")
pl._ax.axhline(y=0., ls="--", color="k")
pl._ax.set_ylim(-0.1, 0.1)
Beispiel #8
0
    # 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..."
    utt2d = fmaps.get_simple_power_enmap(
        enmap.ndmap(
            unlensed if abs(pixratio - 1.) < 1.e-3 else resample.resample_fft(
                unlensed, shape_dat), wcs_dat))
    ltt2d = fmaps.get_simple_power_enmap(olensed)
    ccents, utt = lbinner_dat.bin(utt2d)
    ccents, ltt = lbinner_dat.bin(ltt2d)
Beispiel #9
0
del fMask
del fMaskCMB_T
del fMaskCMB_P
del nT
del nP

k = -1
for index in my_tasks:

    k += 1
    if rank == 0: print(("Rank ", rank, " doing cutout ", index))
    kappa = enmap.read_map(alex_kappa_file(index))

    ucmb = enmap.ndmap(
        enmap.read_map(alex_ucmb_file(index)) / 2.7255e6, wcs_dat)
    utt2d = fmaps.get_simple_power_enmap(ucmb)
    ccents, utt = lbinner_dat.bin(utt2d)
    mpibox.add_to_stats("ucl", utt)
    del ucmb
    del utt2d

    cmb = enmap.ndmap(enmap.read_map(alex_cmb_file(index)) / 2.7255e6, wcs_dat)
    ltt2d = fmaps.get_simple_power_enmap(cmb)
    ccents, ltt = lbinner_dat.bin(ltt2d)
    mpibox.add_to_stats("lcl", ltt)
    del ltt2d

    if rank == 0: print("Reconstructing...")
    measured = cmb
    fkmaps = fftfast.fft(measured, axes=[-2, -1])
    qest.updateTEB_X(fkmaps, alreadyFTed=True)
Beispiel #10
0
                    cov,
                    scalar=True,
                    seed=None,
                    power2d=False,
                    pixel_units=False)
modlmap = m1.modlmap()

io.quickPlot2d(m1[0], out_dir + "m1.png")
cltt = ps[0, 0]
ells = np.arange(0, cltt.size)
pl = io.Plotter(scaleY='log')
pl.add(ells, cltt * ells**2.)

debug_edges = np.arange(200, 2000, 80)
dbinner = stats.bin2D(modlmap, debug_edges)
powermap = fmaps.get_simple_power_enmap(m1[0])
cents, dcltt = dbinner.bin(powermap)

pl.add(cents, dcltt * cents**2., label="power of map")

pa = fmaps.PatchArray(shape, wcs, skip_real=True)
pa.add_noise_2d(powermap)
nT = pa.nT
cents, dcltt = dbinner.bin(nT)
pl.add(cents, dcltt * cents**2., label="binned 2d power from pa")

cov = np.zeros((3, 3, modlmap.shape[0], modlmap.shape[1]))
cov[0, 0] = nT
cov[1, 1] = nT
cov[2, 2] = nT
m2 = enmap.rand_map(shape,
Beispiel #11
0
                                       atClusterZ=atClusterZ)

            else:
                kappa = parray_sim.get_kappa(ktype="grf", vary=False)

    if simulated_cmb:
        phi, fphi = lt.kappa_to_phi(kappa,
                                    parray_sim.modlmap,
                                    return_fphi=True)
        #alpha_pix = enmap.grad_pixf(fphi)
        grad_phi = enmap.grad(phi)

    if not (simulated_cmb):
        if sigurd:
            cmb = enmap.read_map(sigurd_cmb_file(index))[0] / 2.7255e6
            ltt2d = fmaps.get_simple_power_enmap(cmb * taper)
            ccents, ltt = lbinner_dat.bin(ltt2d) / w2
            mpibox.add_to_stats("lcl", ltt)
        else:
            cmb = np.load(cmb_file) / 1.072480e+09
    else:
        if rank == 0: print("Generating unlensed CMB...")
        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,
Beispiel #12
0
    if rank==0: print("Reconstructing...")
    measured = enmap.ndmap(cmb,wcs_dat)
    fkmaps = fftfast.fft(measured,axes=[-2,-1])
    qest.updateTEB_X(fkmaps,alreadyFTed=True)
    qest.updateTEB_Y()
    rawkappa = qest.getKappa("TT").real
    if args.fake: rawkappa += dkappa

    kappa_recon = enmap.ndmap(np.nan_to_num(rawkappa),wcs_dat)
    kappa_recon = enmap.ndmap(fmaps.filter_map(kappa_recon,kappa_recon*0.+1.,parray_dat.modlmap,lowPass=kellmax,highPass=kellmin),wcs_dat)
    mpibox.add_to_stack("recon_kappa2d",kappa_recon)
    cents,kapparecon1d = binner_dat.bin(kappa_recon)
    mpibox.add_to_stats("recon_kappa1d",kapparecon1d)
        
    cpower = fmaps.get_simple_power_enmap(enmap1=kappa_recon,enmap2=dkappa)
    ipower = fmaps.get_simple_power_enmap(enmap1=dkappa)
    lcents, cclkk = lbinner_dat.bin(cpower)
    lcents, iclkk = lbinner_dat.bin(ipower)
    mpibox.add_to_stats("crossp",cclkk)
    mpibox.add_to_stats("inputp",iclkk)

    # measured = X
    # guess = x0
    # updated = X-x0
    # remeasured = f(X-x0)

    Niters = 10
    delensed = measured
    kappa_model = kappa_recon
    pld = io.Plotter(scaleY='log')
Beispiel #13
0
        qest.updateTEB_X(fkmaps[0],fkmaps[1],fkmaps[2],alreadyFTed=True)
    else:
        qest.updateTEB_X(fkmaps,alreadyFTed=True)

    qest.updateTEB_Y()


    
    
    for polcomb in pol_list:
        print(("Reconstructing",polcomb ," for ", i , " ..."))
        kappa_recon = enmap.samewcs(qest.getKappa(polcomb).real,measured)
        # if i==0: io.quickPlot2d(kappa_recon,out_dir+"kappa_recon_single.png")
        kappa_recon -= kappa_recon.mean()

        kpower = fmaps.get_simple_power_enmap(kappa_recon)/w4
        cents_pwr, aclkk = dbinner_dat.bin(kpower)
        apowers[polcomb].append(aclkk)

        m = measured[0] if pol else measured
        data_power_2d_TT = fmaps.get_simple_power_enmap(m)
        sd = qest.N.super_dumb_N0_TTTT(data_power_2d_TT)/w2**2.
        cents_pwr, sdp = dbinner_dat.bin(sd)
        super_dumbs.append(sdp)

        
        
        n0sub = kpower - sd
        cents_pwr, n0subbed = dbinner_dat.bin(n0sub)
        n0subs.append(n0subbed)
Beispiel #14
0
    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)
    cmb = enmap.ndmap(cmb, wcs_dat)
    if rank == 0: print("Calculating powers for diagnostics...")
    utt2d = fmaps.get_simple_power_enmap(
        enmap.ndmap(
            unlensed if abs(pixratio - 1.) < 1.e-3 else resample.resample_fft(
                unlensed, shape_dat), wcs_dat))
    ltt2d = fmaps.get_simple_power_enmap(cmb)
    ccents, utt = lbinner_dat.bin(utt2d)
    ccents, ltt = lbinner_dat.bin(ltt2d)
    mpibox.add_to_stats("ucl", utt)
    mpibox.add_to_stats("lcl", ltt)

    if rank == 0: print("Reconstructing...")
    measured = cmb
    fkmaps = fftfast.fft(measured, axes=[-2, -1])
    qest.updateTEB_X(fkmaps, alreadyFTed=True)
    qest.updateTEB_Y()
    with io.nostdout():
        rawkappa = qest.getKappa("TT").real