Skip to content

Commit a75df39

Browse files
committed
remove magic numbers, rename to pressure for consistency with
`density`
1 parent bcc8ef0 commit a75df39

File tree

3 files changed

+58
-55
lines changed

3 files changed

+58
-55
lines changed

cluster_toolkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def _dcast(x):
3636

3737
from . import (averaging, bias, boostfactors, concentration, deltasigma,
3838
density, exclusion, massfunction, miscentering, peak_height,
39-
pressure_profile, profile_derivatives, sigma_reconstruction, xi)
39+
pressure, profile_derivatives, sigma_reconstruction, xi)

cluster_toolkit/pressure_profile.py renamed to cluster_toolkit/pressure.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
(https://ui.adsabs.harvard.edu/abs/2012ApJ...758...75B/abstract), referred to
1010
as BBPS.
1111
12-
Their best-fit pressure profile is implemented in the function
12+
Their best-fit 3D pressure profile is implemented in the function
1313
`P_BBPS`, and projected profiles are implemented in `projected_P_BBPS` and
14-
`projected_P_BBPS_real`. The difference in the latter is that `projected_P_BBPS`
15-
makes an approximation that reduces cosmology dependence, and
16-
`projected_P_BBPS_real` interpolates over a table of comoving distances to
17-
obtain a more precise answer.
14+
`projected_y_BBPS`.
1815
'''
1916

2017
from cluster_toolkit import _dcast, _lib
@@ -23,10 +20,15 @@
2320
import scipy.special as spec
2421

2522

23+
__BBPS_params_P_0 = (18.1, 0.154, -0.758)
24+
__BBPS_params_x_c = (0.497, -0.00865, 0.731)
25+
__BBPS_params_beta = (4.35, 0.0393, 0.415)
26+
27+
2628
def P_BBPS(r, M, z, omega_b, omega_m,
27-
params_P_0=(18.1, 0.154, -0.758),
28-
params_x_c=(0.497, -0.00865, 0.731),
29-
params_beta=(4.35, 0.0393, 0.415),
29+
params_P_0=__BBPS_params_P_0,
30+
params_x_c=__BBPS_params_x_c,
31+
params_beta=__BBPS_params_beta,
3032
alpha=1, gamma=-0.3,
3133
delta=200):
3234
'''
@@ -42,11 +44,14 @@ def P_BBPS(r, M, z, omega_b, omega_m,
4244
omega_m (float): Matter fraction.
4345
params_P_0 (tuple): 3-tuple of :math:`P_0` mass, redshift dependence \
4446
parameters A, :math:`\\alpha_m`, :math:`\\alpha_z`, \
45-
respectively. See BBPS2 Equation 11.
47+
respectively. See BBPS2 Equation 11. Default is BBPS2's \
48+
best-fit.
4649
params_x_c (tuple): 3-tuple of :math:`x_c` mass, redshift dependence, \
47-
same as `params_P_0`.
50+
same as `params_P_0`. Default is BBPS2's \
51+
best-fit.
4852
params_beta (tuple): 3-tuple of :math:`\\beta` mass, redshift \
49-
dependence, same as `params_P_0`.
53+
dependence, same as `params_P_0`. Default is BBPS2's \
54+
best-fit.
5055
5156
Returns:
5257
float: Pressure at distance `r` from the cluster, in units of \
@@ -83,9 +88,9 @@ def P_BBPS(r, M, z, omega_b, omega_m,
8388

8489

8590
def projected_P_BBPS(r, M, z, omega_b, omega_m,
86-
params_P=(18.1, 0.154, -0.758),
87-
params_x_c=(0.497, -0.00865, 0.731),
88-
params_beta=(4.35, 0.0393, 0.415),
91+
params_P_0=__BBPS_params_P_0,
92+
params_x_c=__BBPS_params_x_c,
93+
params_beta=__BBPS_params_beta,
8994
alpha=1, gamma=-0.3,
9095
delta=200,
9196
limit=1000,
@@ -101,6 +106,16 @@ def projected_P_BBPS(r, M, z, omega_b, omega_m,
101106
z (float): Cluster redshift.
102107
omega_b (float): Baryon fraction.
103108
omega_m (float): Matter fraction.
109+
params_P_0 (tuple): 3-tuple of :math:`P_0` mass, redshift dependence \
110+
parameters A, :math:`\\alpha_m`, :math:`\\alpha_z`, \
111+
respectively. See BBPS2 Equation 11. Default is BBPS2's \
112+
best-fit.
113+
params_x_c (tuple): 3-tuple of :math:`x_c` mass, redshift dependence, \
114+
same as `params_P_0`. Default is BBPS2's \
115+
best-fit.
116+
params_beta (tuple): 3-tuple of :math:`\\beta` mass, redshift \
117+
dependence, same as `params_P_0`. Default is BBPS2's \
118+
best-fit.
104119
105120
Returns:
106121
float or array: Integrated line-of-sight pressure at distance `r` from \
@@ -120,7 +135,7 @@ def projected_P_BBPS(r, M, z, omega_b, omega_m,
120135
P_err_out = np.zeros_like(r, dtype=np.double)
121136

122137
# Set parameters
123-
P_0 = _A_BBPS(M, z, *params_P)
138+
P_0 = _A_BBPS(M, z, *params_P_0)
124139
x_c = _A_BBPS(M, z, *params_x_c)
125140
beta = _A_BBPS(M, z, *params_beta)
126141

@@ -169,13 +184,13 @@ def R_delta(M, z, omega_m, delta=200):
169184
{8 \\pi \\Delta \\rho_{crit}}\Big)^{1/3}`
170185
171186
Args:
172-
M (float): Halo mass :math:`M_{\\Delta}`, in units of Msun.
173-
z (float): Redshift to the cluster center.
174-
omega_m (float): The matter fraction :math:`\\Omega_m`.
175-
delta (float): The halo overdensity :math:`\\Delta`.
187+
M (float or array): Halo mass :math:`M_{\\Delta}`, in units of Msun.
188+
z (float or array): Redshift to the cluster center.
189+
omega_m (float or array): The matter fraction :math:`\\Omega_m`.
190+
delta (float or array): The halo overdensity :math:`\\Delta`.
176191
177192
Returns:
178-
float: Radius, in :math:`\\text{Mpc} h^\\frac{-2}{3}`.
193+
float or array: Radius, in :math:`\\text{Mpc} h^\\frac{-2}{3}`.
179194
'''
180195
volume = M / (delta * _rho_crit(z, omega_m))
181196
return (3 * volume / (4 * np.pi))**(1./3)
@@ -205,15 +220,6 @@ def P_delta(M, z, omega_b, omega_m, delta=200):
205220
(omega_b / omega_m) / (2 * R_delta(M, z, omega_m, delta))
206221

207222

208-
def P_simple_BBPS_generalized(x, M, z, P_0, x_c, beta,
209-
alpha=1, gamma=-0.3, delta=200):
210-
'''
211-
The generalized dimensionless BBPS pressure profile. Input x should be
212-
:math:`r / R_{\\Delta}`.
213-
'''
214-
return P_0 * (x / x_c)**gamma * (1 + (x / x_c)**alpha)**(-beta)
215-
216-
217223
def _A_BBPS(M, z, A_0, alpha_m, alpha_z):
218224
'''
219225
Mass-Redshift dependency model for the generalized BBPS profile parameters,
@@ -223,20 +229,12 @@ def _A_BBPS(M, z, A_0, alpha_m, alpha_z):
223229
return A_0 * (M / 10**14)**alpha_m * (1 + z)**alpha_z
224230

225231

226-
def P_simple_BBPS(x, M, z):
227-
'''
228-
The best-fit pressure profile presented in BBPS2.
229-
'''
230-
params_P = (18.1, 0.154, -0.758)
231-
params_x_c = (0.497, -0.00865, 0.731)
232-
params_beta = (4.35, 0.0393, 0.415)
233-
P_0 = _A_BBPS(M, z, *params_P)
234-
x_c = _A_BBPS(M, z, *params_x_c)
235-
beta = _A_BBPS(M, z, *params_beta)
236-
return P_simple_BBPS_generalized(x, M, z, P_0, x_c, beta)
237-
238-
239232
def projected_y_BBPS(r, M, z, omega_b, omega_m,
233+
params_P_0=__BBPS_params_P_0,
234+
params_x_c=__BBPS_params_x_c,
235+
params_beta=__BBPS_params_beta,
236+
alpha=1, gamma=-0.3,
237+
delta=200,
240238
Xh=0.76, epsrel=1e-3):
241239
'''
242240
Projected Compton-y parameter along the line of sight, at a perpendicular
@@ -263,6 +261,11 @@ def projected_y_BBPS(r, M, z, omega_b, omega_m,
263261
# equation to do so, see BBPS2 p. 3.
264262
ch = (2 * Xh + 2) / (5 * Xh + 3)
265263
return ch * cy * projected_P_BBPS(r, M, z, omega_b, omega_m,
264+
params_P_0=params_P_0,
265+
params_x_c=params_x_c,
266+
params_beta=params_beta,
267+
alpha=alpha, gamma=gamma,
268+
delta=delta,
266269
epsrel=epsrel)
267270

268271

@@ -306,8 +309,8 @@ def smoothed_xi(theta, M, z, omega_b, omega_m, da,
306309
# The following functions are for testing only!! #
307310
##################################################
308311

309-
def py_projected_P_BBPS(r, M, z, omega_b, omega_m,
310-
dist=8, epsrel=1e-3):
312+
def _py_projected_P_BBPS(r, M, z, omega_b, omega_m,
313+
dist=8, epsrel=1e-3):
311314
'''
312315
Computes the projected line-of-sight density of a cluster at a radius r
313316
from the cluster center.
@@ -330,8 +333,8 @@ def py_projected_P_BBPS(r, M, z, omega_b, omega_m,
330333
epsrel=epsrel)[0] / (1 + z)
331334

332335

333-
def projected_P_BBPS_real(r, M, z, omega_b, omega_m, chis, zs,
334-
dist=8, epsrel=1e-3):
336+
def _projected_P_BBPS_real(r, M, z, omega_b, omega_m, chis, zs,
337+
dist=8, epsrel=1e-3):
335338
'''
336339
Computes the projected line-of-sight density of a cluster at a radius r
337340
from the cluster center.

tests/test_pressure_profile.py renamed to tests/test_pressure.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cluster_toolkit import pressure_profile as pp
1+
from cluster_toolkit import pressure as pp
22
import math
33
import numpy as np
44
import os
@@ -47,15 +47,15 @@ def do_test_projection_approximation(n, epsrel=1e-4):
4747
r, M, z = sample_rMz()
4848

4949
# Compute the 'true' value
50-
expected = pp.projected_P_BBPS_real(r, M, z,
51-
Omega_b, Omega_m,
52-
chis, z_chis,
53-
epsrel=epsrel*0.01)
50+
expected = pp._projected_P_BBPS_real(r, M, z,
51+
Omega_b, Omega_m,
52+
chis, z_chis,
53+
epsrel=epsrel*0.01)
5454

5555
# Compute the approximate value
56-
actual = pp.py_projected_P_BBPS(r, M, z,
57-
Omega_b, Omega_m,
58-
epsrel=epsrel*0.01)
56+
actual = pp._py_projected_P_BBPS(r, M, z,
57+
Omega_b, Omega_m,
58+
epsrel=epsrel*0.01)
5959

6060
# Check that the relative difference is acceptable
6161
assert abs((expected - actual) / expected) < epsrel

0 commit comments

Comments
 (0)