예제 #1
0
def test_hod():

    zs = np.linspace(0., 3., 3)  #np.array([0.])
    ks = np.geomspace(1e-4, 100, 100)
    ms = np.geomspace(1e7, 1e17, 2000)
    hcos = hmvec.HaloModel(zs, ks, ms, nfw_numeric=False)
    hcos.add_hod("g", mthresh=10**10.5 + zs * 0., corr="max")

    pl = io.Plotter(xyscale='loglog')
    for i in range(zs.size):
        pl.add(ms, hcos.hods['g']['Nc'][i])
        pl.add(ms, hcos.hods['g']['Ns'][i], ls='--')
    pl._ax.set_ylim(1e-1, 2e3)
    pl.done()

    hcos.add_battaglia_profile("electron", family="AGN", xmax=50, nxs=30000)

    pmm = hcos.get_power_1halo(name="nfw") + hcos.get_power_2halo(name="nfw")
    pee = hcos.get_power_1halo(name="electron") + hcos.get_power_2halo(
        name="electron")
    pgg = hcos.get_power_2halo(name="g") + hcos.get_power_1halo(name="g")
    pge = hcos.get_power_1halo("g", "electron") + hcos.get_power_2halo(
        "g", "electron")
    #sys.exit()
    bg = hcos.hods['g']['bg']
    for i in range(zs.size):
        pl = io.Plotter(xyscale='loglog')
        pl.add(ks, pmm[i] * bg[i]**2., label='bg^2 Pmm')
        pl.add(ks, pmm[i], label='Pmm')
        pl.add(ks, pgg[i], label='Pgg', ls="--")
        pl.add(ks, pee[i], label='Pee')
        pl.add(ks, pge[i], label='Pge')
        pl.done()
예제 #2
0
def test_correlated_alm():
    lmax = 2000
    ells = np.arange(0, lmax, 1)

    def get_cls(ells, index, amplitude):
        cls = amplitude * ells.astype(np.float32)**index
        cls[ells < 2] = 0
        return cls

    Clf1f1 = get_cls(ells, -1, 1)
    Clf2f2 = get_cls(ells, -1.3, 2)
    Clf1f2 = get_cls(ells, -1.4, 0.5)

    alm_f1 = hp.synalm(Clf1f1, lmax=lmax - 1)
    alm_f2 = deltag.generate_correlated_alm(alm_f1, Clf1f1, Clf2f2, Clf1f2)

    f1f1 = hp.alm2cl(alm_f1, alm_f1)
    f2f2 = hp.alm2cl(alm_f2, alm_f2)
    f1f2 = hp.alm2cl(alm_f1, alm_f2)

    pl = io.Plotter(xyscale='linlog', scalefn=lambda x: x)
    pl.add(ells, f1f1, color="C0", alpha=0.4)
    pl.add(ells, f2f2, color="C1", alpha=0.4)
    pl.add(ells, f1f2, color="C2", alpha=0.4)
    pl.add(ells, Clf1f1, label="f1f1", color="C0", ls="--", lw=3)
    pl.add(ells, Clf2f2, label="f2f2", color="C1", ls="--", lw=3)
    pl.add(ells, Clf1f2, label="f1f2", color="C2", ls="--", lw=3)
    pl.done()
예제 #3
0
def test_illustris():
    
    zs = np.linspace(0.,3.,4)[:1]
    ms = np.geomspace(1e8,1e16,1000)
    ks = np.geomspace(1e-2,30,1001)

    hcos = hmvec.HaloModel(zs,ks,ms=ms,halofit=None,mdef='vir',nfw_numeric=False)
    hcos.add_battaglia_profile("electron",family="AGN",xmax=50,nxs=30000)
    pee = hcos.get_power("electron")
    pnn = hcos.get_power("nfw")
    pne = hcos.get_power("nfw","electron")

    p1 = hcos.total_matter_power_spectrum(pnn,pne,pee)
    p0 = pnn

    

    h = hcos.h
    from matplotlib import cm
    pl = io.Plotter(xyscale='loglin',xlabel='$k$ (h/Mpc)',ylabel='$\\Delta P / P$')
    for i in range(zs.size):
        pl.add(ks/h,p1[i]/p0[i],color=cm.Reds(np.linspace(0.3,0.95,zs.size)[::-1][i]),label='hmvec + Battaglia')
    ok,od = np.loadtxt("data/schneider_horizon_agn.csv",delimiter=',',unpack=True)
    pl.add(ok,od,lw=2,color='k',label='Horizon AGN')
    ok,od = np.loadtxt("data/schneider_owls.csv",delimiter=',',unpack=True)
    pl.add(ok,od,lw=2,color='k',ls='--',label='OWLS')
    pl.vline(x=10.)
    pl.hline(y=1.)
    pl._ax.set_ylim(0.68,1.04)
    pl._ax.set_xlim(0.08,25)
    pl.done("illustris_comp.png")
예제 #4
0
def main():
    z_edges = np.arange(0., 1.0, 0.05)
    Mexp_edges = np.arange(14.0, 15.0, 0.05)

    emu = NmzEmulator(Mexp_edges, z_edges)
    mzs = emu.get_catalog(poisson=True)
    pdf2d, _, _ = np.histogram2d(mzs[:, 0],
                                 mzs[:, 1],
                                 bins=(Mexp_edges, z_edges))
    print(emu.Nmz.sum(), pdf2d.sum(), lnlike(pdf2d, emu.Nmz))

    io.plot_img(pdf2d, "pdf2d.png", flip=False)
    io.plot_img(emu.Nmz, "N2d.png", flip=False)

    data = pdf2d

    true_as = emu.cc.cosmo['As']
    cparams = cosmo.defaultCosmology
    lnlikes = []
    Ases = np.linspace(2.19e-9, 2.21e-9, 30)
    for As in Ases:
        cparams['As'] = As
        temu = NmzEmulator(Mexp_edges, z_edges, cosmo_params=cparams)
        lnlikes.append(lnlike(data, temu.Nmz))

    lnlikes = np.array(lnlikes)

    pl = io.Plotter(xlabel="As", ylabel="lnlike")
    #pl.add(Ases,np.exp(lnlikes))
    pl.add(Ases, np.exp(lnlikes - lnlikes.max()))
    pl.vline(x=true_as, ls="--")
    pl.done("lnlike.png")
