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')) )
def compare_growth(z, gfac_bench, Omega_v, w0, wa): """ Compare growth factor calculated by pyccl with the values in the benchmark file. This test only works if radiation is explicitly set to 0. """ # Set Omega_K in a consistent way Omega_k = 1.0 - Omega_c - Omega_b - Omega_v # Create new Parameters and Cosmology objects p = ccl.Parameters(Omega_c=Omega_c, Omega_b=Omega_b, Neff=Neff, m_nu=m_nu, h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k, w0=w0, wa=wa) p.parameters.Omega_g = 0. # Hack to set to same value used for benchmarks cosmo = ccl.Cosmology(p) # Calculate distance using pyccl a = 1. / (1. + z) gfac = ccl.growth_factor_unnorm(cosmo, a) # Compare to benchmark data assert_allclose(gfac, gfac_bench, atol=1e-12, rtol=GROWTH_TOLERANCE)
def compare_growth(z, gfac_bench, Omega_v, w0, wa, mu_0, sigma_0, high_tol=False): """ Compare growth factor calculated by pyccl with the values in the benchmark file. This test only works if 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, m_nu=m_nu, h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k, Omega_g=0, w0=w0, wa=wa, mu_0=mu_0, sigma_0=sigma_0) # Calculate distance using pyccl a = 1. / (1. + z) gfac = ccl.growth_factor_unnorm(cosmo, a) # Compare to benchmark data if high_tol: assert_allclose(gfac, gfac_bench, atol=1e-12, rtol=GROWTH_HIZ_TOLERANCE) else: assert_allclose(gfac, gfac_bench, atol=1e-12, rtol=GROWTH_TOLERANCE)
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 is_comoving = 0 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))) # comoving_angular_distance assert_(all_finite(ccl.comoving_angular_distance(cosmo, a_scl))) assert_(all_finite(ccl.comoving_angular_distance(cosmo, a_lst))) assert_(all_finite(ccl.comoving_angular_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'))) # Fractional density of different types of fluid assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'dark_energy'))) assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'radiation'))) assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'curvature'))) assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'neutrinos_rel'))) assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'neutrinos_massive'))) # Check that omega_x fails if invalid component type is passed assert_raises(ValueError, ccl.omega_x, cosmo, a_scl, 'xyz') # rho_crit_a assert_(all_finite(ccl.rho_x(cosmo, a_scl, 'critical', is_comoving))) assert_(all_finite(ccl.rho_x(cosmo, a_lst, 'critical', is_comoving))) assert_(all_finite(ccl.rho_x(cosmo, a_arr, 'critical', is_comoving))) # rho_m_a assert_(all_finite(ccl.rho_x(cosmo, a_scl, 'matter', is_comoving))) assert_(all_finite(ccl.rho_x(cosmo, a_lst, 'matter', is_comoving))) assert_(all_finite(ccl.rho_x(cosmo, a_arr, 'matter', is_comoving)))