def get_box_resids(i):
    cosmo, h, Omega_m = get_cosmo(i)
    M = np.logspace(12, 16, num=200)  #Msun/h
    k = np.logspace(-5, 1, num=1000)  #Mpc^-1
    bfpath = "bf_%s_box%d.txt" % (name, i)
    print i, name
    params = np.loadtxt(bfpath)
    zb = np.array([])
    Mb = np.array([])
    nub = np.array([])
    R = np.array([])
    Re = np.array([])
    for j in range(0, 10):  #snap
        Mlo, Mhi, N, Mtot = AD.building_box_binned_mass_function(i, j).T
        Mj = Mtot / N
        Mb = np.concatenate((Mb, Mj))
        zb = np.concatenate((zb, np.ones_like(N) * zs[j]))
        edge = 10**np.concatenate((Mlo, Mhi[-1:]))
        cov = AD.building_box_binned_mass_function_covariance(i, j)
        icov = np.linalg.inv(cov)
        err = np.sqrt(np.diag(cov))
        p = np.array([cosmo.pk_lin(ki, zs[j]) for ki in k]) * h**3
        nub = np.concatenate((nub, bias.nu_at_M(Mj, k / h, p, Omega_m)))
        d, e, f, g = model_swap(params, name, x[j])
        dndM = massfunction.dndM_at_M(M, k / h, p, Omega_m, d, e, f, g)
        Nmodel = massfunction.n_in_bins(edge, M, dndM) * volume
        R = np.concatenate((R, (Nmodel - N) / Nmodel))
        Re = np.concatenate((Re, err / Nmodel))
    return Mb, nub, zb, R, Re
Exemple #2
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)
def test_mf_binned():
    M2 = np.logspace(12, 16, num=100)
    dn = mf.dndM_at_M(M2, k / h, p, Omega_m)
    edges = np.logspace(12, 16, 11)
    n = mf.n_in_bins(edges, M2, dn)
    npt.assert_array_less(n[1:], n[:-1])
    n2 = np.array([
        mf.n_in_bin(edges[i], edges[i + 1], M2, dn)
        for i in range(len(edges) - 1)
    ])
    npt.assert_array_less(n2[1:], n2[:-1])
    npt.assert_array_equal(n, n2)
Exemple #4
0
def mass_func(pars, args):
    x = args['x']
    Omega_m = args['Omega_m']
    M = args['M']
    k = args['k']
    ps = args['ps']
    edges = args['edges']  #Msun/h
    Nout = []
    for i in range(len(x)):
        d, e, f, g = model_swap(pars, args['name'], x[i])
        dndM = massfunction.dndM_at_M(M, k, ps[i], Omega_m, d, e, f, g)
        Nout.append(massfunction.n_in_bins(edges[i], M, dndM) * volume)
    return Nout
def test_dndM_M():
    n = mf.dndM_at_M(M, k / h, p, Omega_m) * M
    npt.assert_array_less(n[1:], n[:-1])
    """
def test_dndM():
    n = mf.dndM_at_M(M, k / h, p, Omega_m) * M
    k2 = k / h
    n2 = np.array([mf.dndM_at_M(Mi, k2, p, Omega_m) for Mi in M]) * M
    npt.assert_array_equal(n, n2)