예제 #5
0
def plot_corrcoeff(cents, c1ds_data, plot_fname):
    from orphics import io
    dpi = 300
    ncomps = c1ds_data.shape[0]
    if ncomps == 3:
        pols = ['150-I', '150-Q', '150-U']
    elif ncomps == 6:
        pols = ['150-I', '150-Q', '150-U', '90-I', '90-Q', '90-U']

    pl = io.Plotter(xlabel="$\\ell$",
                    ylabel="$N_{XY}/\\sqrt{N_{XX}N_{YY}}$",
                    xyscale='linlin')
    for i in range(c1ds_data.shape[0]):
        for j in range(i + 1, c1ds_data.shape[0]):
            polstring = "%s x %s" % (pols[i], pols[j])
            pl.add(cents, c1ds_data[i, j], label=polstring)
    pl._ax.set_xlim(30, 10000)
    pl._ax.set_ylim(-0.3, 0.3)
    pl.hline(y=0.05)
    pl.hline(y=-0.05)
    pl.hline(y=0.01, ls='-.')
    pl.hline(y=-0.01, ls='-.')
    pl.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    pl.hline(y=0, ls='-')
    pl.vline(x=500)
    pl.vline(x=300, ls='-.')
    pl.done("%s_compare_corrcoeff.png" % (plot_fname), dpi=dpi)
예제 #6
0
def test_fft_transform():

    zs = np.linspace(0.1, 4., 4)
    ms = np.geomspace(2e9, 1e17, 5)
    ks = np.geomspace(1e-4, 100, 1001)
    hcos = hm.HaloModel(zs, ks, ms=ms)
    with bench.show("nfw"):
        _, ouks = hcos.add_nfw_profile("matter", ms)
    cs = hcos.concentration(ms)
    rvirs = hcos.rvir(ms[None, :], hcos.zs[:, None])
    rscales = (rvirs / cs)[..., None]
    rhoscale = 1  # we do not care about normalization of profile
    rmax = 10 * rvirs.max()
    dr = 0.001
    iks, iuk = hm.uk_fft(lambda rs: hm.rho_nfw(rs, rhoscale, rscales),
                         rvirs,
                         dr=dr,
                         rmax=rmax)
    k = 0
    for i in range(iuk.shape[0]):
        for j in range(iuk.shape[1]):
            k += 1
            pl = io.Plotter(xyscale='loglog')
            pl.add(iks / (1. + hcos.zs[i]), iuk[i, j])
            pl.add(hcos.ks, ouks[i, j], ls='--')
            pl.hline(y=1)
            pl._ax.set_xlim(ks.min(), ks.max())
            pl.done("profile_test_%d.png" % k)
    print(iuk.shape)
예제 #7
0
def plot(cents, nls, ncoadd, pols, tag="default"):
    npols = len(pols)
    pl = io.Plotter(xyscale='linlog', ylabel='$C_L$', xlabel='$L$')
    for i in range(npols):
        for j in range(i, npols):
            nl1d = nls[i, j]
            if i != j:
                pl.add(cents, np.abs(nl1d), ls="--",
                       alpha=0.2)  #,label=pols[i]+'x'+pols[j]
            else:
                pl.add(cents, nl1d, alpha=0.6)  #,label=pols[i])

    ells = np.arange(0, 2500, 1)
    theory = cosmology.default_theory()
    clkk = theory.gCl('kk', ells)
    pl.add(ells, clkk, color='k', lw=3)
    pl.legend(loc='upper right')
    pl._ax.set_ylim(1e-10, 1e-4)
    pl.add(cents, ncoadd, color='red', lw=3)  #,label='MV')
    pl.done("nlkk_%s.png" % tag)
    # pl = io.Plotter(xyscale='linlin')
    # pl.add(cents,nls[0,3],label="TT x EB")
    # pl.hline(y=0)
    # pl.done("nltteb_%s.png"%tag)
    io.save_cols("lensing_noise_%s.txt" % tag, (cents, ncoadd))
예제 #8
0
def test_illustris():

    zs = np.linspace(0., 3., 4)
    ms = np.geomspace(1e8, 1e16, 1000)
    ks = np.geomspace(1e-2, 30, 1001)

    hcos = hmvec.HaloModel(zs,
                           ks,
                           ms=ms,
                           halofit=None,
                           mdef='vir',
                           nfw_numeric=False)
    hcos.add_battaglia_profile("electron", family="AGN", xmax=50, nxs=30000)
    pee = hcos.get_power("electron")
    pnn = hcos.get_power("nfw")
    pne = hcos.get_power("nfw", "electron")

    p1 = hcos.total_matter_power_spectrum(pnn, pne, pee)
    p0 = pnn

    h = hcos.h
    from matplotlib import cm
    pl = io.Plotter(xyscale='loglin',
                    xlabel='$k$ (h/Mpc)',
                    ylabel='$\\Delta P / P$')
    for i in range(zs.size):
        pl.add(ks / h,
               p1[i] / p0[i],
               color=cm.Reds(np.linspace(0.3, 0.95, zs.size)[i]))
    pl.vline(x=10.)
    pl.hline(y=1.)
    pl._ax.set_ylim(0.68, 1.04)
    pl._ax.set_xlim(0.08, 25)
    pl.done("illustris_comp.png")
