Exemple #1
0
    def plot(self,
             spec,
             keys,
             out_dir=None,
             scaleY='log',
             scaleX='log',
             scale_spectrum=True,
             xlim=None,
             ylim=None,
             skip_uzero=True,
             pl=None,
             skip_labels=True):

        if pl is None: pl = io.Plotter(scaleY=scaleY, scaleX=scaleX)
        if scale_spectrum:
            scalefac = self.cents**2.
        else:
            scalefac = 1.
        cmb_specs = ['TT', 'EE', 'BB', 'TE', 'ET', 'EB', 'BE', 'TB', 'BT']
        uspecs = ['BB', 'EB', 'BE', 'TB', 'BT']
        done_spec = []

        suffspec = ""
        if (spec in cmb_specs) and self.pol:
            suffspec = spec

        for key in keys:

            if ("unlensed" in key) and (spec in uspecs) and skip_uzero:
                continue

            st = self.mpibox.stats[key + suffspec]

            if ("unlensed" in key) or ("delensed" in key):
                spec_key = "u" + spec
            else:
                if (spec in cmb_specs):
                    spec_key = "l" + spec
                else:
                    spec_key = spec

            if spec_key not in done_spec:
                done_spec.append(spec_key)
                th2d = self.theory.gCl(spec_key, self.modlmap)
                cents, th1d = self.lbinner.bin(th2d)
                pl.add(cents, th1d * scalefac)

            pl.addErr(cents,
                      st['mean'] * scalefac,
                      yerr=st['errmean'] * scalefac,
                      marker="x",
                      ls="none",
                      label=key)

        if xlim is not None: pl._ax.set_xlim(xlim[0], xlim[1])
        if ylim is not None: pl._ax.set_ylim(ylim[0], ylim[1])
        if not (skip_labels): pl.legendOn(labsize=10)
        if pl is None: pl.done(out_dir)
Exemple #2
0
def plot_stats(cents, cont, ells, ells_pp, theory):
    if len(cont['tt']) < 3: return

    print("Calculating stats...")
    st = {}
    for spec in ['tt', 'ee', 'te', 'bb', 'pp']:
        st[spec] = stats.getStats(cont[spec])

    print("Plotting...")
    pl = io.Plotter(scaleY='log', scaleX='log')
    for spec in ['tt', 'ee', 'bb']:
        pl.add(ells, theory[spec] * ells**2., lw=2)
        pl.addErr(cents,
                  st[spec]['mean'] * cents**2.,
                  yerr=st[spec]['errmean'] * cents**2.,
                  ls="none",
                  marker="o")

    pl.done(os.environ['WORK'] + "/web/plots/clsauto.png")
    pl = io.Plotter(scaleX='log')
    for spec in ['te']:
        pl.add(ells, theory[spec] * ells**2., lw=2)
        pl.addErr(cents,
                  st[spec]['mean'] * cents**2.,
                  yerr=st[spec]['errmean'] * cents**2.,
                  ls="none",
                  marker="o")

    pl.done(os.environ['WORK'] + "/web/plots/clste.png")
    pl = io.Plotter(scaleY='log')
    for spec in ['pp']:
        pl.add(ells_pp, theory[spec], lw=2)
        pl.addErr(cents,
                  st[spec]['mean'],
                  yerr=st[spec]['errmean'],
                  ls="none",
                  marker="o")
    pl._ax.set_xlim(2, 3000)
    pl.done(os.environ['WORK'] + "/web/plots/clspp.png")
Exemple #3
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")
Exemple #4
0
def plot_powers(cmb,suffix,power=None,w2=1.):

    if power is None:
        power,lteb1,lteb2 = fc.power2d(cmb,pixel_units=False,skip_cross=True)
    power /= w2
    cents,dtt = lbinner.bin(power[0,0])
    cents,dee = lbinner.bin(power[1,1])
    cents,dbb = lbinner.bin(power[2,2])


    pl = io.Plotter(scaleY='log')
    ellrange = np.arange(200,6000,1)
    cltt = theory.lCl('TT',ellrange)
    clee = theory.lCl('EE',ellrange)
    clbb = theory.lCl('BB',ellrange)
    pl.add(ellrange,cltt*ellrange**2.,color="k")
    pl.add(ellrange,clee*ellrange**2.,color="k")
    pl.add(ellrange,clbb*ellrange**2.,color="k")
    pl.add(cents,dtt*cents**2.)
    pl.add(cents,dee*cents**2.)
    pl.add(cents,dbb*cents**2.)
    pl.done(out_dir+"powers_"+suffix+".png")
Exemple #5
0
        print((ix, iy))
        c += 1
        ixs.append(ix)
        iys.append(iy)

print(c)

#sys.exit()

holeArc = 10.
holeFrac = 1.

