Пример #1
0
def check_background(cosmo):
    """
    Check that background and growth functions can be run.
    """
    # Types of scale factor input (scalar, list, array)
    a_scl = 0.5
    a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
    a_arr = np.linspace(0.2, 1., 5)
    
    # growth_factor
    assert_( all_finite(ccl.growth_factor(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_factor(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_factor(cosmo, a_arr)) )
    
    # growth_factor_unnorm
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_arr)) )
    
    # growth_rate
    assert_( all_finite(ccl.growth_rate(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_rate(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_rate(cosmo, a_arr)) )
    
    # comoving_radial_distance
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_scl)) )
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_lst)) )
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_arr)) )
    
    # h_over_h0
    assert_( all_finite(ccl.h_over_h0(cosmo, a_scl)) )
    assert_( all_finite(ccl.h_over_h0(cosmo, a_lst)) )
    assert_( all_finite(ccl.h_over_h0(cosmo, a_arr)) )
    
    # luminosity_distance
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_scl)) )
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_lst)) )
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_arr)) )
    
    # scale_factor_of_chi
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)) )
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)) )
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)) )
    
    # omega_m_a
    assert_( all_finite(ccl.omega_x(cosmo, a_scl, 'matter')) )
    assert_( all_finite(ccl.omega_x(cosmo, a_lst, 'matter')) )
    assert_( all_finite(ccl.omega_x(cosmo, a_arr, 'matter')) )
Пример #2
0
def Tspin(z, OmegaH, OmegaM):
    ## Formula from Tzu-Ching, in mK, arXiv:0709.3672
    return 0.3 * (OmegaH / 1e-3) * np.sqrt(
        (1 + z) / (2.5) * 0.29 / (OmegaM + (1. - OmegaM) / (1 + z)**3))


# first let's compute background values at our zs
for name, zs in [("zlow", zlow)]:  #,("zhigh",zhigh)]:
    f = open("background_%s.dat" % (name), 'w')
    f.write(
        "# z distance(z)[Mpc] growth(z)[normalised at z=0] f(z)=dlng/dlna Tspin(z) [mK]  b(z) N(z) [Mpc^3] \n"
    )
    for z in zs:
        print z
        afact = 1. / (1 + z)
        dist = ccl.luminosity_distance(cosmo, afact)  # this is what class has
        gf = ccl.growth_factor(cosmo, afact)
        gr = ccl.growth_rate(cosmo, afact)
        print z, gr
        if z < 10:
            Ts = Tspin(z, OmegaH, OmegaC)
            bias = castorinaBias(z)
            Pn = castorinaPn(z) / h**3  # converting from Mpc/h^3 to Mpc^3
        else:
            Ts = pritchardTSpin(z)
            bias = 1.0
            Pn = 0.0
        f.write("%3.2f %g %g %g %g %g %g  \n" %
                (z, dist, gf, gr, Ts, bias, Pn))
    f.close()