예제 #9
0
def test_massfn():

    from szar import counts
    
    import hmf
    from cluster_toolkit import massfunction

    zs = np.linspace(0.,3.,20)
    ms = np.geomspace(1e14,1e17,200)

    ks = np.geomspace(1e-3,10,101)

    from enlib import bench
    with bench.show("init"):
        hcos = hm.HaloModel(zs,ks,ms=ms,mass_function="tinker")

    dndM_ct2 = np.zeros((zs.size,ms.size))
    for i,z in enumerate(zs):
        h = hmf.MassFunction(z=z,Mmin=np.log10(ms.min()*hcos.h),Mmax=np.log10(ms.max()*hcos.h))
        if i==0: dndM_ct = np.zeros((zs.size,h.dndm.size))
        dndM_ct[i,:] = h.dndm.copy()
        dndM_ct2[i,:] = massfunction.dndM_at_M(ms*hcos.h, hcos.ks_sigma2/hcos.h, hcos.sPzk[i]*hcos.h**3, hcos.om0)
        

    fsky = 0.4

    hmf = counts.Halo_MF(counts.ClusterCosmology(hcos.params,skipCls=True),np.log10(ms),zs)
    nz_szar = hmf.N_of_z()*fsky
    print(nz_szar,nz_szar.shape)
    # sys.exit()
        
    print(hcos.nzm.shape,hcos.bh.shape)
    bh = hcos.bh
    nzm = hcos.nzm

    # ims,ins = np.loadtxt("data/tinker2008Fig5.txt",unpack=True,delimiter=',')
    # pl = io.Plotter(xyscale='linlin')
    # pl.add(ims,ins,ls="--")
    # pl.add(np.log10(ms*hcos.h),np.log10(nzm[0,:]*ms**2./hcos.rho_matter_z(0.)))
    # pl.done()

    chis = hcos.results.angular_diameter_distance(hcos.zs) * (1+hcos.zs)
    nz = np.trapz(nzm,ms,axis=-1)*4.*np.pi*chis**2./hcos.results.h_of_z(hcos.zs)*fsky 
    nz_ct = np.trapz(dndM_ct,h.m,axis=-1)*4.*np.pi*chis**2./hcos.results.h_of_z(hcos.zs)*fsky  * hcos.h**3.
    nz_ct2 = np.trapz(dndM_ct2,ms,axis=-1)*4.*np.pi*chis**2./hcos.results.h_of_z(hcos.zs)*fsky * hcos.h**3.
    pl = io.Plotter()
    pl.add(zs,nz,label='hmvec')
    pl.add(hmf.zarr,nz_szar,ls='--',label='szar')
    pl.add(zs,nz_ct,ls='-.',label='hmf')
    pl.add(zs,nz_ct2,ls='-.',label='ct')
    pl.done()
    n = np.trapz(nz,zs)
    print(n)
    n = np.trapz(nz_szar,hmf.zarr)
    print(n)
    n = np.trapz(nz_ct,zs)
    print(n)
    n = np.trapz(nz_ct2,zs)
    print(n)
예제 #10
0
def test_fft_integral():
    dx = 0.001
    xs = np.arange(dx, 20., dx)
    real = np.exp(-xs**2. / 2.)
    ks, uk = hm.fft_integral(xs, real)
    # pl = io.Plotter()
    # pl.add(xs,real)
    # pl.done()

    pl = io.Plotter(xyscale='loglin')
    pl.add(ks, uk)
    pl.add(ks, hm.analytic_fft_integral(ks), ls="--")
    pl.done()

    dr = 0.001
    rvir = 5.
    rmax = 10. * rvir
    r = np.arange(dr, rmax, dr)
    rs = 1
    rhos = 1e3
    rho = hm.rho_nfw(r, rhos, rs)

    # pl = io.Plotter(xyscale='loglog')
    # pl.add(r,rho)
    # pl.done()

    kmin = 1e-3
    kmax = 30
    ks = np.geomspace(kmin, kmax, 2000)
    uk = hm.uk_brute_force(r, rho, rvir, ks)

    pl = io.Plotter(xyscale='loglog')
    pl.add(ks, uk)
    #for rmax in [10.,20.,50.,100.,1000.,1e4]:
    #for dr in [0.1,0.05,0.01,0.001]:
    for dr in [0.001]:
        rmax = 100
        fks, fuks = hm.uk_fft(lambda x: hm.rho_nfw(x, rhos, rs),
                              rvir,
                              dr=dr,
                              rmax=rmax)
        pl.add(fks, fuks, ls="--")
    pl._ax.set_xlim(1e-3, 20)
    pl._ax.set_ylim(1e-3, 2)
    pl.done()
예제 #11
0
def test_limber():

    zs = np.geomspace(0.1,10.,40)
    ks = np.geomspace(1e-4,10,100)
    ms = np.geomspace(1e8,1e16,30)
    hcos = hmvec.HaloModel(zs,ks,ms,nfw_numeric=False)
    pmm_1h = hcos.get_power_1halo(name="nfw")
    pmm_2h = hcos.get_power_2halo(name="nfw")

    Wk = hcos.lensing_window(zs,zs=1100.)
    
    Pmm = pmm_1h + pmm_2h
    ells = np.linspace(100,1000,20)
    ckk = hcos.C_kk(ells,zs,ks,Pmm,lwindow1=Wk,lwindow2=Wk)
    theory = cosmology.default_theory()
    
    pl = io.Plotter(xyscale='linlog')
    pl.add(ells,ckk)
    pl.add(ells,theory.gCl('kk',ells),ls='--')
    pl.done('ckk_comp.png')

    bias = 2.
    nzs = np.exp(-(zs-1.0)**2./0.3**2.)
    ckg = hcos.C_kg(ells,zs,ks,Pmm*bias,lwindow=Wk,gzs=zs,gdndz=nzs)
    cgg = hcos.C_gg(ells,zs,ks,Pmm*bias**2,gzs=zs,gdndz=nzs)
    lc = cosmology.LimberCosmology(skipCls=True,low_acc=True)
    lc.addNz('g',zs,nzs,bias=bias)
    lc.generateCls(ells)
    ckg2 = lc.getCl('cmb','g')
    cgg2 = lc.getCl('g','g')
    
    pl = io.Plotter(xyscale='linlog')
    pl.add(ells,ckg)
    pl.add(ells,ckg2,ls='--')
    pl.done('ckg_comp.png')

    pl = io.Plotter(xyscale='linlog')
    pl.add(ells,cgg)
    pl.add(ells,cgg2,ls='--')
    pl.done('cgg_comp.png')