ra_range = [lmap.x1 - 360., lmap.x0]
dec_range = [lmap.y0, lmap.y1]

stack, cents, recons = fmaps.stack_on_map(lmap, 60., 0.5, ra_range, dec_range,
                                          ras, decs)

io.quickPlot2d(stack, out_dir + "stack.png")

pl = io.Plotter(labelX='Distance from Center (arcminutes)',
                labelY='Temperature Fluctuation ($\mu K$)',
                ftsize=10)
pl.add(cents, recons)
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(out_dir + "profiles.png")

mask = inp.maskLiteMap(lmap, iys, ixs, holeArc, holeFrac)

io.highResPlot2d(mask.data, out_dir + "mask.png")
Exemple #6
0
            with io.nostdout():
                Fisher, paramList = sfisher.cluster_fisher_from_config(
                    Config,
                    expName,
                    grid,
                    cal,
                    fish + fish_suff_pass,
                    tauOverride=tau,
                    do_clkk_override=do_clkk_ov)
            if fish == "mnu-paper": print(paramList)
            margerrs = sfisher.marginalized_errs(Fisher, paramList)
            print((margerrs['mnu'] * 1000.))
            performance[cal][fish_suff].append(margerrs['mnu'] * 1000.)
            #print margerrs['b_wl']*100.

    pl = io.Plotter(labelY='$\\sigma(\\Sigma m_{\\nu})$ (meV)', ftsize=18)
    for fish_suff, lab in zip(fishall, laball):
        pl._ax.bar(y_pos,
                   performance[cal][fish_suff],
                   align='center',
                   alpha=al,
                   label=lab)

    pl._ax.set_xticks(y_pos)  #y_pos, objects)
    pl._ax.set_xticklabels(objects)
    pl._ax.set_ylim(0, 62)
    min_mass = 58.
    pl._ax.axhline(y=min_mass, ls="-", color="k", alpha=0.3)
    pl._ax.axhline(y=old_div(min_mass, 3.), ls="--", color="k")
    pl._ax.axhline(y=old_div(min_mass, 5.), ls="-.", color="k")
    pl.legendOn(labsize=16)
Exemple #7
0
    if rank == 0:
        print(
            ("Rank ", rank, " doing job ", k + 1, " / ", len(my_tasks), "..."))
    sim(index, Nsims + index)
    sim(2 * Nsims + index, 3 * Nsims + index)
    sim(4 * Nsims + index, 5 * Nsims + index)
    sim(6 * Nsims + index, 5 * Nsims + index, skip_kappa_verif=True
        )  # skip kappa verification because kappa is repeated