# next write power spectrum
Пример #3
0
def compare_with_ccl():
    """
    Compare some results with CCL to check for accuracy.
    """
    # Set-up CCL
    import pyccl as ccl
    p = default_params
    OmegaB = 0.045
    cosmo1 = ccl.Cosmology(Omega_c=p['omegaM'] - OmegaB,
                           Omega_b=OmegaB,
                           h=p['h'],
                           Omega_k=0.,
                           w0=-1.,
                           wa=0.,
                           A_s=2.1e-9,
                           n_s=0.96)
    cosmo2 = ccl.Cosmology(Omega_c=p['omegaM'] - OmegaB,
                           Omega_b=OmegaB,
                           h=p['h'],
                           Omega_k=0.02,
                           w0=-1.,
                           wa=0.,
                           A_s=2.1e-9,
                           n_s=0.96)
    cosmo3 = ccl.Cosmology(Omega_c=p['omegaM'] - OmegaB,
                           Omega_b=OmegaB,
                           h=p['h'],
                           Omega_k=0.02,
                           w0=-0.8,
                           wa=0.,
                           A_s=2.1e-9,
                           n_s=0.96,
                           m_nu=0.)

    # Set z_eq to include massless neutrinos
    p['z_eq'] = p['omegaM'] \
              / (cosmo1.params['Omega_g'] + cosmo1.params['Omega_n_rel']) - 1.
    print(p['z_eq'])

    # Expansion rate
    a = np.logspace(-3., 0., 400)
    ccl_H1 = (100. * p['h']) * ccl.h_over_h0(cosmo1, a)
    ccl_H2 = (100. * p['h']) * ccl.h_over_h0(cosmo2, a)
    ccl_H3 = (100. * p['h']) * ccl.h_over_h0(cosmo3, a)

    this_H1 = Hz(a, pdict(w0=-1., winf=-1., omegaK=0., zc=2., deltaz=0.5))
    this_H2 = Hz(a, pdict(w0=-1., winf=-1., omegaK=0.02, zc=2., deltaz=0.5))
    this_H3 = Hz(a, pdict(w0=-0.8, winf=-0.8, omegaK=0.02, zc=2., deltaz=0.5))

    # Angular diameter distance
    ccl_DA1 = ccl.luminosity_distance(cosmo1, a) * a**2.
    ccl_DA2 = ccl.luminosity_distance(cosmo2, a) * a**2.
    ccl_DA3 = ccl.luminosity_distance(cosmo3, a) * a**2.

    this_DA1 = DAz(a, pdict(w0=-1., winf=-1., omegaK=0., zc=2., deltaz=0.5))
    this_DA2 = DAz(a, pdict(w0=-1., winf=-1., omegaK=0.02, zc=2., deltaz=0.5))
    this_DA3 = DAz(a, pdict(w0=-0.8, winf=-0.8, omegaK=0.02, zc=2.,
                            deltaz=0.5))

    # Plot comparisons
    P.subplot(121)
    P.plot(a, this_H1 / ccl_H1 - 1., 'k-', lw=1.8)
    P.plot(a, this_H2 / ccl_H2 - 1., 'r-', lw=1.8)
    P.plot(a, this_H3 / ccl_H3 - 1., 'b-', lw=1.8)
    P.xscale('log')

    P.subplot(122)
    P.plot(a, this_DA1 / ccl_DA1 - 1., 'k-', lw=1.8)
    P.plot(a, this_DA2 / ccl_DA2 - 1., 'r-', lw=1.8)
    P.plot(a, this_DA3 / ccl_DA3 - 1., 'b-', lw=1.8)
    P.xscale('log')

    P.tight_layout()
    P.show()
                              bcm_log10Mc=14.079181246047625, bcm_etab=0.5, bcm_ks=55.0)

# Cosmology where the power spectrum will be computed with an emulator.
cosmo_emu = ccl.Cosmology(Omega_c=0.27, Omega_b=0.05, h=0.67, sigma8=0.83, n_s=0.96, 
                          Neff=3.04, Omega_k=0., transfer_function='emulator', 
                          matter_power_spectrum="emu")

# background quantities
z = np.linspace(0.0001, 5., 100)
a = 1. / (1.+z)


# Compute distances
chi_rad = ccl.comoving_radial_distance(cosmo, a) 
chi_ang = ccl.comoving_angular_distance(cosmo,a)
lum_dist = ccl.luminosity_distance(cosmo, a)
dist_mod = ccl.distance_modulus(cosmo, a)


# Plot the comoving radial distance as a function of redshift, as an example.
plt.figure()
plt.plot(z, chi_rad, 'k', linewidth=2)
plt.xlabel('$z$', fontsize=20)
plt.ylabel('Comoving distance, Mpc', fontsize=15)
plt.tick_params(labelsize=13)
# plt.show()
plt.close()

# Compute growth quantities :
D = ccl.growth_factor(cosmo, a)
f = ccl.growth_rate(cosmo, a)