예제 #12
0
def test_lensing():

    zs = np.geomspace(0.1, 300., 30)
    ks = np.geomspace(1e-4, 20, 100)
    ms = np.geomspace(1e10, 1e17, 20)
    hcos = hmvec.HaloModel(zs, ks, ms, nfw_numeric=False)
    pmm_1h = hcos.get_power_1halo(name="nfw")
    pmm_2h = hcos.get_power_2halo(name="nfw")

    Wk = hcos.lensing_window(zs, zs=1100.)
    pl = io.Plotter(xyscale='loglin')
    pl.add(zs, Wk)
    pl.done()

    Pmm = pmm_1h + pmm_2h
    ells = np.linspace(100, 1000, 20)
    ckk = hcos.C_kk(ells, zs, ks, Pmm, lwindow1=Wk, lwindow2=Wk)
    theory = cosmology.default_theory()

    pl = io.Plotter(xyscale='linlog')
    pl.add(ells, ckk)
    pl.add(ells, theory.gCl('kk', ells), ls='--')
    pl.done()
예제 #13
0
def fit_noise_1d(npower,lmin=300,lmax=10000,wnoise_annulus=500,bin_annulus=20,lknee_guess=3000,alpha_guess=-4,
                 lknee_min=0,lknee_max=9000,alpha_min=-5,alpha_max=1,allow_low_wnoise=False):
    """Obtain a white noise + lknee + alpha fit to a 2D noise power spectrum
    The white noise part is inferred from the mean of lmax-wnoise_annulus < ells < lmax
    
    npower is 2d noise power
    """
    fbin_edges = np.arange(lmin,lmax,bin_annulus)
    modlmap = npower.modlmap()
    fbinner = stats.bin2D(modlmap,fbin_edges)
    cents,dn1d = fbinner.bin(npower)
    w2 = dn1d[np.logical_and(cents>=(lmax-wnoise_annulus),cents<lmax)].mean()
    try:
        # print(w2)
        assert w2>0
        # pl = io.Plotter('Dell')
        # pl.add(cents,dn1d)
        # pl.add(cents,cents*0+w2)
        # pl.done(os.environ['WORK']+"/nonpos_white_works.png")

    except:
        print("White noise level not positive")
        print(w2)
        if not(allow_low_wnoise):
            pl = io.Plotter('Dell')
            pl.add(cents,dn1d)
            pl.done(os.environ['WORK']+"/nonpos_white.png")
            raise
        else:
            w2 = np.abs(w2)
            print("Setting to ",w2)
            

    wnoise = np.sqrt(w2)*180.*60./np.pi
    ntemplatefunc = lambda x,lknee,alpha: fbinner.bin(rednoise(modlmap,wnoise,lknee=lknee,alpha=alpha))[1]
    #ntemplatefunc = lambda x,lknee,alpha: rednoise(x,wnoise,lknee=lknee,alpha=alpha) # FIXME: This switch needs testing !!!!
    res,_ = curve_fit(ntemplatefunc,cents,dn1d,p0=[lknee_guess,alpha_guess],bounds=([lknee_min,alpha_min],[lknee_max,alpha_max]))
    lknee_fit,alpha_fit = res

    # print(lknee_fit,alpha_fit,wnoise)
    # pl = io.Plotter(xyscale='linlog',xlabel='l',ylabel='D',scalefn=lambda x: x**2./2./np.pi)
    # pl.add(cents,dn1d)
    # pl.add(cents,cents*0+w2)
    # pl.add(cents,rednoise(cents,wnoise,lknee=lknee_fit,alpha=alpha_fit),ls="--")
    # pl.add(cents,rednoise(cents,wnoise,lknee=lknee_guess,alpha=alpha_guess),ls="-.")
    # pl._ax.set_ylim(1e-1,1e4)
    # pl.done(os.environ['WORK']+"/fitnoise_pre.png")
    # sys.exit()

    return wnoise,lknee_fit,alpha_fit