mpibox.get_stats()
if rank == 0:

    plot_list = ["unlensed", "lensed", "dlensed"
                 ] if not (vonly) else ['dlensed']
    spec_list = ["TT", "EE", "BB"] if pol else ['TT']
    pl = io.Plotter(scaleY='log')
    for spec in spec_list:
        if not (vonly):
            sverif_cmb.plot(spec, plot_list, xlim=[kellmin, kellmax], pl=pl)
        sverif_dcmb.plot(spec, plot_list, xlim=[kellmin, kellmax], pl=pl)
    pl.done(pout_dir + "cl.png")

    if pol:
        plot_list = ["unlensed", "lensed", "dlensed"
                     ] if not (vonly) else ['dlensed']
        spec_list = ["TE"]
        pl = io.Plotter()
        for spec in spec_list:
            if not (vonly):
                sverif_cmb.plot(spec,
                                plot_list,
Exemple #8
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")
Exemple #9
0
    def dump(self,save_meanfield,skip_recon):
        mlist = ['s','e','r']

        def unpack(label,m):
            dic = self.mpibox.stats[label+"-"+m]
            return dic['mean'],dic['errmean']

        ellrange = np.arange(0,self.bin_edges[-1])
        cltheory = self.theory.lCl('TT',ellrange)

        # CLTT vs input powers
        pl = io.Plotter()

        pdiff = (self.mpibox.stats["fullsky_ps"]['mean'][:ellrange.size]-cltheory)/cltheory
        perr = self.mpibox.stats["fullsky_ps"]['errmean'][:ellrange.size]/cltheory
        pl.addErr(ellrange,pdiff,yerr=perr,label="sht fullsky",ls="-",alpha=0.3)

        for m in mlist:
            modlmap = self.modlmap[m]
            cltt = self.binner[m].bin(self.theory.lCl('TT',modlmap))[1]
            pcltt,pcltt_err = unpack("cmb",m)
            pdiff = (pcltt-cltt)/cltt
            perr = pcltt_err/cltt
            pl.addErr(self.cents,pdiff,yerr=perr,label=m,ls="-")
        pl.hline()
        pl.legendOn()
        pl._ax.set_ylim(-0.1,0.1)
        pl.done(io.dout_dir+"clttdiff.png")

        # CLKK vs input powers
        pl = io.Plotter()
        for m in mlist:
            modlmap = self.modlmap[m]
            clkk = self.binner[m].bin(self.theory.gCl('kk',modlmap))[1]
            pclkk,pclkk_err = unpack("ixi",m)
            pdiff = (pclkk-clkk)/clkk
            perr = pclkk_err/clkk
            pl.addErr(self.cents,pdiff,yerr=perr,label=m,ls="-")
        pl.hline()
        pl.legendOn()
        pl.done(io.dout_dir+"clkkdiff.png")

        if skip_recon: return
        
        if save_meanfield:
            for m in mlist:
                mf = self.mpibox.stacks["meanfield-"+m]
                enmap.write_map("meanfield_"+m+".hdf",mf)
            
        


            




        # RECONSTRUCTION VS CLKK PLOT

        ellrange = np.arange(0,3000)
        clkk = self.theory.gCl("kk",ellrange)

        
        cents = self.cents
        
        for m in mlist:
            modlmap = self.modlmap[m]
            clkk2d = self.theory.gCl('kk',modlmap)

            clkk1d = self.binner[m].bin(clkk2d)[1]
            nlkk = self.binner[m].bin(self.qest[m].N.Nlkk['TT'])[1]
            totkk = self.binner[m].bin(clkk2d+self.qest[m].N.Nlkk['TT'])[1]
            
            pl = io.Plotter(scaleY='log')
            pl.add(ellrange,clkk,color="k",lw=2)
            pl.add(cents,nlkk,ls="--")
            pl.add(cents,totkk,ls="-")
            
            y,err = unpack("rxr",m)
            pl.addErr(cents,y,err,ls="none",marker="o")
            y,err = unpack("rxr-n0",m)
            pl.addErr(cents,y,err,ls="none",marker="o")
            y,err = unpack("rxi",m)
            pl.addErr(cents,y,err,ls="none",marker="o")
            y,err = unpack("ixi",m)
            pl.add(cents,y,ls="none",marker="x",color="k")
            y,err = unpack("n0",m)
            pl.add(cents,y,ls="--")
            pl.add(cents,y+clkk1d,ls="-")
            pl.legendOn()
            pl._ax.set_ylim(1.e-10,1.e-6)
            pl.done(io.dout_dir+"clkkrecon_"+m+".png")


        pl = io.Plotter()
        rxi_e,rxi_err_e = unpack("rxi","e")

        for m in ['s','r']:
            
            y,err = unpack("rxi",m)
            diff = (y-rxi_e)/rxi_e
            diff_err = np.abs(y/rxi_e)*np.sqrt((err/y)**2.+(rxi_err_e/rxi_e)**2.)
            pl.addErr(cents,diff,diff_err,ls="--",marker="o",label=m+"-cross")
            
        pl.legendOn()
        pl.hline()
        pl._ax.set_ylim(-0.1,0.1)
        pl.done(io.dout_dir+"clkkdiffrecon_cross.png")

        pl = io.Plotter()
        rxr_e,rxr_err_e = unpack("rxr-n0","e")

        for m in ['s','r']:
            y,err = unpack("rxr-n0",m)
            diff = (y-rxr_e)/rxr_e
            diff_err = np.abs(y/rxr_e)*np.sqrt((err/y)**2.+(rxr_err_e/rxr_e)**2.)
            pl.addErr(cents,diff,diff_err,ls="-",marker="o",label=m+"-auto")
            
            
        pl.legendOn()
        pl.hline()
        pl._ax.set_ylim(-0.4,0.4)
        pl.done(io.dout_dir+"clkkdiffrecon_auto.png")


        pl = io.Plotter()

        for m in mlist:
            modlmap = self.modlmap[m]
            clkk2d = self.theory.gCl('kk',modlmap)
            clkk1d = self.binner[m].bin(clkk2d)[1]
            
            
            y,err = unpack("rxi",m)
            diff = (y-clkk1d)/clkk1d
            diff_err = err/clkk1d
            pl.addErr(cents,diff,diff_err,ls="--",marker="o",label=m+"-cross")
            
        pl.legendOn()
        pl.hline()
        pl._ax.set_ylim(-0.1,0.1)
        pl.done(io.dout_dir+"clkkdiffrecon_theory_cross.png")


        pl = io.Plotter()

        for m in mlist:
            modlmap = self.modlmap[m]
            clkk2d = self.theory.gCl('kk',modlmap)
            clkk1d = self.binner[m].bin(clkk2d)[1]
            
            y,err = unpack("rxr-n0",m)
            diff = (y-clkk1d)/clkk1d
            diff_err = err/clkk1d
            pl.addErr(cents,diff,diff_err,ls="-",marker="o",label=m+"-auto")
            
        pl.legendOn()
        pl.hline()
        pl._ax.set_ylim(-0.4,0.4)
        pl.done(io.dout_dir+"clkkdiffrecon_theory_auto.png")
Exemple #10
0
import os, sys, glob
from orphics.theory.cosmology import Cosmology
import numpy as np

cc = Cosmology(lmax=3000, pickling=True)
ells = np.arange(2, 3000, 1)
clkktheory = cc.theory.gCl("kk", ells)

output_dir = "/gpfs01/astro/workarea/msyriac/data/sigurd_sims/"

clkkn0pers = []
clkkpers = []
sdppers = []
clttpers = []

pl = io.Plotter(scaleY="log")
pl.add(ells, clkktheory, color="k", lw=3)

for k in range(50):
    print(k)

    try:
        exp_name = "south"
        cents_pwr, sn0subbed = pickle.load(
            open(
                output_dir + exp_name + "_clkk_n0subbed_" + str(k).zfill(2) +
                ".pkl", 'rb'))
        cents_pwr, saclkk = pickle.load(
            open(
                output_dir + exp_name + "_rawclkk_" + str(k).zfill(2) + ".pkl",
                'rb'))
Exemple #11
0

theory_file_root = "data/Aug6_highAcc_CDM"
theory = cmb.loadTheorySpectraFromCAMB(theory_file_root,
                                       unlensedEqualsLensed=False,
                                       useTotal=False,
                                       TCMB=2.7255e6,
                                       lpad=9000,
                                       get_dimensionless=False)

ells, tcltt = b(theory.lCl('TT', fineells))
ells, tclee = b(theory.lCl('EE', fineells))
ells, tclte = b(theory.lCl('TE', fineells))
ells, tclbb = b(theory.lCl('BB', fineells))

pl = io.Plotter(scaleY='log')
pl.add(ells, cltt * ells**2.)
pl.add(ells, clee * ells**2.)
pl.add(ells, tcltt * ells**2., color="k")
pl.add(ells, tclee * ells**2., color="k")
pl.add(ells, clbb * ells**2.)
pl.add(ells, tclbb * ells**2., color="k")
pl._ax.set_ylim(1.e-3, 5e5)
pl.done(io.dout_dir + "sigurd_alex_clcomp_.png")

cut_root = "/gpfs01/astro/workarea/msyriac/data/depot/distortions/"
mells, mcltt, _ = np.loadtxt(
    cut_root + "distspectrav6unlensed_equator_car_TT_unlensed.txt",
    unpack=True)
mells, mclee, _ = np.loadtxt(
    cut_root + "distspectrav6unlensed_equator_car_EE_unlensed.txt",
Exemple #12
0
    cents,clkk1d = lbinner.bin(clkk2d)
    idiag_est = clkk1d+(3.*(idiag**2.-clkk1d**2.)/clkk1d)

    
    io.quickPlot2d(stats.cov2corr(rxr['covmean']),pout_dir+"rcorr.png")
    io.quickPlot2d(stats.cov2corr(rxr_raw['covmean']),pout_dir+"corr.png")

    # if paper and not(unlensed):
    #     np.save(pout_dir+"covmat_"+str(area)+"sqdeg.npy",rxr['cov'])
    #     np.save(pout_dir+"lbin_edges_"+str(area)+"sqdeg.npy",lbin_edges)
    #     import cPickle as pickle
    #     pickle.dump((cents,mpibox.stats['noisett']['mean']),open(pout_dir+"noise.pkl",'wb'))
    
    ellrange = np.arange(2,kellmax,1)
    clkk = theory.gCl('kk',ellrange)
    pl = io.Plotter(scaleY='log',labelX="$L$",labelY="$C^{\\kappa\\kappa}_L$")#,scaleX='log')
    pl.add(ellrange,clkk,color="k",lw=3)
    io.save_cols(pout_dir+"_plot_clkk_theory.txt",(ellrange,clkk))
    pl.addErr(cents-140,ixr['mean'],yerr=ixr['errmean'],ls="none",marker="o",label='Input x Reconstruction')
    io.save_cols(pout_dir+"_plot_inputXrecon.txt",(cents,ixr['mean'],ixr['errmean']))
    pl.addErr(cents,rxr_raw['mean'],yerr=rxr_raw['errmean'],ls="none",marker="o",label='Total Autospectrum',alpha=0.5)
    io.save_cols(pout_dir+"_plot_reconXrecon_raw.txt",(cents,rxr_raw['mean'],rxr_raw['errmean']))
    if not(paper): pl.addErr(cents,rxr['mean'],yerr=rxr['errmean'],ls="none",marker="o",label='rxr sdn0')
    # pl.addErr(cents,ixi['mean'],yerr=ixi['errmean'],ls="none",marker="x",color="k",label='Input x Reconstruction')
    #pl.add(cents,ixi['mean'],ls="none",marker="x",color="k",label='Input x Input')
    if not(paper) and doN1: pl.add(cents+140,unb1d,marker="o",label='Debiased Reconstruction Autospectrum',ls="none")
    if not(paper): pl.add(cents,diagraw,ls="--",marker="^",label="diag raw",alpha=0.5)
    pl.add(cents,diagn0sub,ls="--",marker="^",label="Variance of Power")
    io.save_cols(pout_dir+"_plot_varPower.txt",(cents,diagn0sub))
    #pl.add(cents,idiag_est,ls="--",marker="^",label="Variance of Power from Cross")
    #pl.add(cents,diagcross,ls="--",marker="^",label="diag cross")
Exemple #13
0
    def plot_diff(self,
                  spec,
                  keys,
                  out_dir=None,
                  scaleY='linear',
                  scaleX='linear',
                  xlim=None,
                  ylim=None,
                  pl=None,
                  skip_labels=True,
                  ratio=True,
                  save_root=None):
        if pl is None: pl = io.Plotter(scaleY=scaleY, scaleX=scaleX)
        cmb_specs = ['TT', 'EE', 'BB', 'TE', 'ET', 'EB', 'BE', 'TB', 'BT']
        done_spec = []

        suffspec = ""
        if (spec in cmb_specs) and self.pol:
            suffspec = spec

        for key in keys:

            st = self.mpibox.stats[key + suffspec]

            if ("unlensed" in key) or ("delensed" in key):
                spec_key = "u" + spec
            else:
                if (spec in cmb_specs):
                    spec_key = "l" + spec
                else:
                    spec_key = spec

            if spec_key not in done_spec:
                done_spec.append(spec_key)
                th2d = self.theory.gCl(spec_key, self.modlmap)
                if ("unlensed" in key) or ("delensed" in key):
                    cents, th1d_unlensed = self.lbinner.bin(th2d)
                else:
                    cents, th1d = self.lbinner.bin(th2d)

            if ("unlensed" in key) or ("delensed" in key):
                th1dnow = th1d_unlensed
            else:
                th1dnow = th1d

            rdiff = (st['mean'] - th1dnow)
            rerr = st['errmean']
            div = th1dnow if ratio else 1.

            pl.addErr(cents,
                      rdiff / div,
                      yerr=rerr / div,
                      marker="x",
                      ls="none",
                      label=key)
            if save_root is not None:
                io.save_cols(save_root + spec + "_" + key + ".txt",
                             (cents, rdiff / div, rerr / div))

        if not (skip_labels): pl.legendOn(labsize=10)
        if xlim is not None: pl._ax.set_xlim(xlim[0], xlim[1])
        if ylim is not None: pl._ax.set_ylim(ylim[0], ylim[1])
        pl.hline()
        if pl is None: pl.done(out_dir)
Exemple #14
0
    def getKappa(self, XY, weightedFt=False):

        assert self._hasX and self._hasY
        assert XY in ['TT', 'TE', 'ET', 'EB', 'TB', 'EE']
        X, Y = XY

        WXY = self.N.WXY(XY)
        WY = self.N.WY(Y + Y)

        import orphics.tools.io as io
        io.quickPlot2d(np.fft.fftshift((WXY.real)), "wxy_" + XY + ".png")
        io.quickPlot2d(np.fft.fftshift((WY.real)), "wyy_" + Y + Y + ".png")
        io.quickPlot2d(np.fft.fftshift((self.N.Nlkk[XY])),
                       "nxy_" + XY + ".png")

        lx = self.N.lxMap
        ly = self.N.lyMap

        if Y in ['E', 'B']:
            phaseY = self.phaseY
        else:
            phaseY = 1.

        phaseB = (int(Y == 'B') * 1.j) + (int(Y != 'B'))

        fmask = self.N.modLMap * 0. + 1.
        #fmask[self.N.modLMap>6000]=0.

        HighMapStar = ifft(self.kHigh[Y] * WY * phaseY * phaseB * fmask,
                           axes=[-2, -1],
                           normalize=True).conjugate()
        kPx = fft(
            ifft(self.kGradx[X] * WXY * phaseY, axes=[-2, -1],
                 normalize=True) * HighMapStar,
            axes=[-2, -1]) * fmask
        kPy = fft(
            ifft(self.kGrady[X] * WXY * phaseY, axes=[-2, -1],
                 normalize=True) * HighMapStar,
            axes=[-2, -1]) * fmask
        rawKappa = ifft(1.j * lx * kPx + 1.j * ly * kPy,
                        axes=[-2, -1],
                        normalize=True).real

        AL = np.nan_to_num(self.AL[XY] * fmask)

        kappaft = -AL * fft(rawKappa, axes=[-2, -1]) * fmask
        self.kappa = ifft(kappaft, axes=[-2, -1], normalize=True).real
        try:
            #raise
            assert not (np.any(np.isnan(self.kappa)))
        except:
            import orphics.tools.io as io
            import orphics.tools.stats as stats
            io.quickPlot2d(self.kappa.real, "nankappa.png")
            debug_edges = np.arange(20, 20000, 100)
            dbinner = stats.bin2D(self.N.modLMap, debug_edges)
            cents, bclkk = dbinner.bin(self.N.clkk2d)
            cents, nlkktt = dbinner.bin(self.N.Nlkk['TT'])
            try:
                cents, nlkkeb = dbinner.bin(self.N.Nlkk['EB'])
            except:
                pass
            pl = io.Plotter(scaleY='log', scaleX='log')
            pl.add(cents, bclkk)
            pl.add(cents, nlkktt, label="TT")
            try:
                pl.add(cents, nlkkeb, label="EB")
            except:
                pass
            pl.legendOn()
            pl.done("clkk.png")

            sys.exit()

        # from orphics.tools.io import Plotter
        # pl = Plotter()
        # #pl.plot2d(np.nan_to_num(self.kappa))
        # pl.plot2d((self.kappa.real))
        # pl.done("output/nankappa.png")
        # sys.exit(0)
        # try:
        #     assert not(np.any(np.isnan(self.kappa)))
        # except:
        #     from orphics.tools.io import Plotter
        #     pl = Plotter()
        #     pl.plot2d(np.nan_to_num(self.kappa))
        #     pl.done("output/nankappa.png")
        #     sys.exit(0)

        if self.doCurl:
            OmAL = self.OmAL[XY]
            rawCurl = ifft(1.j * lx * kPy - 1.j * ly * kPx,
                           axes=[-2, -1],
                           normalize=True).real
            self.curl = -ifft(OmAL * fft(rawCurl, axes=[-2, -1]),
                              axes=[-2, -1],
                              normalize=True)
            return self.kappa, self.curl

        return self.kappa
Exemple #15
0
    cents1d, bin1d_iso = binner1d.binned(fine1d_ells, cl1d * fine1d_ells)
    cents1d, bin1d_iso_norm = binner1d.binned(fine1d_ells, fine1d_ells)
    bin1d_iso /= bin1d_iso_norm

    # the most correctest way to do it if you can work with 2d matrices
    cents2d, bin2d = binner2d.bin(cl2d)

    assert np.all(np.isclose(cents1d, cents2d))

    # the not so great way to do it, especially if your spectrum is very
    # red like with TT, or has peaks and troughs like with TT
    try:
        interped1d = theory.lCl(spec, cents1d)
    except:
        interped1d = theory.gCl(spec, cents1d)

    # a percentage difference function
    pdiff = lambda x, y: (x - y) * 100. / y

    # define 2d binning as the truth
    truth = bin2d
    cents = cents2d

    pl = io.Plotter(labelX="$\ell$", labelY="% diff")
    pl.add(cents, pdiff(bin1d, truth), label="1d mean")
    pl.add(cents, pdiff(bin1d_iso, truth), label="1d iso mean")
    pl.add(cents, pdiff(interped1d, truth), label="interpolated")
    pl.legendOn(loc="upper right")
    pl._ax.set_ylim(-5, 30)
    pl.done(spec + "_bin.png")
Exemple #16
0
theory = cc.theory
cltt = theory.lCl('TT',ellfine)

cltt2d = theory.lCl('TT',modLMap)


nfunc = cmb.get_noise_func(beamArcmin,noiseMukArcmin,ellmin=ellmin_cmb,ellmax=ellmax_cmb,TCMB=2.7255e6,lknee=lknee,alpha=alpha)

nells = nfunc(ellfine)

n2d = nfunc(modLMap)

n2dp = n2d/pwindow**2.
cents, nclsp = binner.bin(n2dp)
cents, ncls = binner.bin(n2d)


pl = io.Plotter(scaleY='log',scaleX='log')
pl.add(ellfine,cltt*ellfine**2.)
pl.add(ellfine,nells*ellfine**2.,ls="--")
pl.add(cents,nclsp*cents**2.,ls="-.")
pl.legendOn()
pl.done(out_dir+"pcls.png")


pl = io.Plotter(labelY="% diff of $N_{\ell}$ with pixel",labelX="$\ell$")
pl.add(cents,(nclsp-ncls)*100./ncls)
pl.done(out_dir+"pdiff.png")


Exemple #17
0
#meanfield = {}
#meanfieled_pwr = {}
cross = {}
n0 = {}
for region in ['equator', 'south']:
    print(region)
    save_dir = "/gpfs01/astro/workarea/msyriac/data/depot/distortions/distspectrav4mfsub_" + region + "_"
    autokk[region] = np.loadtxt(save_dir + "autokk.txt", unpack=True)
    inputkk[region] = np.loadtxt(save_dir + "ikk.txt", unpack=True)
    cross[region] = np.loadtxt(save_dir + "rxikk.txt", unpack=True)
    n0[region] = np.loadtxt(save_dir + "sdn0.txt", unpack=True)

ells = inputkk["equator"][0]

# First let's look at the difference of the inputs
pl = io.Plotter(labelX="$L$", labelY="$\Delta C_L^{II}/C_L^{II}$")
eq = inputkk["equator"][1]
so = inputkk["south"][1]
pl.add(ells, (so - eq) / eq)
pl.hline()
pl._ax.set_xlim(0, lmax)
pl.done(io.dout_dir + "dist_inpdiff.png")

# Next diff w.r.t input
pl = io.Plotter(labelX="$L$", labelY="$(C_L^{IR}-C_L^{II})/C_L^{II}$")
for ls, region in zip(("-", "--"), ['equator', 'south']):
    inp = inputkk[region][1]
    crossp = cross[region][1]
    pl.add(ells, (crossp - inp) / inp, ls=ls, label=region)
pl.hline()
pl.legendOn()
Exemple #18
0
expList = ['S4-1.0-paper','S4-1.5-paper','S4-2.0-paper','S4-2.5-paper','S4-3.0-paper']
gridName = "grid-default"


# get mass and z grids
ms = listFromConfig(Config,gridName,'mexprange')
mexp_edges = np.arange(ms[0],ms[1]+ms[2],ms[2])
zs = listFromConfig(Config,gridName,'zrange')
z_edges = np.arange(zs[0],zs[1]+zs[2],zs[2])



lkneeList = np.arange(0,6000,500.)
alphaList = [-4.,-4.5,-5.]

pl = io.Plotter(scaleY='log',labelX="$\ell_{\mathrm{knee}}$",labelY="Cluster detections",ftsize=16)


lslist = ["--","-","-."]
collist = ['#1C110A','#E4D6A7','#E9B44C','#9B2915','#50A2A7']
lablist = ['S4 1.0\'','S4 1.5\'','S4 2.0\'','S4 2.5\'','S4 3.0\'']

for expName,col,lab in zip(expList,collist,lablist):
    for alpha,ls in zip(alphaList,lslist):
        Ns = []
        for lknee in lkneeList:

            try:
                N = sfisher.counts_from_config(Config,bigDataDir,version,expName,gridName,mexp_edges,z_edges,lkneeTOverride = lknee,alphaTOverride=alpha)
                print(N)
            except:
Exemple #19
0
        io.quickPlot2d(np.fft.fftshift(reb2d), out_dir + "reb2d.png")

        finells = np.arange(2, kellmax, 1)
        clkk1d = theory.gCl('kk', finells)
        ntt2d = rtt2d - clkk2d
        neb2d = reb2d - clkk2d

        cents, rtt1d = lbinner_dat.bin(rtt2d)
        cents, reb1d = lbinner_dat.bin(reb2d)
        cents, ntt1d = lbinner_dat.bin(ntt2d)
        cents, neb1d = lbinner_dat.bin(neb2d)

        cents, thntt1d = lbinner_dat.bin(thntt2d)
        cents, thneb1d = lbinner_dat.bin(thneb2d)

        pl = io.Plotter(scaleX='linear', scaleY='log')
        pl.add(finells, clkk1d, color="k")

        pl.add(cents,
               rtt1d,
               ls="none",
               marker="o",
               alpha=0.1,
               label="clkk+ntt",
               color="C0")
        pl.add(cents,
               reb1d,
               ls="none",
               marker="o",
               alpha=0.1,
               label="clkk+neb",
np.random.seed(100)

# probability function is assumed to be exponential
x0 = 10.  # the knee of the exponential
norm = 6.065  # this norm was explicitly calculated for x0=10 and richness bounds [5,10]
prob = lambda x: np.exp(-x / x0
                        ) / norm  # analytical pdf of exponential distribution
cdf = lambda x: np.piecewise(
    x, [x <= a, np.logical_and(x > a, x < b), x >= b], [
        lambda x: 0., lambda x: x0 *
        (np.exp(-a / x0) - np.exp(-x / x0)) / norm, lambda x: 1.
    ])  # analytic cdf of the same

# check cdf and norm
prange = np.linspace(a, b, 100)
pl = io.Plotter(labelX="richness $x$", labelY="$P(X<x)$")
pl.add(prange, cdf(prange))
pl.done("cdf.png")
print(("Norm: ", np.trapz(prob(prange), prange)))

# sample using the inverse transform sampling method
inv_cdf = lambda y: -x0 * np.log(np.exp(-a / x0) - y * norm / x0
                                 )  # analytic inverse of cdf
Nsamples = 8000
samples = [inv_cdf(np.random.random()) for x in range(Nsamples)]

# histogram
nbins = 20
n, bins, patches = plt.hist(samples,
                            nbins,
                            facecolor='blue',
Exemple #21
0
    io.quickPlot2d(mpibox.stacks['mkappa'],out_dir+"stack.png")

    mean = mpibox.stats['prof']['mean']
    cov = mpibox.stats['prof']['covmean']
    siginv = np.linalg.inv(cov)
    
    chisq = np.dot(np.dot(mean,siginv),mean)
    print((np.sqrt(chisq)))

    mass_range = np.linspace(1.e14,5.e14,300)
    Likes = []
    for k,m in enumerate(mass_range):
        trial = get_nfw(m)
        kellmin = 200
        kellmax = 8500
        trial = enmap.ndmap(fmaps.filter_map(trial,true2d*0.+1.,modlmap,lowPass=kellmax,highPass=kellmin),wcs)
        cents,theory = rbinner.bin(trial)
        Likes.append(np.exp(-0.5*stats.fchisq(mean,siginv,theory,amp=1.)))
        if k%10==0: print(m)

    Likes = np.array(Likes)
    Likes /= Likes.sum()
    
    pl = io.Plotter()
    pl.add(mass_range,Likes)
    pl._ax.axvline(x=true_mass,ls="--")
    pl.done(out_dir+"likes.png")

    

                                       tellmaxX=tellmax,
                                       pellminX=pellmin,
                                       pellmaxX=pellmax)
nlgen.N.getNlkk2d('TT', halo=True)
nlkk0_2d = nlgen.N.Nlkk['TT']
cents, nlkk0 = lbinner_dat.bin(nlkk0_2d)
clkk2d = theory.gCl('kk', modlmap_dat)

cents, nltt = lbinner_dat.bin(nTX)

# lensed cls prediction
dtheory = cmb.get_lensed_cls(theory, ellrange, clkk, lmax)
dlcltt = dtheory.lCl('TT', ellrange)
ducltt = dtheory.uCl('TT', ellrange)

plkk = io.Plotter(scaleY='log')
plkk.add(ellrange, clkk, color="k", lw=3)
plkk.add(cents, nlkk0, ls="--")  #,alpha=1/(niter+3.))

pltt = io.Plotter(scaleY='log')
pltt.add(ellrange, ucltt * ellrange**2., ls="--")
pltt.add(ellrange, lcltt * ellrange**2., ls="-")
pltt.add(cents, nltt * cents**2., ls="--", color="k")
#pltt.add(ellrange,dlcltt*ellrange**2.,ls="-.")

# unlensed limit
nlgen = qe.NlGenerator(template, theory, lensedEqualsUnlensed=True)
nlgen.updateNoise(beamX=beam,
                  noiseTX=noiseT,
                  noisePX=0.,
                  tellminX=tellmin,
Exemple #23
0
from orphics.theory.cosmology import Cosmology
import numpy as np
import orphics.tools.io as io

cc = Cosmology(lmax=6000,pickling=True)


ells = np.arange(2,6000,1)
ucltt = cc.theory.uCl('TT',ells)
lcltt = cc.theory.lCl('TT',ells)

pl = io.Plotter(scaleY='log',scaleX='log')
pl.add(ells,ucltt*ells**2.,ls="--")
pl.add(ells,lcltt*ells**2.)
pl.done("cmbdemo.png")
Exemple #24
0
Config.optionxform = str
Config.read(iniFile)

freq_to_use = 150.

cc = Cosmology(lmax=8000, pickling=True)
theory = cc.theory

ells = np.arange(2, 8000, 1)
cltt = theory.lCl('TT', ells)
TCMB = 2.7255e6

out_dir = os.environ['WWW']

pl = io.Plotter(scaleY='log',
                labelX="$\ell$",
                labelY="$\ell^2 C_{\ell}$",
                ftsize=20)

for expName, lab in zip(['S4-1.0-0.4-noatm', 'S4-1.0-0.4'],
                        ['S4 1arc no atm', 'S4 1arc lknee=5500 (in paper)']):

    beam = listFromConfig(Config, expName, 'beams')
    noise = listFromConfig(Config, expName, 'noises')
    freq = listFromConfig(Config, expName, 'freqs')
    lkneeT, lkneeP = listFromConfig(Config, expName, 'lknee')
    alphaT, alphaP = listFromConfig(Config, expName, 'alpha')

    print((expName, beam, noise, lkneeT, lkneeP, alphaT, alphaP))

    ind = np.where(np.isclose(freq, freq_to_use))
    beamFind = np.array(beam)[ind]