Skip to content

Commit 1d53563

Browse files
committed
inline constant, much faster
1 parent 7376268 commit 1d53563

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cluster_toolkit/pressure_profile.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
`projected_P_BBPS_real` interpolates over a table of comoving distances to
1717
obtain a more precise answer.
1818
'''
19-
import astropy.constants as c
20-
import astropy.units as u
2119
import numpy as np
2220
from scipy.integrate import quad
2321

2422

2523
def _rho_crit(z, omega_m, omega_lambda):
2624
'''
27-
The critical density of the universe, in units of $Msun*Mpc^{-3}*h^{-2}$.
25+
The critical density of the universe, in units of $Msun*Mpc^{-3}*h^2$.
2826
'''
2927
# The constant is 3 * (100 km / s / Mpc)**2 / (8 * pi * G)
3028
# in units of Msun h^2 Mpc^{-3}
29+
# (source: astropy's constants module and unit conversions)
3130
return 2.77536627e+11 * (omega_m * (1 + z)**3 + omega_lambda)
3231

3332

@@ -41,7 +40,9 @@ def P_delta(M, z, omega_b, omega_m, omega_lambda, delta=200):
4140
See BBPS, section 4.1 for details.
4241
Units: Msun s^{-2} Mpc^{-1}
4342
'''
44-
return c.G * M * delta * _rho_crit(z, omega_m, omega_lambda) * \
43+
# G = 4.51710305e-48 Mpc^3 Msun^{-1} s^{-2}
44+
# (source: astropy's constants module and unit conversions)
45+
return 4.51710305e-48 * M * delta * _rho_crit(z, omega_m, omega_lambda) * \
4546
omega_b / omega_m / 2 / R_delta(M, omega_m, omega_lambda, z, delta)
4647

4748

@@ -151,7 +152,7 @@ def projected_P_BBPS(r, M, z, omega_b, omega_m, omega_lambda,
151152
R_del = R_delta(M, z, omega_m, omega_lambda)
152153
return quad(lambda x: P_BBPS(np.sqrt(x*x + r*r), M, z,
153154
omega_b, omega_m,
154-
omega_lambda).value,
155+
omega_lambda),
155156
-dist * R_del, dist * R_del,
156157
epsrel=1e-3)[0] / (1 + z)
157158

@@ -181,8 +182,7 @@ def projected_P_BBPS_real(r, M, z, omega_b, omega_m, omega_lambda, chis, zs,
181182
return quad(lambda x: P_BBPS(np.sqrt((x - chi_cluster)**2 + r*r),
182183
M, z,
183184
omega_b, omega_m,
184-
omega_lambda).value
185-
/ (1 + np.interp(x, chis, zs)),
185+
omega_lambda) / (1 + np.interp(x, chis, zs)),
186186
chi_cluster - dist * R_del,
187187
chi_cluster + dist * R_del,
188188
epsrel=1e-3)[0]

tests/test_pressure_profile.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ def do_test_projection_approximation(n, epsrel=1e-6):
5656

5757

5858
def test_projection_approximation_1():
59-
do_test_projection_approximation(1)
60-
do_test_projection_approximation(1)
59+
for i in range(8):
60+
do_test_projection_approximation(1)
6161

6262

6363
def test_projection_approximation_2():
64-
do_test_projection_approximation(2)
65-
do_test_projection_approximation(2)
64+
for i in range(8):
65+
do_test_projection_approximation(2)
6666

6767

6868
def test_projection_approximation_3():
69-
do_test_projection_approximation(3)
70-
do_test_projection_approximation(3)
69+
for i in range(8):
70+
do_test_projection_approximation(3)
7171

7272

7373
def test_projection_approximation_4():
74-
do_test_projection_approximation(4)
75-
do_test_projection_approximation(4)
74+
for i in range(8):
75+
do_test_projection_approximation(4)
7676

7777

7878
def test_projection_approximation_5():
79-
do_test_projection_approximation(5)
80-
do_test_projection_approximation(5)
79+
for i in range(8):
80+
do_test_projection_approximation(5)
8181

8282

8383
def test_projection_approximation_6():
84-
do_test_projection_approximation(6)
85-
do_test_projection_approximation(6)
84+
for i in range(8):
85+
do_test_projection_approximation(6)

0 commit comments

Comments
 (0)