예제 #14
0
def test_gas_fft():

    zs = np.array([0.6, 1.0])
    ks = np.geomspace(1e-4, 100, 100)
    ms = np.geomspace(1e7, 1e17, 2000)
    hcos = hmvec.HaloModel(zs, ks, ms, nfw_numeric=False)
    hcos.add_battaglia_profile("electron", family="AGN", xmax=50, nxs=30000)
    # hcos.add_nfw_profile("electron",numeric=False)

    pmm_1h = hcos.get_power_1halo(name="nfw")
    pmm_2h = hcos.get_power_2halo(name="nfw")

    pee_1h = hcos.get_power_1halo(name="electron")
    pee_2h = hcos.get_power_2halo(name="electron")

    pme_1h = hcos.get_power_1halo("nfw", "electron")
    pme_2h = hcos.get_power_2halo("nfw", "electron")

    pem_1h = hcos.get_power_1halo("electron", "nfw")
    pem_2h = hcos.get_power_2halo("electron", "nfw")

    # pl = io.Plotter(xyscale='loglog')
    # pl.add(ks,pee_1h[0]/pmm_1h[0])
    # pl._ax.set_xlim(0.1,100)
    # pl.done()

    # pl = io.Plotter(xyscale='loglog')
    # pl.add(ks,pmm_1h[0]+pmm_2h[0])
    # pl.add(ks,pee_1h[0]+pee_2h[0],ls='--')
    # pl.add(ks,pme_1h[0]+pme_2h[0],ls='-.')
    # pl.add(ks,pem_1h[0]+pem_2h[0],ls='-')
    # pl.done()

    omtoth2 = hcos.p['omch2'] + hcos.p['ombh2']
    fc = hcos.p['omch2'] / omtoth2
    fb = hcos.p['ombh2'] / omtoth2

    pl = io.Plotter(xyscale='loglin',
                    xlabel='$k \\mathrm{Mpc}^{-1}$',
                    ylabel='$P_{mm}^{\\rm{fb}}/P_{mm}^{\\rm{no-fb}}$')
    for i in range(zs.size):
        Pnn = pmm_1h[i] + pmm_2h[i]
        Pee = pee_1h[i] + pee_2h[i]
        Pne = pme_1h[i] + pme_2h[i]
        Pmm = fc**2. * Pnn + 2. * fc * fb * Pne + fb * fb * Pee
        pl.add(ks, Pmm / Pnn)
    pl.hline(y=1)
    pl.done("feedback.pdf")
예제 #15
0
def test_pgm():

    import halomodel as mmhm
    from orphics import cosmology
    cc = cosmology.Cosmology(hmvec.default_params, skipCls=True, low_acc=False)
    mmhmod = mmhm.HaloModel(cc)

    mthresh = np.array([10.5])
    zs = np.array([0., 1., 2., 3.])
    ms = np.geomspace(1e8, 1e16, 1000)
    ks = np.geomspace(1e-4, 100, 1001)
    # ks,pks = np.loadtxt("mm_k_pk.txt",unpack=True)  # !!!

    eeP = mmhmod.P_gg_2h(ks, zs, mthreshHOD=mthresh) + mmhmod.P_gg_1h(
        ks, zs, mthreshHOD=mthresh)
    meP = mmhmod.P_mg_2h(ks, zs, mthreshHOD=mthresh) + mmhmod.P_mg_1h(
        ks, zs, mthreshHOD=mthresh)
    mmP = mmhmod.P_mm_2h(ks, zs) + mmhmod.P_mm_1h(ks, zs)

    hcos = hmvec.HaloModel(zs,
                           ks,
                           ms=ms,
                           halofit=None,
                           mdef='vir',
                           nfw_numeric=False)

    hcos.add_hod("g", mthresh=(10**mthresh[0]) + zs * 0., corr="max")
    # hcos.add_battaglia_profile("electron",family="AGN",xmax=100,nxs=60000)

    pme_1h = hcos.get_power_1halo(name="g", name2="nfw")
    pme_2h = hcos.get_power_2halo(name="g", name2="nfw")
    pmm_1h = hcos.get_power_1halo("nfw")
    pmm_2h = hcos.get_power_2halo("nfw")
    pee_1h = hcos.get_power_1halo("g")
    pee_2h = hcos.get_power_2halo("g")

    for i in range(zs.size):
        pl = io.Plotter(xyscale='loglin', xlabel='$k$', ylabel='$P$')
        pl.add(ks, (pme_2h[i] + pme_1h[i]) / meP[i], ls="--", color="C%d" % i)
        pl.add(ks, (pmm_2h[i] + pmm_1h[i]) / mmP[i], ls="-", color="C%d" % i)
        pl.add(ks, (pee_2h[i] + pee_1h[i]) / eeP[i], ls=":", color="C%d" % i)
        pl.vline(x=10.)
        pl.hline(y=1.)
        pl._ax.set_ylim(0.8, 1.3)
        pl.done("pgcomp_rat_z_%d.png" % i)
예제 #16
0
def test_lensing_window():

    zs = np.geomspace(0.01, 10., 100)  #np.array([0.])
    ks = np.geomspace(1e-4, 10, 100)
    ms = np.geomspace(1e10, 1e17, 200)
    hcos = hmvec.HaloModel(zs, ks, ms, nfw_numeric=False)
    pmm_1h = hcos.get_power_1halo(name="nfw")
    pmm_2h = hcos.get_power_2halo(name="nfw")

    Wk = hcos.lensing_window(zs, zs=2.)
    sigz = 0.1
    dndz = np.exp(-(zs - 2.)**2. / 2. / sigz**2.)
    Wk2 = hcos.lensing_window(zs, zs, dndz)
    # print(Wk2)
    pl = io.Plotter(xyscale='loglin')
    pl.add(zs, Wk)
    pl.add(zs, Wk2, ls="--")
    pl.done()
예제 #17
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(xlabel='l', ylabel='D', yscale='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")
예제 #18
0
                  wcs,
                  feed_dict,
                  xmask=xmask,
                  ymask=ymask,
                  kmask=kmask,
                  Al=None,
                  estimator=estimator,
                  hardening=hardening)
N_l_bh = h.get_Nl()

bin_edges = np.arange(20, Lmax, 20)
ells = np.arange(20, Lmax, 1)
binner = stats.bin2D(modlmap, bin_edges)
clkk = theory.gCl('kk', ells)

#print(binner.bin(anull)[1])

cents, nl1d = binner.bin(N_l)
cents, nlbh1d = binner.bin(N_l_bh)
pl = io.Plotter('CL', xyscale='loglog')
pl.add(ells, clkk, color='k')
pl.add(cents, nl1d, ls='--')
pl.add(cents, nlbh1d, ls=':')
pl._ax.set_ylim(1e-8, 5e-4)
pl.done('bh.png')

pl = io.Plotter('rCL', xyscale='linlin')
pl.add(cents, nlbh1d / nl1d)
pl.hline(y=1)
pl.done('bhdiff.png')
예제 #19
0
print(bmap2.shape)

