1 import numpy
as np,math
2 from numpy.testing
import assert_raises, assert_warns, assert_no_warnings, \
3 assert_, decorators, run_module_suite, assert_allclose
5 from pyccl
import CCLError
9 Create a set of reference Cosmology() objects. 12 cosmo1 = ccl.Cosmology(
13 Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
16 cosmo2 = ccl.Cosmology(
17 Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10,
18 n_s=0.96, Omega_k=0.05)
21 cosmo3 = ccl.Cosmology(
22 Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10,
23 n_s=0.96, w0=-0.95, wa=0.05)
26 cosmo4 = ccl.Cosmology(
27 Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96,
28 transfer_function=
'bbks')
31 cosmo5 = ccl.Cosmology(
32 Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96,
33 transfer_function=
'eisenstein_hu')
36 cosmo6 = ccl.Cosmology(
37 Omega_c=0.27, Omega_b=0.022/0.67**2, h=0.67, sigma8=0.8,
38 n_s=0.96, Neff=3.04, m_nu=0.,
39 transfer_function=
'emulator',
40 matter_power_spectrum=
'emu')
43 cosmo8 = ccl.Cosmology(
44 Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96,
45 baryons_power_spectrum=
'bcm')
48 cosmo9 = ccl.Cosmology(
49 Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96,
50 bcm_log10Mc=math.log10(1.7e14), bcm_etab=0.3, bcm_ks=75.,
51 baryons_power_spectrum=
'bcm')
60 return [cosmo1, cosmo4, cosmo5, cosmo9]
64 Create a set of reference cosmological models with massive neutrinos. 65 This is separate because certain functionality is not yes implemented 66 for massive neutrino cosmologies so will throw errors. 70 cosmo1 = ccl.Cosmology(
71 Omega_c=0.27, Omega_b=0.022/0.67**2, h=0.67, sigma8=0.8,
72 n_s=0.96, Neff=3.04, m_nu=[0.02, 0.02, 0.02],
73 transfer_function=
'emulator',
74 matter_power_spectrum=
'emu')
86 Returns True if all elements are finite (i.e. not NaN or inf). 88 return np.all( np.isfinite(vals) )
92 Check that background and growth functions can be run. 98 a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
99 a_arr = np.linspace(0.2, 1., 5)
102 assert_(
all_finite(ccl.growth_factor(cosmo, a_scl)) )
103 assert_(
all_finite(ccl.growth_factor(cosmo, a_lst)) )
104 assert_(
all_finite(ccl.growth_factor(cosmo, a_arr)) )
107 assert_(
all_finite(ccl.growth_factor_unnorm(cosmo, a_scl)) )
108 assert_(
all_finite(ccl.growth_factor_unnorm(cosmo, a_lst)) )
109 assert_(
all_finite(ccl.growth_factor_unnorm(cosmo, a_arr)) )
112 assert_(
all_finite(ccl.growth_rate(cosmo, a_scl)) )
113 assert_(
all_finite(ccl.growth_rate(cosmo, a_lst)) )
114 assert_(
all_finite(ccl.growth_rate(cosmo, a_arr)) )
117 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_scl)) )
118 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_lst)) )
119 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_arr)) )
122 assert_(
all_finite(ccl.comoving_angular_distance(cosmo, a_scl)) )
123 assert_(
all_finite(ccl.comoving_angular_distance(cosmo, a_lst)) )
124 assert_(
all_finite(ccl.comoving_angular_distance(cosmo, a_arr)) )
127 assert_(
all_finite(ccl.h_over_h0(cosmo, a_scl)) )
128 assert_(
all_finite(ccl.h_over_h0(cosmo, a_lst)) )
129 assert_(
all_finite(ccl.h_over_h0(cosmo, a_arr)) )
132 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_scl)) )
133 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_lst)) )
134 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_arr)) )
137 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)) )
138 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)) )
139 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)) )
142 assert_(
all_finite(ccl.omega_x(cosmo, a_scl,
'matter')) )
143 assert_(
all_finite(ccl.omega_x(cosmo, a_lst,
'matter')) )
144 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'matter')) )
147 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'dark_energy')) )
148 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'radiation')) )
149 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'curvature')) )
150 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'neutrinos_rel')) )
151 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'neutrinos_massive')) )
154 assert_raises(ValueError, ccl.omega_x, cosmo, a_scl,
'xyz')
157 assert_(
all_finite(ccl.rho_x(cosmo, a_scl,
'critical', is_comoving)) )
158 assert_(
all_finite(ccl.rho_x(cosmo, a_lst,
'critical', is_comoving)) )
159 assert_(
all_finite(ccl.rho_x(cosmo, a_arr,
'critical', is_comoving)) )
162 assert_(
all_finite(ccl.rho_x(cosmo, a_scl,
'matter', is_comoving)) )
163 assert_(
all_finite(ccl.rho_x(cosmo, a_lst,
'matter', is_comoving)) )
164 assert_(
all_finite(ccl.rho_x(cosmo, a_arr,
'matter', is_comoving)) )
169 Check that background functions can be run and that the growth functions 170 exit gracefully in functions with massive neutrinos (not implemented yet). 174 a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
175 a_arr = np.linspace(0.2, 1., 5)
178 assert_raises(CCLError, ccl.growth_factor, cosmo, a_scl)
179 assert_raises(CCLError, ccl.growth_factor, cosmo, a_lst)
180 assert_raises(CCLError, ccl.growth_factor, cosmo, a_arr)
183 assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_scl)
184 assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_lst)
185 assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_arr)
188 assert_raises(CCLError,ccl.growth_rate, cosmo, a_scl)
189 assert_raises(CCLError,ccl.growth_rate, cosmo, a_lst)
190 assert_raises(CCLError,ccl.growth_rate, cosmo, a_arr)
193 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_scl)) )
194 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_lst)) )
195 assert_(
all_finite(ccl.comoving_radial_distance(cosmo, a_arr)) )
198 assert_(
all_finite(ccl.h_over_h0(cosmo, a_scl)) )
199 assert_(
all_finite(ccl.h_over_h0(cosmo, a_lst)) )
200 assert_(
all_finite(ccl.h_over_h0(cosmo, a_arr)) )
203 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_scl)) )
204 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_lst)) )
205 assert_(
all_finite(ccl.luminosity_distance(cosmo, a_arr)) )
208 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)) )
209 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)) )
210 assert_(
all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)) )
213 assert_(
all_finite(ccl.omega_x(cosmo, a_scl,
'matter')) )
214 assert_(
all_finite(ccl.omega_x(cosmo, a_lst,
'matter')) )
215 assert_(
all_finite(ccl.omega_x(cosmo, a_arr,
'matter')) )
220 Check that power spectrum and sigma functions can be run. 224 a_arr = np.linspace(0.2, 1., 5.)
228 k_lst = [1e-4, 1e-3, 1e-2, 1e-1, 1e0]
229 k_arr = np.logspace(-4., 0., 5)
233 R_lst = [1., 5., 10., 20., 50., 100.]
234 R_arr = np.array([1., 5., 10., 20., 50., 100.])
237 assert_(
all_finite(ccl.linear_matter_power(cosmo, k_scl, a)) )
238 assert_(
all_finite(ccl.linear_matter_power(cosmo, k_lst, a)) )
239 assert_(
all_finite(ccl.linear_matter_power(cosmo, k_arr, a)) )
241 assert_raises(TypeError, ccl.linear_matter_power, cosmo, k_scl, a_arr)
242 assert_raises(TypeError, ccl.linear_matter_power, cosmo, k_lst, a_arr)
243 assert_raises(TypeError, ccl.linear_matter_power, cosmo, k_arr, a_arr)
246 assert_(
all_finite(ccl.nonlin_matter_power(cosmo, k_scl, a)) )
247 assert_(
all_finite(ccl.nonlin_matter_power(cosmo, k_lst, a)) )
248 assert_(
all_finite(ccl.nonlin_matter_power(cosmo, k_arr, a)) )
250 assert_raises(TypeError, ccl.nonlin_matter_power, cosmo, k_scl, a_arr)
251 assert_raises(TypeError, ccl.nonlin_matter_power, cosmo, k_lst, a_arr)
252 assert_raises(TypeError, ccl.nonlin_matter_power, cosmo, k_arr, a_arr)
255 assert_(
all_finite(ccl.sigmaR(cosmo, R_scl)) )
256 assert_(
all_finite(ccl.sigmaR(cosmo, R_lst)) )
257 assert_(
all_finite(ccl.sigmaR(cosmo, R_arr)) )
260 assert_(
all_finite(ccl.sigmaV(cosmo, R_scl)) )
261 assert_(
all_finite(ccl.sigmaV(cosmo, R_lst)) )
262 assert_(
all_finite(ccl.sigmaV(cosmo, R_arr)) )
270 Check that mass function and supporting functions can be run. 274 z_arr = np.linspace(0., 2., 10)
276 a_arr = 1. / (1.+z_arr)
278 mhalo_lst = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16]
279 mhalo_arr = np.array([1e11, 1e12, 1e13, 1e14, 1e15, 1e16])
283 assert_(
all_finite(ccl.massfunc(cosmo, mhalo_scl, a, odelta)) )
284 assert_(
all_finite(ccl.massfunc(cosmo, mhalo_lst, a, odelta)) )
285 assert_(
all_finite(ccl.massfunc(cosmo, mhalo_arr, a, odelta)) )
287 assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_scl, a_arr, odelta)
288 assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_lst, a_arr, odelta)
289 assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_arr, a_arr, odelta)
292 assert_raises(CCLError, ccl.massfunc, cosmo, mhalo_scl, a, 199.)
293 assert_raises(CCLError, ccl.massfunc, cosmo, mhalo_scl, a, 5000.)
296 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_scl)) )
297 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_lst)) )
298 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_arr)) )
301 assert_(
all_finite(ccl.sigmaM(cosmo, mhalo_scl, a)) )
302 assert_(
all_finite(ccl.sigmaM(cosmo, mhalo_lst, a)) )
303 assert_(
all_finite(ccl.sigmaM(cosmo, mhalo_arr, a)) )
305 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_scl, a_arr)
306 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_lst, a_arr)
307 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_arr, a_arr)
310 assert_(
all_finite(ccl.halo_bias(cosmo, mhalo_scl, a)) )
311 assert_(
all_finite(ccl.halo_bias(cosmo, mhalo_lst, a)) )
312 assert_(
all_finite(ccl.halo_bias(cosmo, mhalo_arr, a)) )
317 Check that mass function and supporting functions can be run. 320 z_arr = np.linspace(0., 2., 10)
322 a_arr = 1. / (1.+z_arr)
324 mhalo_lst = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16]
325 mhalo_arr = np.array([1e11, 1e12, 1e13, 1e14, 1e15, 1e16])
329 assert_raises(CCLError, ccl.massfunc,cosmo, mhalo_scl, a, odelta)
330 assert_raises(CCLError, ccl.massfunc,cosmo, mhalo_lst, a, odelta)
331 assert_raises(CCLError, ccl.massfunc,cosmo, mhalo_arr, a, odelta)
334 assert_raises(CCLError, ccl.halo_bias, cosmo, mhalo_scl, a, odelta)
335 assert_raises(CCLError, ccl.halo_bias, cosmo, mhalo_lst, a, odelta)
336 assert_raises(CCLError, ccl.halo_bias, cosmo, mhalo_arr, a, odelta)
339 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_scl)) )
340 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_lst)) )
341 assert_(
all_finite(ccl.massfunc_m2r(cosmo, mhalo_arr)) )
344 assert_raises(CCLError, ccl.sigmaM, cosmo, mhalo_scl, a)
345 assert_raises(CCLError, ccl.sigmaM, cosmo, mhalo_lst, a)
346 assert_raises(CCLError, ccl.sigmaM, cosmo, mhalo_arr, a)
348 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_scl, a_arr)
349 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_lst, a_arr)
350 assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_arr, a_arr)
355 Check that halo model functions can be run. 360 z_array = np.linspace(0., 2., 10)
362 a_array = 1. / (1.+z_array)
369 mass_list = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16]
370 mass_array = np.array([1e11, 1e12, 1e13, 1e14, 1e15, 1e16])
374 k_list = [1e-3, 1e-2, 1e-1, 1e0, 1e1]
375 k_array = np.array([1e-3, 1e-2, 1e-1, 1e0, 1e1])
378 assert_(
all_finite(ccl.halo_concentration(cosmo, mass_scalar, a, odelta)) )
379 assert_(
all_finite(ccl.halo_concentration(cosmo, mass_list, a, odelta)) )
380 assert_(
all_finite(ccl.halo_concentration(cosmo, mass_array, a, odelta)) )
382 assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_scalar, a_array, odelta)
383 assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_list, a_array, odelta)
384 assert_raises(TypeError, ccl.halo_concentration, cosmo, mass_array, a_array, odelta)
387 assert_(
all_finite(ccl.halomodel_matter_power(cosmo, k_scalar, a)) )
388 assert_(
all_finite(ccl.halomodel_matter_power(cosmo, k_list, a)) )
389 assert_(
all_finite(ccl.halomodel_matter_power(cosmo, k_array, a)) )
391 assert_(
all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_scalar, a)) )
392 assert_(
all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_list, a)) )
393 assert_(
all_finite(ccl.halomodel.twohalo_matter_power(cosmo, k_array, a)) )
395 assert_(
all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_scalar, a)) )
396 assert_(
all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_list, a)) )
397 assert_(
all_finite(ccl.halomodel.onehalo_matter_power(cosmo, k_array, a)) )
399 assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_scalar, a_array)
400 assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_list, a_array)
401 assert_raises(TypeError, ccl.halomodel_matter_power, cosmo, k_array, a_array)
405 Check that neutrino-related functions can be run. 408 z_arr = np.linspace(0., 2., 10)
410 a_arr = 1. / (1.+z_arr)
411 a_lst = [_a
for _a
in a_arr]
415 mnu = [0.02, 0.02, 0.02]
418 assert_(
all_finite(ccl.Omeganuh2(a, mnu, TCMB)) )
419 assert_(
all_finite(ccl.Omeganuh2(a_lst, mnu, TCMB)) )
420 assert_(
all_finite(ccl.Omeganuh2(a_arr, mnu, TCMB)) )
425 assert_(
all_finite(ccl.nu_masses(OmNuh2,
'normal', TCMB)) )
426 assert_(
all_finite(ccl.nu_masses(OmNuh2,
'inverted', TCMB)) )
427 assert_(
all_finite(ccl.nu_masses(OmNuh2,
'equal', TCMB)) )
428 assert_(
all_finite(ccl.nu_masses(OmNuh2,
'sum', TCMB)) )
431 assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045,
432 h=0.67, A_s=1e-10, n_s=0.96,
433 m_nu=[0.1, 0.2, 0.3, 0.4])
434 assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045,
435 h=0.67, A_s=1e-10, n_s=0.96,
436 m_nu=[0.1, 0.2, 0.3],
438 assert_raises(ValueError, ccl.Cosmology, Omega_c=0.27, Omega_b=0.045,
439 h=0.67, A_s=1e-10, n_s=0.96,
445 Check that redshift functions can be run and produce finite values. 449 a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
450 a_arr = np.linspace(0.2, 1., 5)
454 z_lst = [0., 0.5, 1., 1.5, 2.]
455 z_arr = np.array(z_lst)
458 def pz1(z_ph, z_s, args):
459 return np.exp(- (z_ph - z_s)**2. / 2.)
462 pz2 =
lambda z_ph, z_s, args: np.exp(-(z_ph - z_s)**2. / 2.)
465 PZ1 = ccl.PhotoZFunction(pz1)
466 PZ2 = ccl.PhotoZFunction(pz2)
467 PZ3 = ccl.PhotoZGaussian(sigma_z0=0.1)
471 return z**1.24 * np.exp(- (z / 0.51)**1.01)
473 dNdZ1 = ccl.dNdzFunction(dndz1)
474 dNdZ2 = ccl.dNdzSmail(alpha = 1.24, beta = 1.01, z0 = 0.51)
481 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ1, dNdZ1)) )
482 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ1, dNdZ1)) )
483 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ1, dNdZ1)) )
485 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ2, dNdZ1)) )
486 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ2, dNdZ1)) )
487 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ2, dNdZ1)) )
489 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ3, dNdZ1)) )
490 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ3, dNdZ1)) )
491 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ3, dNdZ1)) )
493 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ1, dNdZ2)) )
494 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ1, dNdZ2)) )
495 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ1, dNdZ2)) )
497 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ2, dNdZ2)) )
498 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ2, dNdZ2)) )
499 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ2, dNdZ2)) )
501 assert_(
all_finite(ccl.dNdz_tomog(z_scl, zmin, zmax, PZ3, dNdZ2)) )
502 assert_(
all_finite(ccl.dNdz_tomog(z_lst, zmin, zmax, PZ3, dNdZ2)) )
503 assert_(
all_finite(ccl.dNdz_tomog(z_arr, zmin, zmax, PZ3, dNdZ2)) )
506 assert_raises(TypeError, ccl.dNdz_tomog, z_scl, zmin, zmax, pz1, z_arr)
507 assert_raises(TypeError, ccl.dNdz_tomog, z_scl, zmin, zmax, z_arr, dNdZ1)
508 assert_raises(TypeError, ccl.dNdz_tomog, z_scl, zmin, zmax,
None,
None)
512 Check that cls functions can be run. 515 z = np.linspace(0., 1., 200)
516 n = np.exp(-((z-0.5)/0.1)**2)
523 ell_lst = [2, 3, 4, 5, 6, 7, 8, 9]
524 ell_arr = np.arange(2, 10)
528 if cosmo._config.matter_power_spectrum_method \
529 == ccl.core.matter_power_spectrum_types[
'emu']: cmb_ok =
False 532 lens1 = ccl.WeakLensingTracer(cosmo, (z, n))
533 lens2 = ccl.WeakLensingTracer(cosmo, dndz=(z,n), ia_bias=(z, n), red_frac=(z,n))
534 nc1 = ccl.NumberCountsTracer(cosmo,
False, dndz=(z,n), bias=(z,b))
535 nc2 = ccl.NumberCountsTracer(cosmo,
True, dndz=(z,n), bias=(z,b))
536 nc3 = ccl.NumberCountsTracer(cosmo,
True, dndz=(z,n), bias=(z,b), mag_bias=(z,b))
537 cmbl=ccl.CMBLensingTracer(cosmo, 1100.)
539 assert_raises(ValueError, ccl.WeakLensingTracer, cosmo,
None)
540 assert_raises(ValueError, ccl.NumberCountsTracer, cosmo,
False, (z,n),
None)
543 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_scl)) )
544 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_lst)) )
545 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_arr)) )
547 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_scl)) )
548 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_lst)) )
549 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr)) )
551 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, cmbl, cmbl, ell_arr)) )
554 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr, l_limber=20)))
557 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens2, ell_arr)) )
558 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, nc1, ell_arr)) )
559 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, nc2, ell_arr)) )
560 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, nc3, ell_arr)) )
561 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, lens1, cmbl, ell_arr)) )
562 assert_(
all_finite(ccl.angular_cl(cosmo, lens2, nc1, ell_arr)) )
563 assert_(
all_finite(ccl.angular_cl(cosmo, lens2, nc2, ell_arr)) )
564 assert_(
all_finite(ccl.angular_cl(cosmo, lens2, nc3, ell_arr)) )
565 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, lens2, cmbl, ell_arr)) )
566 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc2, ell_arr)) )
567 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc3, ell_arr)) )
568 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, nc1, cmbl, ell_arr)) )
569 assert_(
all_finite(ccl.angular_cl(cosmo, nc2, nc3, ell_arr)) )
570 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, nc2, cmbl, ell_arr)) )
571 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, nc3, cmbl, ell_arr)) )
574 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, lens1, ell_arr)) )
575 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, lens2, ell_arr)) )
581 Check that cls functions can be run. 584 z = np.linspace(0., 1., 200)
585 n = np.exp(-((z-0.5)/0.1)**2)
592 ell_lst = [2, 3, 4, 5, 6, 7, 8, 9]
593 ell_arr = np.arange(2, 10)
597 if cosmo._config.matter_power_spectrum_method \
598 == ccl.core.matter_power_spectrum_types[
'emu']: cmb_ok =
False 601 lens1 = ccl.WeakLensingTracer(cosmo, dndz=(z,n))
602 lens2 = ccl.WeakLensingTracer(cosmo, dndz=(z,n), ia_bias=(z,n), red_frac=(z,n))
603 nc1 = ccl.NumberCountsTracer(cosmo,
False, dndz=(z,n), bias=(z,b))
606 assert_raises(CCLError, ccl.NumberCountsTracer, cosmo,
True, dndz=(z,n), bias=(z,b))
608 cmbl=ccl.CMBLensingTracer(cosmo,1100.)
611 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_scl)) )
612 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_lst)) )
613 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_arr)) )
615 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_scl)) )
616 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_lst)) )
617 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr)) )
619 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, cmbl, cmbl, ell_arr)) )
622 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, lens2, ell_arr)) )
623 assert_(
all_finite(ccl.angular_cl(cosmo, lens1, nc1, ell_arr)) )
624 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, lens1, cmbl, ell_arr)) )
625 assert_(
all_finite(ccl.angular_cl(cosmo, lens2, nc1, ell_arr)) )
626 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, lens2, cmbl, ell_arr)) )
627 if cmb_ok: assert_(
all_finite(ccl.angular_cl(cosmo, nc1, cmbl, ell_arr)) )
630 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, lens1, ell_arr)) )
631 assert_(
all_finite(ccl.angular_cl(cosmo, nc1, lens2, ell_arr)) )
635 a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
636 a_arr = np.linspace(0.2, 1., 5)
637 assert_(
all_finite(nc1.get_internal_function(cosmo,
'dndz', a_scl)) )
638 assert_(
all_finite(nc1.get_internal_function(cosmo,
'dndz', a_lst)) )
639 assert_(
all_finite(nc1.get_internal_function(cosmo,
'dndz', a_arr)) )
642 assert_raises(ValueError, nc1.get_internal_function, cosmo,
'x', a_arr)
643 assert_raises(CCLError, ccl.NumberCountsTracer, cosmo,
True,
644 dndz=(z,n), bias=(z,b))
645 assert_raises(ValueError, ccl.WeakLensingTracer, cosmo,
646 dndz=(z,n), ia_bias=(z,n))
652 z = np.linspace(0., 1., 200)
656 lens1 = ccl.WeakLensingTracer(cosmo, dndz=(z, n))
657 lens2 = ccl.WeakLensingTracer(cosmo, dndz=(z,n), ia_bias=(z,n), red_frac=(z,n))
659 ells = np.arange(3000)
660 cls = ccl.angular_cl(cosmo, lens1, lens2, ells)
662 t_arr = np.logspace(-2., np.log10(5.), 20)
663 t_lst = [t
for t
in t_arr]
668 corr1 = ccl.correlation(cosmo, ells, cls, t_arr, corr_type=
'L+',
670 corr2 = ccl.correlation(cosmo, ells, cls, t_lst, corr_type=
'L+',
672 corr3 = ccl.correlation(cosmo, ells, cls, t_scl, corr_type=
'L+',
674 corr4 = ccl.correlation(cosmo, ells, cls, t_int, corr_type=
'L+',
682 assert_raises(ValueError, ccl.correlation, cosmo, ells, cls, t_arr,
683 corr_type=
'xx', method=
'FFTLog')
684 assert_raises(ValueError, ccl.correlation, cosmo, ells, cls, t_arr,
685 corr_type=
'L+', method=
'xx')
695 r_lst = np.linspace(50,100,10)
698 corr1 = ccl.correlation_3d(cosmo, a, r_int)
699 corr2 = ccl.correlation_3d(cosmo, a, r)
700 corr3 = ccl.correlation_3d(cosmo, a, r_lst)
709 Check that invalid transfer_function <-> matter_power_spectrum pairs raise 712 params = {
'Omega_c': 0.27,
'Omega_b': 0.045,
'h': 0.67,
713 'A_s': 1e-10,
'n_s': 0.96,
'w0': -1.,
'wa': 0. }
715 assert_raises(ValueError, ccl.Cosmology, transfer_function=
'emulator',
716 matter_power_spectrum=
'linear', **params)
719 assert_raises(ValueError, ccl.Cosmology, transfer_function=
'bbks',
720 matter_power_spectrum=
'emu', **params)
724 Test background and growth functions in ccl.background. 727 yield check_background, cosmo
730 yield check_background_nu, cosmo_nu
734 Test power spectrum and sigma functions in ccl.power. 737 yield check_power, cosmo
740 yield check_power, cosmo_nu
745 Test mass function and supporting functions. 748 yield check_massfunc, cosmo
751 yield check_massfunc_nu, cosmo_nu
755 Test halo model and supporting functions. 758 yield check_halomod, cosmo
763 Test neutrino-related functions. 765 yield check_neutrinos
769 Test redshifts module. 772 yield check_redshifts, cosmo
775 yield check_redshifts, cosmo_nu
780 Test top-level functions in pyccl.cls module. 783 yield check_cls, cosmo
786 yield check_cls_nu, cosmo_nu
790 Test top-level functions in pyccl.correlation module. 793 yield check_corr, cosmo
796 yield check_corr, cosmo_nu
799 yield check_corr_3d, cosmo
802 yield check_corr_3d, cosmo_nu
806 Test that debug mode can be toggled. 809 ccl.debug_mode(
False)
813 if __name__ ==
'__main__':
def check_massfunc_nu(cosmo)
def check_background(cosmo)
def check_background_nu(cosmo)
def check_massfunc(cosmo)
def test_valid_transfer_combos()
def reference_models_nu()
def check_redshifts(cosmo)