示例#1
0
def check_halomod(cosmo):
    """
    Check that halo model functions can be run.
    """

    # Time variables
    z = 0.
    z_array = np.linspace(0., 2., 10)
    a = 1.
    a_array = 1. / (1. + z_array)

    # Halo definition
    odelta = 200.

    # Mass variables
    mass_scalar = 1e13
    mass_list = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16]
    mass_array = np.array([1e11, 1e12, 1e13, 1e14, 1e15, 1e16])

    # Wave-vector variables
    k_scalar = 1.
    k_list = [1e-3, 1e-2, 1e-1, 1e0, 1e1]
    k_array = np.array([1e-3, 1e-2, 1e-1, 1e0, 1e1])

    # halo concentration
    assert_(all_finite(ccl.halo_concentration(cosmo, mass_scalar, a, odelta)))
    assert_(all_finite(ccl.halo_concentration(cosmo, mass_list, a, odelta)))
    assert_(all_finite(ccl.halo_concentration(cosmo, mass_array, a, odelta)))

    assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_scalar,
                  a_array, odelta)
    assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_list, a_array,
                  odelta)
    assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_array,
                  a_array, odelta)

    # halo model
    assert_(all_finite(ccl.halomodel_matter_power(cosmo, k_scalar, a)))
    assert_(all_finite(ccl.halomodel_matter_power(cosmo, k_list, a)))
    assert_(all_finite(ccl.halomodel_matter_power(cosmo, k_array, a)))

    assert_(all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_scalar, a)))
    assert_(all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_list, a)))
    assert_(all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_array, a)))

    assert_(all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_scalar, a)))
    assert_(all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_list, a)))
    assert_(all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_array, a)))

    assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_scalar,
                  a_array)
    assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_list,
                  a_array)
    assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_array,
                  a_array)
示例#2
0
def test_halomodel_power_consistent():
    a = 0.8
    k = np.logspace(-1, 1, 10)
    tot = ccl.halomodel_matter_power(COSMO, k, a)
    one = ccl.onehalo_matter_power(COSMO, k, a)
    two = ccl.twohalo_matter_power(COSMO, k, a)

    assert np.allclose(one + two, tot)
示例#3
0
def test_halomod(model):
    Omega_c = [0.2500, 0.2265, 0.2685]
    Omega_b = [0.0500, 0.0455, 0.0490]
    h = [0.7000, 0.7040, 0.6711]
    sigma8 = [0.8000, 0.8100, 0.8340]
    n_s = [0.9600, 0.9670, 0.9624]

    cosmo = ccl.Cosmology(Omega_c=Omega_c[model],
                          Omega_b=Omega_b[model],
                          h=h[model],
                          sigma8=sigma8[model],
                          n_s=n_s[model],
                          Neff=0,
                          m_nu=0,
                          Omega_k=0,
                          transfer_function='eisenstein_hu',
                          matter_power_spectrum='linear',
                          mass_function='shethtormen',
                          halo_concentration='duffy2008')

    data_z0 = np.loadtxt("./benchmarks/data/pk_hm_c%d_z0.txt" % (model + 1))
    data_z1 = np.loadtxt("./benchmarks/data/pk_hm_c%d_z1.txt" % (model + 1))

    k = data_z0[:, 0] * cosmo['h']
    pk = data_z0[:, -1] / (cosmo['h']**3)
    pk_ccl = ccl.halomodel_matter_power(cosmo, k, 1)
    tol = pk * HALOMOD_TOLERANCE
    err = np.abs(pk_ccl - pk)
    assert np.all(err <= tol)

    k = data_z1[:, 0] * cosmo['h']
    pk = data_z1[:, -1] / (cosmo['h']**3)
    pk_ccl = ccl.halomodel_matter_power(cosmo, k, 0.5)
    tol = pk * HALOMOD_TOLERANCE
    err = np.abs(pk_ccl - pk)
    assert np.all(err <= tol)
示例#4
0
    def __init__(self,
                 cosmo,
                 k_range=[1E-1, 5],
                 nlk=20,
                 z_range=[0., 1.],
                 nz=16):

        lkarr = np.linspace(np.log10(k_range[0]), np.log10(k_range[1]), nlk)
        karr = 10.**lkarr
        zarr = np.linspace(z_range[0], z_range[1], nz)

        pk_hm = np.array([
            ccl.halomodel_matter_power(cosmo, karr, a) for a in 1. / (1 + zarr)
        ])
        pk_hf = np.array(
            [ccl.nonlin_matter_power(cosmo, karr, a) for a in 1. / (1 + zarr)])
        ratio = pk_hf / pk_hm

        self.rk_func = interpolate.interp2d(lkarr,
                                            zarr,
                                            ratio,
                                            bounds_error=False,
                                            fill_value=1)