bmap = maps.filter_map(imap.copy(),kbeam)

taper,w2 = maps.get_taper(shape)

io.plot_img(imap*taper,io.dout_dir+"bmap0.png",high_res=True)
io.plot_img(bmap*taper,io.dout_dir+"bmap1.png",high_res=True)
io.plot_img(bmap2*taper,io.dout_dir+"bmap2.png",high_res=True)

bin_edges = np.arange(200,3000,100)
binner = stats.bin2D(modlmap,bin_edges)
fc = maps.FourierCalc(shape,wcs)
p2d,_,_ = fc.power2d(imap*taper)
cents,p1di = binner.bin(p2d/w2)
p2d,_,_ = fc.power2d(bmap*taper)
cents,p1db = binner.bin(p2d/w2)
p2d,_,_ = fc.power2d(bmap2*taper)
cents,p1db2 = binner.bin(p2d/w2)

pl = io.Plotter(yscale='log')
pl.add(ells,ps[0,0]*ells**2.)
pl.add(ells,ps[0,0]*ells**2.*maps.gauss_beam(ells,fwhm)**2.)
pl.add(cents,p1di*cents**2.)
pl.add(cents,p1db*cents**2.,label="fourier")
pl.add(cents,p1db2*cents**2.,label="real")
pl._ax.set_xlim(2,3000)
pl._ax.set_ylim(1e-12,1e-8)
pl.legend(loc='lower left')
pl.done(io.dout_dir+"beam.png")
예제 #20
0
    actmap = {
        "d56_01": "D56_1_149",
        "d56_02": "D56_2_149",
        "d56_03": "D56_3_149",
        "d56_04": "D56_4_149",
        "d56_05": "D56_5_097",
        "d56_06": "D56_6_149"
    }

    if comp == 'comptony':
        wstr = '$W (1/\mu K \\times 10^7)$'
    else:
        wstr = '$W$ (dimensionless)'

    #pl = io.Plotter(xyscale='loglin',xlabel='$\\ell$',ylabel=wstr,ftsize=16)
    pl = io.Plotter(xyscale='linlin', xlabel='$\\ell$', ylabel=wstr,
                    ftsize=16)  # !!!
    for i in range(len(qids)):
        col = cols[i]
        qid = qids[i]
        lmin, lmax, hybrid, radial, friend, cfreq, fgroup, wrfit = aspecs(qid)

        if tutils.is_lfi(qid):
            ls = "-."
            lab = "LFI %d GHz" % cfreq
        elif tutils.is_hfi(qid):
            ls = "--"
            lab = "HFI %d GHz" % cfreq
        else:
            ls = "-"
            aind = qid.split("_")[1]
            lab = actmap[qid]  #"ACT_%s %d GHz" % (aind,cfreq )
예제 #21
0
                    tcmb=None)

totres = fg.power_cibp(ells, nu, nu2=None) + fg.power_cibc(
    ells, nu, nu2=None) + fg.power_radps(
        ells, nu,
        nu2=None) + fg.power_ksz_reion(ells) + +fg.power_ksz_late(ells)


def resmodel(ells, a1, a2, e1, e2, ell0=3000):
    plaw = lambda a, e: a * (ells / ell0)**(e)
    return plaw(a1, e1) + plaw(a2, e2)


clres = resmodel(ells, 1e-5, 1e-5, 0.5, 1.0)

