2 from numpy.testing
import assert_allclose, run_module_suite
11 Compare the redshift functions to an analytic toy case. 14 z_lst = [0., 0.5, 1., 1.5, 2.]
18 def pz_ana(z_ph, z_s, args):
19 return (np.exp(- (z_ph - z_s)**2. / 2. / 0.1**2) / np.sqrt(2.
23 PZ_ana = ccl.PhotoZFunction(pz_ana)
27 def dndz_ana(z, args):
28 if ((z>=0.)
and (z<=1.0)):
34 from math
import erf, erfc
45 def dNdz_tomog_analytic(z, sigz, zmin, zmax):
46 if ( (z>=0.)
and (z<=1.0) ):
47 return (erf((z-zmin) / np.sqrt(2.)/sigz) - erf((z-zmax)/
48 np.sqrt(2.)/sigz)) / (-1. + (-np.exp(-(zmax-1)**2
49 / 2. / sigz**2) + np.exp(-zmax**2 / 2. / sigz**2) +
50 np.exp(-(zmin-1)**2 / 2. / sigz**2) - np.exp(
51 -zmin**2 / 2 /sigz**2)) * np.sqrt(2. / np.pi)*sigz
52 + erf( (zmax-1) / np.sqrt(2.) / sigz) + erfc(
53 (zmin-1.)/np.sqrt(2.)/sigz) + zmax * (erf(zmax/
54 np.sqrt(2.)/sigz) - erf( (zmax-1.) / np.sqrt(2.)/
55 sigz)) + zmin * ( erf( (zmin-1.)/np.sqrt(2.)
56 / sigz) - erf(zmin/np.sqrt(2.)/sigz)))
61 dNdZ_ana = ccl.dNdzFunction(dndz_ana)
69 assert_allclose(ccl.dNdz_tomog(z, zmin, zmax, PZ_ana,
70 dNdZ_ana), dNdz_tomog_analytic(z, 0.1, zmin,
71 zmax), rtol=TOLERANCE)
75 Compare the redshift functions to a high precision integral. 78 z_lst = [0., 0.5, 1., 1.5, 2.]
81 def pz1(z_ph, z_s, args):
82 return np.exp(- (z_ph - z_s)**2. / 2.)
85 pz2 =
lambda z_ph, z_s, args: np.exp(-(z_ph - z_s)**2. / 2.)
88 def pz3(z_ph, z_s, sigz):
90 return (np.exp(- (z_ph - z_s)**2. / 2. / sig**2) / np.sqrt(2.
94 PZ1 = ccl.PhotoZFunction(pz1)
95 PZ2 = ccl.PhotoZFunction(pz2)
96 PZ3 = ccl.PhotoZGaussian(sigma_z0=0.1)
100 return z**1.24 * np.exp(- (z / 0.51)**1.01)
103 dNdZ1 = ccl.dNdzFunction(dndz1)
104 dNdZ2 = ccl.dNdzSmail(alpha = 1.24, beta = 1.01, z0 = 0.51)
109 zp = np.linspace(zmin, zmax, 10000)
110 zs = np.linspace(0., 5., 10000)
112 denom_zp_1 =np.asarray([np.trapz(pz1(zp, z, []), zp)
for z
in zs])
113 denom_zp_2 =np.asarray([np.trapz(pz2(zp, z, []), zp)
for z
in zs])
114 denom_zp_3 =np.asarray([np.trapz(pz3(zp, z, 0.1), zp)
for z
in zs])
115 np_dndz_1 = ([ dndz1(z, []) * np.trapz(pz1(zp, z, []), zp) /
116 np.trapz(dndz1(zs, []) * denom_zp_1, zs)
for z
in 118 np_dndz_2 = ([ dndz1(z, []) * np.trapz(pz2(zp, z, []), zp) /
119 np.trapz(dndz1(zs, []) * denom_zp_2, zs)
for z
in 121 np_dndz_3 = ([ dndz1(z, []) * np.trapz(pz3(zp, z, 0.1), zp) /
122 np.trapz(dndz1(zs, []) * denom_zp_3, zs)
for z
in 127 for i
in range(0, len(z_lst)):
128 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ1,
129 dNdZ1), np_dndz_1[i], rtol=TOLERANCE)
130 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ1,
131 dNdZ2), np_dndz_1[i], rtol=TOLERANCE)
132 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ2,
133 dNdZ1), np_dndz_2[i], rtol=TOLERANCE)
134 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ2,
135 dNdZ2), np_dndz_2[i], rtol=TOLERANCE)
136 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ3,
137 dNdZ1), np_dndz_3[i], rtol=TOLERANCE)
138 assert_allclose(ccl.dNdz_tomog(z_lst[i], zmin, zmax, PZ3,
139 dNdZ2), np_dndz_3[i], rtol=TOLERANCE)
141 if __name__ ==
"__main__":
def test_redshift_numerical()
def test_redshift_analytic()
auto range(T const &first, T const &last) -> Generator< T >