def check_neutrinos(): """ Check that neutrino-related functions can be run. """ z = 0. z_arr = np.linspace(0., 2., 10) a = 1. a_arr = 1. / (1. + z_arr) a_lst = [_a for _a in a_arr] T_CMB = 2.725 N_nu_mass = 3 mnu = [0.02, 0.02, 0.02] # Omeganuh2 assert_(all_finite(ccl.Omeganuh2(a, mnu, T_CMB))) assert_(all_finite(ccl.Omeganuh2(a_lst, mnu, T_CMB))) assert_(all_finite(ccl.Omeganuh2(a_arr, mnu, T_CMB))) OmNuh2 = 0.01 # Omeganuh2_to_Mnu assert_(all_finite(ccl.nu_masses(OmNuh2, 'normal', T_CMB))) assert_(all_finite(ccl.nu_masses(OmNuh2, 'inverted', T_CMB))) assert_(all_finite(ccl.nu_masses(OmNuh2, 'equal', T_CMB))) assert_(all_finite(ccl.nu_masses(OmNuh2, 'sum', T_CMB))) # Check that the right exceptions are raised assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96, m_nu=[0.1, 0.2, 0.3, 0.4]) assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96, m_nu=[0.1, 0.2, 0.3], mnu_type="sum") assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96, m_nu=42)
def test_emu_nu(model): model_numbers = [38, 39, 40, 42] data = np.loadtxt("./benchmarks/data/emu_nu_smooth_pk_M%d.txt" % model_numbers[model]) cosmos = np.loadtxt("./benchmarks/data/emu_nu_cosmologies.txt") mnu = ccl.nu_masses(cosmos[model, 7] * cosmos[model, 2]**2, 'equal', T_CMB=2.725) cosmo = ccl.Cosmology( Omega_c=cosmos[model, 0], Omega_b=cosmos[model, 1], h=cosmos[model, 2], sigma8=cosmos[model, 3], n_s=cosmos[model, 4], w0=cosmos[model, 5], wa=cosmos[model, 6], m_nu=mnu, m_nu_type='list', Neff=3.04, Omega_g=0, Omega_k=0, transfer_function='boltzmann_class', matter_power_spectrum='emu', ) a = 1 k = data[:, 0] pk = ccl.nonlin_matter_power(cosmo, k, a) err = np.abs(pk / data[:, 1] - 1) assert np.allclose(err, 0, rtol=0, atol=EMU_TOLERANCE)
def test_nu_masses_smoke(split): m = ccl.nu_masses(0.1, split) if split == 'sum': assert np.ndim(m) == 0 else: assert np.ndim(m) == 1 assert np.shape(m) == (3, )
def test_nu_masses_smoke(split): m = ccl.nu_masses(0.1, split) if split in ['sum', 'single']: assert np.ndim(m) == 0 else: assert np.ndim(m) == 1 assert np.shape(m) == (3,)
def test_emu_lin(model): cosmos = np.loadtxt("./benchmarks/data/emu_input_cosmologies.txt") mnu = ccl.nu_masses(cosmos[model, 7] * cosmos[model, 2]**2, 'equal', T_CMB=2.725) cosmo = ccl.Cosmology( Omega_c=cosmos[model, 0], Omega_b=cosmos[model, 1], h=cosmos[model, 2], sigma8=cosmos[model, 3], n_s=cosmos[model, 4], w0=cosmos[model, 5], wa=cosmos[model, 6], m_nu=mnu, m_nu_type='list', Neff=3.04, Omega_g=0, Omega_k=0, transfer_function='boltzmann_camb', matter_power_spectrum='emu', ) a = 1 k = np.logspace(-3, -2, 50) # Catch warning about neutrino linear growth if (np.sum(mnu) > 0): pk = ccl.pyutils.assert_warns(ccl.CCLWarning, ccl.nonlin_matter_power, cosmo, k, a) else: pk = ccl.nonlin_matter_power(cosmo, k, a) # Catch warning about linear matter power pk_lin = ccl.pyutils.assert_warns(ccl.CCLWarning, ccl.linear_matter_power, cosmo, k, a) err = np.abs(pk / pk_lin - 1) assert np.allclose(err, 0, rtol=0, atol=EMU_TOLERANCE)
def test_nu_mass_consistency(a, split): m = ccl.nu_masses(0.1, split) assert np.allclose(ccl.Omeganuh2(a, m), 0.1, rtol=0, atol=1e-4)
def test_neutrinos_raises(): with pytest.raises(ValueError): ccl.nu_masses(0.1, 'blah')