pl = io.Plotter(xyscale='linlog', scalefn=lambda x: x**2. / 2. / np.pi)
pl.add(ells, cltt, lw=3, color='k')
pl.add(ells, clyy)
#pl.add(ells,clres)
pl.add(ells, totres, ls='--')
pl.done()
"""

For each freq1,freq2:
res = ps - cmb - tsz(freq1,freq2)
Fit a1*ell**e1 + a2*ell**e2 to res
With 2000 < ell < 8000 for act x act
With 2000 < ell < 6000 for act x hfi
With 2000 < ell < 3000 for act x lfi
With 2000 < ell < 6000 for hfi x hfi
With 2000 < ell < 3000 for lfi x lfi
예제 #22
0
w2 = np.mean(mask**2)
dm = sints.PlanckHybrid(region=mask)

qids = "p01,p02,p03,p04,p05,p06,p07,p08".split(',')

narrays = len(qids)
cbin_edges = np.arange(20, 8000, 20)
cbinner = stats.bin2D(modlmap, cbin_edges)

fpath = "/scratch/r/rbond/msyriac/data/depot/actsims/fg_res/fgfit_deep56"

for i in range(narrays):
    for j in range(i, narrays):
        pl = io.Plotter(xyscale='linlog',
                        xlabel='l',
                        ylabel='D',
                        scalefn=lambda x: x**2.)

        qid1 = qids[i]
        qid2 = qids[j]
        array1 = sints.arrays(qid1, 'freq')
        array2 = sints.arrays(qid2, 'freq')

        splits1 = dm.get_splits([array1], ncomp=1, srcfree=True)[0, :, 0]
        wins1 = dm.get_splits_ivar([array1])[0, :, 0]

        splits2 = dm.get_splits([array2], ncomp=1, srcfree=True)[0, :, 0]
        wins2 = dm.get_splits_ivar([array2])[0, :, 0]

        fbeam1 = lambda x: tutils.get_kbeam(
            qid1, x, sanitize=True, planck_pixwin=True)
예제 #23
0
s.get_stats()
# totcmb = putils.allreduce(totcmb,comm) /nsims
#tottsz = putils.allreduce(tottsz,comm) /nsims
for key in sorted(totinputs.keys()):
    totinputs[key] = putils.allreduce(totinputs[key], comm) / nsims
for key in sorted(totautos.keys()):
    totautos[key] = putils.allreduce(totautos[key], comm) / nsims
for key in sorted(totcrosses.keys()):
    totcrosses[key] = putils.allreduce(totcrosses[key], comm) / nsims

if rank == 0:

    cents = binner.centers
    for input_name in input_names:
        pl = io.Plotter(xyscale='linlog',
                        scalefn=lambda x: x**2. / 2. / np.pi,
                        xlabel='$\\ell$',
                        ylabel='$D_{\\ell}$')
        # ii = totcmb if input_name=='CMB' else tottsz
        ii = totinputs[input_name]
        pl.add(cents, ii, color='k', lw=3)
        for i, solution in enumerate(args.solutions.split(',')):
            color = "C%d" % i
            iname = components[solution][0]
            if iname != input_name: continue
            ri = totcrosses[solution]
            pl.add(cents,
                   ri,
                   label=solution,
                   ls="none",
                   marker="o",
                   color=color,
예제 #24
0
from __future__ import print_function
from orphics import maps, io, cosmology
from enlib import enmap
import numpy as np
import os, sys

broot = lambda param: "output/BAO_highAcc_DESI2_szar_step_0.01_dfk_%s.csv" % param
broot2 = lambda param: "output/BAO_highAcc_DESI2_szar__dfk_%s.csv" % param

params = "H0,ombh2,omch2,tau,As,ns,mnu,w,wa".split(',')
zs = np.array([
    .15, .25, .35, .45, .55, .65, .75, .85, .95, 1.05, 1.15, 1.25, 1.35, 1.45,
    1.55, 1.65, 1.75, 1.85
])
for param in params:

    pl = io.Plotter()
    d = np.loadtxt(broot(param))
    d2 = np.loadtxt(broot2(param))
    pl.add(zs, d)
    pl.add(zs, d2, ls="--")
    pl.done(io.dout_dir + "dbao_%s.png" % param)
예제 #25
0
if rank==0:

    stack = mstats.stacks['recon']

    recon1d = mstats.stats['recon1d']['mean']
    recon1d_err = mstats.stats['recon1d']['errmean']
    recon1d_cov = mstats.stats['recon1d']['covmean']

    io.plot_img(stack,pout_dir+"stack.png")

    kappa_true = maps.filter_map(lensing.nfw_kappa(kamp_true*1e15,modrmap,cc,overdensity=200.,critical=True,atClusterZ=True),kmask)
    cents, ktrue1d = binner.bin(kappa_true)

    arcs,ks = np.loadtxt("input/hdv.csv",unpack=True,delimiter=",")
    
    pl = io.Plotter()
    pl.add(cents,ktrue1d,lw=2,color="k")
    pl.add(arcs,ks,lw=2,alpha=0.5)
    pl.add_err(cents,recon1d,recon1d_err,ls="--")
    pl.hline()
    pl.done(pout_dir+"recon1d.png")


    
    pl1 = io.Plotter(xlabel="$A$",ylabel="$\\mathrm{ln}\\mathcal{L}$")
    pl2 = io.Plotter(xlabel="$A$",ylabel="$\\mathcal{L}$")
    

    arcmaxes = [10.0] #[5.0,7.5,10.0,15.0,20.0,30.0]
    for j,arcmax in enumerate(arcmaxes):
예제 #26
0
        beam1 = tutils.get_kbeam(qid1,cents,sanitize=False,planck_pixwin=True)
        beam2 = tutils.get_kbeam(qid2,cents,sanitize=False,planck_pixwin=True)

        kc1 = "/scratch/r/rbond/msyriac/data/depot/tilec/test_v1.1.0_rc_deep56/kcoadd_%s.npy" % qid1
        kc2 = "/scratch/r/rbond/msyriac/data/depot/tilec/test_v1.1.0_rc_deep56/kcoadd_%s.npy" % qid2
        p2d = np.real(np.load(kc1)*np.load(kc2).conj())/w2
        cents,pow1d = binner.bin(p2d)

        p2d = np.load("/scratch/r/rbond/msyriac/data/depot/tilec/test_v1.1.0_rc_deep56/tilec_hybrid_covariance_%s_%s.npy" % (qid1,qid2))
        cents,cov1d = binner.bin(p2d)
        

        # fbeam1 = tutils.get_kbeam(qid1,ells,sanitize=False,planck_pixwin=True)
        # fbeam2 = tutils.get_kbeam(qid2,ells,sanitize=False,planck_pixwin=True)

        pl = io.Plotter(xyscale='loglog',scalefn = lambda x: x**2./2./np.pi,xlabel='l',ylabel='D')
        pl.add(cents,up1d/beam1/beam2,label='unsmoothed S')
        pl.add(cents,sp1d/beam1/beam2,label='smoothed S')
        pl.add(cents,np1d/beam1/beam2,label='smoothed N')
        pl.add(cents,pow1d/beam1/beam2,label='S+N power')
        pl.add(cents,cov1d/beam1/beam2,label='smoothed S+N')
        if qid1[0]=='p' and qid2[0]=='p':
            cfit = ctheory.get_theory_cls(f1,f2)
            pl.add(cents,cfit,ls='--')
            cfit = ctheory.get_theory_cls(f1,f2,a_gal=0.8)
            pl.add(cents,cfit,ls=':')

        # lmin,lmax,hybrid,radial,friend,f1,fgroup,wrfit = tutils.get_specs(qid1)
        # lmin,lmax,hybrid,radial,friend,f2,fgroup,wrfit = tutils.get_specs(qid2)
        # beam1 = tutils.get_kbeam(qid1,cents,sanitize=False,planck_pixwin=True)
        # beam2 = tutils.get_kbeam(qid2,cents,sanitize=False,planck_pixwin=True)
예제 #27
0
import hmvec
import numpy as np
from orphics import io

halofits = [
    'takahashi', 'original', 'bird', 'peacock', 'mead', 'casarini', 'mead2015'
]
zs = np.array([0., 1., 2., 3.])
ks = np.geomspace(1e-4, 20., 1000)
pks = {}
for halofit in halofits:
    print(halofit)
    hc = hmvec.HaloCosmology(zs, ks, halofit=halofit)
    pks[halofit] = hc.nPzk

for i, z in enumerate(zs):
    pl = io.Plotter(xyscale='loglin', xlabel='$k$', ylabel='$P/P_0$')
    for halofit in halofits[1:]:
        pl.add(ks, pks[halofit][i] / pks[halofits[0]][i], label=halofit)
    pl.hline(y=1)
    pl.legend(loc='upper left')
    pl._ax.set_ylim(0.7, 1.3)
    pl.done("halofit_comp_z_%d.png" % i)
예제 #28
0
    mf_alm = hp.read_alm(f'{solenspipe.opath}/mf_{args.label}_{args.polcomb}_{isostr}_alm.fits')
else:
    mf_alm = 0


for task in my_tasks:

    # Choose a seed. This has to be varied when simulating.
    seed = (0,0,task+sindex)

    # If debugging, get unfiltered maps and plot Cls
    if task==0 and debug_cmb:
        t_alm,e_alm,b_alm = solint.get_kmap(channel,seed,lmin,lmax,filtered=False)
        tcl = hp.alm2cl(t_alm)
        ls = np.arange(tcl.size)
        pl = io.Plotter('Cell')
        pl.add(ls,tcl/w2)
        ls2,nells,nells_P = solint.get_noise_power(channel,beam_deconv=True)
        theory = cosmology.default_theory()
        pl.add(ls,theory.lCl('TT',ls) + maps.interp(ls2,nells)(ls),color='k')
        pl._ax.set_xlim(1,6000)
        pl._ax.set_ylim(1e-6,1e3)
        pl.done(f'{solenspipe.opath}/tcl.png')
        imap = enmap.downgrade(solint.alm2map(np.asarray([t_alm,e_alm,b_alm]),ncomp=3) * maps.binary_mask(mask),2)
        for i in range(3): io.hplot(imap[i],f'{solenspipe.opath}/imap_{i}',mask=0)


    with bench.show("sim"):
        # Get simulated, prepared filtered T, E, B maps, i.e. (1/(C+N) * teb_alm)
        t_alm,e_alm,b_alm = solint.get_kmap(channel,seed,lmin,lmax,filtered=True)
        # Get the reconstructed kappa map alms and filter it with the normalization
예제 #29
0
arraynames = {'p01':'030','p02':'044','p03':'070'}

dm = sints.PlanckHybrid(region=mask)
for qid in qids:


    split = enmap.read_map("%ssplit_%s.fits" % (froot,qid))
    #io.hplot(enmap.downgrade(split,4),"split_%s" % qid)

    arrayname = arraynames[qid]
    wts = dm.get_splits_ivar(arrayname)[0,:,0,...]

    coadd,_ = noise.get_coadd(split[:,0,...],wts,axis=0) * mask

    pl = io.Plotter(xyscale='linlog',xlabel='l',ylabel='C')

    kmap = enmap.fft(coadd,normalize='phys')
    p2d = np.real(kmap*kmap.conj())/w2
    cents,p1d = binner.bin(p2d)
    pl.add(cents,p1d,label='sim power')
    
    kcoadd = enmap.enmap(np.load("%skcoadd_%s.npy" % (kroot,qid)),wcs)
    p2d = np.real(kcoadd*kcoadd.conj())/w2
    cents,p1d = binner.bin(p2d)
    pl.add(cents,p1d,label='sim power 2')


    p2d = enmap.enmap(np.load("%stilec_hybrid_covariance_%s_%s.npy" % (kroot,qid,qid)),wcs)
    cents,p1d = binner.bin(p2d)
    pl.add(cents,p1d,label='sim cov')
예제 #30
0
sn[sn>1e30] = 1e30
#print(sn.min(),sn.max())
#io.plot_img(np.log10(np.fft.fftshift(sn)))


tt = binner.bin(agen.ps_cmb)[1]

lss,snls = np.loadtxt("/home/msyriac/repos/halofg/data/smica_nls.txt",unpack=True)
lsl,lnls = np.loadtxt("/home/msyriac/repos/halofg/data/lgmca_nls.txt",unpack=True)
snls = snls[lss<3000]
lss = lss[lss<3000]
lnls = lnls[lsl<3000]
lsl = lsl[lsl<3000]


pl = io.Plotter(yscale='log',xlabel='l',ylabel='D')
pl.add(cents,cmb*cents**2.,lw=2,color='k')
pl.add_err(cents,scxcmb*cents**2.,yerr=escxcmb*cents**2,lw=1,label="ilc",marker="o",color="C0")
pl.add_err(cents,ccxcmb*cents**2.,yerr=eccxcmb*cents**2,lw=1,label="cilc",marker="o",color="C1")
pl.add(cents,sc*cents**2.,lw=1,ls="--",color="C0")
pl.add(cents,cc*cents**2.,lw=1,ls="--",color="C1")
pl.add(cents,(sc_noise-tt)*cents**2.,lw=1,ls="-.",color="C0")
pl.add(cents,(cc_noise-tt)*cents**2.,lw=1,ls="-.",color="C1")
pl.add(lss,(snls)*lss**2./maps.gauss_beam(lss,5.)**2.,lw=1,ls="-.",color="C2",label='smica',alpha=0.5)
pl.add(lsl,(lnls)*lsl**2./maps.gauss_beam(lss,5.)**2.,lw=1,ls="-.",color="C3",label='lgmca',alpha=0.5)
pl._ax.set_ylim(1e1,3e4)
pl.legend(loc='lower center')
pl.done(save_root+"cmb.png")


pl = io.Plotter(yscale='log',xlabel='l',ylabel='D')