Esempio n. 1
0
def compare_class_distances(z,
                            chi_bench,
                            dm_bench,
                            Neff=3.0,
                            m_nu=0.0,
                            Omega_k=0.0,
                            w0=-1.0,
                            wa=0.0):
    """
    Compare distances calculated by pyccl with the distances in the CLASS
    benchmark file.
    """
    cosmo = ccl.Cosmology(Omega_c=Omega_c,
                          Omega_b=Omega_b,
                          Neff=Neff,
                          h=h,
                          A_s=A_s,
                          n_s=n_s,
                          Omega_k=Omega_k,
                          m_nu=m_nu,
                          w0=w0,
                          wa=wa)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a)
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, rtol=DISTANCES_TOLERANCE_CLASS)

    # Compare distance moudli where a!=1
    a_not_one = a != 1
    dm = ccl.distance_modulus(cosmo, a[a_not_one])
    assert_allclose(dm, dm_bench[a_not_one], rtol=DISTANCES_TOLERANCE_CLASS)
Esempio n. 2
0
def compare_distances_mnu_hiz(z, chi_bench, dm_bench, Omega_v, w0, wa,
                              Neff_mnu, mnu):
    """
    Compare distances calculated by pyccl with the distances in the benchmark
    file.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v

    cosmo = ccl.Cosmology(Omega_c=Omega_c,
                          Omega_b=Omega_b,
                          Neff=Neff,
                          h=h,
                          A_s=A_s,
                          n_s=n_s,
                          Omega_k=Omega_k,
                          w0=w0,
                          wa=wa,
                          m_nu=mnu)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a)
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE_MNU)

    # compare distance moudli where a!=1
    a_not_one = (a != 1).nonzero()
    dm = ccl.distance_modulus(cosmo, a[a_not_one])

    assert_allclose(dm,
                    dm_bench[a_not_one],
                    atol=1e-3,
                    rtol=DISTANCES_TOLERANCE_MNU)
Esempio n. 3
0
def compare_distances(z, chi_bench, dm_bench, Omega_v, w0, wa):
    """
    Compare distances calculated by pyccl with the distances in the benchmark
    file.
    This test is only valid when radiation is explicitly set to 0.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v

    cosmo = ccl.Cosmology(Omega_c=Omega_c,
                          Omega_b=Omega_b,
                          Neff=Neff,
                          h=h,
                          A_s=A_s,
                          n_s=n_s,
                          Omega_k=Omega_k,
                          w0=w0,
                          wa=wa,
                          Omega_g=0)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a) * h
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE)

    # compare distance moudli where a!=1
    a_not_one = (a != 1).nonzero()
    dm = ccl.distance_modulus(cosmo, a[a_not_one])

    assert_allclose(dm,
                    dm_bench[a_not_one],
                    atol=1e-3,
                    rtol=DISTANCES_TOLERANCE * 10)
Esempio n. 4
0
def compare_distances_muSig(z, chi_bench, dm_bench, Omega_v, w0, wa):
    """
    Compare distances calculated by pyccl with the distances in the benchmark
    file, for a ccl cosmology with mu / Sigma parameterisation of gravity.
    Nonzero mu / Sigma should NOT affect distances so we compare to the same
    benchmarks as the mu = Sigma = 0 case deliberately.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v

    # Create new Parameters and Cosmology objects
    cosmo = ccl.Cosmology(
        Omega_c=Omega_c, Omega_b=Omega_b, Neff=Neff,
        h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k,
        w0=w0, wa=wa, mu_0=mu_0, sigma_0=sigma_0, Omega_g=0.)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a) * h
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE)

    # compare distance moudli where a!=1
    a_not_one = (a != 1).nonzero()
    dm = ccl.distance_modulus(cosmo, a[a_not_one])

    assert_allclose(
        dm, dm_bench[a_not_one], atol=1e-3, rtol=DISTANCES_TOLERANCE*10)
Esempio n. 5
0
    def distanceModulus(self, z):
        """Compute the distance modulus as a function of redshift

        Parameters
        ----------
        z : array
            redshifts to compute distance modulus at

        Returns
        -------
        distance_modulus : array
            distance modulus at input redshifts

        """

        distance_modulus = ccl.distance_modulus(self._cosmo, 1 / (1. + z))
        return distance_modulus
# 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)