Skip to content

Commit 842c2d5

Browse files
committed
Added y computation, much improved function docs
1 parent 0e7edf1 commit 842c2d5

File tree

2 files changed

+91
-35
lines changed

2 files changed

+91
-35
lines changed

cluster_toolkit/pressure_profile.py

Lines changed: 91 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,100 @@
2020
from scipy.integrate import quad
2121

2222

23-
def _rho_crit(z, omega_m, omega_lambda):
23+
def _rho_crit(z, omega_m):
2424
'''
25-
The critical density of the universe, in units of $Msun*Mpc^{-3}*h^2$.
25+
The critical density of the universe :math:`\\rho_{crit}`, in units of
26+
:math:`Msun*Mpc^{-3}*h^2`.
2627
'''
28+
# The below formula assumes a flat univers, i.e. omega_m + omega_lambda = 1
29+
omega_lambda = 1 - omega_m
2730
# The constant is 3 * (100 km / s / Mpc)**2 / (8 * pi * G)
2831
# in units of Msun h^2 Mpc^{-3}
2932
# (source: astropy's constants module and unit conversions)
3033
return 2.77536627e+11 * (omega_m * (1 + z)**3 + omega_lambda)
3134

3235

33-
def P_delta(M, z, omega_b, omega_m, omega_lambda, delta=200):
36+
def P_delta(M, z, omega_b, omega_m, delta=200):
3437
'''
3538
The pressure amplitude of a halo:
3639
37-
P_{delta} = G * M_{delta} * delta * rho_crit(z) \
38-
* omega_b / omega_m / (2R_delta)
40+
:math:`P_{\\Delta} = G * M_{\\Delta} * \\Delta * \\rho_{crit}(z) \
41+
* \\Omega_b / \\Omega_m / (2R_{\\Delta})`
3942
4043
See BBPS, section 4.1 for details.
41-
Units: Msun s^{-2} Mpc^{-1}
44+
45+
Args:
46+
M (float): Halo mass :math:`M_{\\Delta}`, in units of Msun.
47+
omega_b (float): The baryon fraction :math:`\\Omega_b`.
48+
omega_m (float): The matter fraction :math:`\\Omega_m`.
49+
delta (float): The halo overdensity :math:`\\Delta`.
50+
51+
Returns:
52+
float: Pressure amplitude, in units of Msun h^{8/3} s^{-2} Mpc^{-1}.
4253
'''
4354
# G = 4.51710305e-48 Mpc^3 Msun^{-1} s^{-2}
4455
# (source: astropy's constants module and unit conversions)
45-
return 4.51710305e-48 * M * delta * _rho_crit(z, omega_m, omega_lambda) * \
46-
omega_b / omega_m / 2 / R_delta(M, omega_m, omega_lambda, z, delta)
56+
return 4.51710305e-48 * M * delta * _rho_crit(z, omega_m) * \
57+
omega_b / omega_m / 2 / R_delta(M, omega_m, z, delta)
4758

4859

49-
def R_delta(M, z, omega_m, omega_lambda, delta=200):
60+
def R_delta(M, z, omega_m, delta=200):
5061
'''
5162
The radius of a sphere of mass M (in Msun), which has a density `delta`
5263
times the critical density of the universe.
5364
54-
Units: Mpc h^(-2/3)
65+
:math:`R_{\\Delta} = \\Big(\\frac{3 M_{\\Delta}} \
66+
{8 \\pi \\Delta \\rho_{crit}}\Big)^{1/3}`
67+
68+
Args:
69+
M (float): Halo mass :math:`M_{\\Delta}`, in units of Msun.
70+
omega_b (float): The baryon fraction :math:`\\Omega_b`.
71+
omega_m (float): The matter fraction :math:`\\Omega_m`.
72+
delta (float): The halo overdensity :math:`\\Delta`.
73+
74+
Returns:
75+
float: Radius, in :math:`\\text{Mpc} h^\\frac{-2}{3}`.
5576
'''
56-
volume = M / (delta * _rho_crit(z, omega_m, omega_lambda))
77+
volume = M / (delta * _rho_crit(z, omega_m))
5778
return (3 * volume / (4 * np.pi))**(1./3)
5879

5980

6081
def P_simple_BBPS_generalized(x, M, z, P_0, x_c, beta,
6182
alpha=1, gamma=-0.3, delta=200):
6283
'''
6384
The generalized dimensionless BBPS pressure profile. Input x should be
64-
`r / R_{delta}`.
85+
:math:`r / R_{\\Delta}`.
6586
'''
6687
return P_0 * (x / x_c)**gamma * (1 + (x / x_c)**alpha)**(-beta)
6788

6889

69-
def P_BBPS_generalized(r, M, z, omega_b, omega_m, omega_lambda,
90+
def P_BBPS_generalized(r, M, z, omega_b, omega_m,
7091
P_0, x_c, beta, alpha=1, gamma=-0.3, delta=200):
71-
r'''
92+
'''
7293
The generalized NFW form of the Battaglia profile, presented in BBPS2
7394
equation 10 as:
7495
75-
P = P_{delta} P_0 (x / x_c)^\gamma [1 + (x / x_c)^\alpha]^{-\beta}
96+
:math:`P = P_{\\Delta} P_0 (x / x_c)^\\gamma \
97+
[1 + (x / x_c)^\\alpha]^{-\\beta}`
98+
99+
Where :math:`x = r/R_{\\Delta}`.
100+
101+
Args:
102+
r (float): Radius from cluster center, in Mpc.
103+
M (float): Halo mass M_{200}, in Msun.
104+
z (float): Redshift to cluster.
105+
omega_b (float): Baryon fraction.
106+
omega_m (float): Matter fraction.
107+
P_0 (float): Pressure scale parameter, see BBPS2 Eq. 10.
108+
x_c (float): Core scale parameter, see BBPS2 Eq. 10.
109+
beta (float): Asymptotic dropoff parameter, see BBPS2 Eq. 10.
110+
111+
Returns:
112+
float: Pressure at a distance `r` from a cluster center, in units of \
113+
Msun s^{-2} Mpc^{-1}.
76114
'''
77-
x = r / R_delta(M, z, omega_m, omega_lambda, delta=delta)
78-
Pd = P_delta(M, z, omega_b, omega_m, omega_lambda, delta=delta)
115+
x = r / R_delta(M, z, omega_m, delta=delta)
116+
Pd = P_delta(M, z, omega_b, omega_m, delta=delta)
79117
return Pd * P_simple_BBPS_generalized(x, M, z, P_0, x_c, beta,
80118
alpha=alpha, gamma=gamma, delta=delta)
81119

@@ -102,17 +140,16 @@ def P_simple_BBPS(x, M, z):
102140
return P_simple_BBPS_generalized(x, M, z, P_0, x_c, beta)
103141

104142

105-
def P_BBPS(r, M, z, omega_b, omega_m, omega_lambda):
143+
def P_BBPS(r, M, z, omega_b, omega_m):
106144
'''
107145
The best-fit pressure profile presented in BBPS2.
108146
109147
Args:
110148
r (float): Radius from the cluster center, in Mpc.
111-
M (float): Cluster M_{200}, in Msun.
149+
M (float): Cluster :math:`M_{\\Delta}`, in Msun.
112150
z (float): Cluster redshift.
113151
omega_b (float): Baryon fraction.
114152
omega_m (float): Matter fraction.
115-
omega_lambda (float): Dark energy fraction.
116153
117154
Returns:
118155
float: Pressure at distance `r` from the cluster, in units of \
@@ -127,62 +164,83 @@ def P_BBPS(r, M, z, omega_b, omega_m, omega_lambda):
127164
P_0 = _A_BBPS(M, z, *params_P)
128165
x_c = _A_BBPS(M, z, *params_x_c)
129166
beta = _A_BBPS(M, z, *params_beta)
130-
return P_BBPS_generalized(r, M, z, omega_b, omega_m, omega_lambda,
167+
return P_BBPS_generalized(r, M, z, omega_b, omega_m,
131168
P_0, x_c, beta)
132169

133170

134-
def projected_P_BBPS(r, M, z, omega_b, omega_m, omega_lambda,
171+
def projected_P_BBPS(r, M, z, omega_b, omega_m,
135172
dist=8, epsrel=1e-3):
136173
'''
137174
Computes the projected line-of-sight density of a cluster at a radius r
138175
from the cluster center.
139176
140177
Args:
141178
r (float): Radius from the cluster center, in Mpc.
142-
M (float): Cluster M_{200}, in Msun.
179+
M (float): Cluster :math:`M_{\\Delta}`, in Msun.
143180
z (float): Cluster redshift.
144181
omega_b (float): Baryon fraction.
145182
omega_m (float): Matter fraction.
146-
omega_lambda (float): Dark energy fraction.
147183
148184
Returns:
149185
float: Integrated line-of-sight pressure at distance `r` from the \
150186
cluster, in units of Msun s^{-2}.
151187
'''
152-
R_del = R_delta(M, z, omega_m, omega_lambda)
188+
R_del = R_delta(M, z, omega_m)
153189
return quad(lambda x: P_BBPS(np.sqrt(x*x + r*r), M, z,
154-
omega_b, omega_m,
155-
omega_lambda),
190+
omega_b, omega_m),
156191
-dist * R_del, dist * R_del,
157192
epsrel=epsrel)[0] / (1 + z)
158193

159194

160-
def projected_P_BBPS_real(r, M, z, omega_b, omega_m, omega_lambda, chis, zs,
195+
def projected_y_BBPS(r, M, z, omega_b, omega_m,
196+
dist=8, epsrel=1e-3):
197+
'''
198+
Projected Compton-y parameter along the line of sight, at a perpendicular
199+
distance `r` from a cluster of mass `M` at redshift `z`. All arguments have
200+
the same meaning as `projected_P_BBPS`.
201+
202+
Args:
203+
r (float): Radius from the cluster center, in Mpc.
204+
M (float): Cluster :math:`M_{\\Delta}`, in Msun.
205+
z (float): Cluster redshift.
206+
omega_b (float): Baryon fraction.
207+
omega_m (float): Matter fraction.
208+
209+
Returns:
210+
float: Compton y parameter. Unitless.
211+
'''
212+
# The constant is \sigma_T / (m_e * c^2), i.e. the Thompson cross-section
213+
# divided by the mass-energy of the electron, in units of s^2 Msun^{-1}.
214+
# Source: Astropy constants and unit conversions.
215+
cy = 1.61574202e+15
216+
return cy * projected_P_BBPS(r, M, z, omega_b, omega_m,
217+
dist=dist, epsrel=epsrel)
218+
219+
220+
def projected_P_BBPS_real(r, M, z, omega_b, omega_m, chis, zs,
161221
dist=8, epsrel=1e-3):
162222
'''
163223
Computes the projected line-of-sight density of a cluster at a radius r
164224
from the cluster center.
165225
166226
Args:
167227
r (float): Radius from the cluster center, in Mpc.
168-
M (float): Cluster M_{200}, in Msun.
228+
M (float): Cluster :math:`M_{\\Delta}`, in Msun.
169229
z (float): Cluster redshift.
170230
omega_b (float): Baryon fraction.
171231
omega_m (float): Matter fraction.
172-
omega_lambda (float): Dark energy fraction.
173232
chis (1d array of floats): The comoving line-of-sight distance, in Mpc.
174233
zs (1d array of floats): The redshifts corresponding to `chis`.
175234
176235
Returns:
177236
float: Integrated line-of-sight pressure at distance `r` from the \
178237
cluster, in units of Msun s^{-2}.
179238
'''
180-
R_del = R_delta(M, z, omega_m, omega_lambda)
239+
R_del = R_delta(M, z, omega_m)
181240
chi_cluster = np.interp(z, zs, chis)
182241
return quad(lambda x: P_BBPS(np.sqrt((x - chi_cluster)**2 + r*r),
183242
M, z,
184-
omega_b, omega_m,
185-
omega_lambda) / (1 + np.interp(x, chis, zs)),
243+
omega_b, omega_m) / (1 + np.interp(x, chis, zs)),
186244
chi_cluster - dist * R_del,
187245
chi_cluster + dist * R_del,
188246
epsrel=epsrel)[0]

tests/test_pressure_profile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ def do_test_projection_approximation(n, epsrel=1e-4):
4545
# Compute the 'true' value
4646
expected = pp.projected_P_BBPS_real(r, M, z,
4747
Omega_b, Omega_m,
48-
Omega_lambda,
4948
chis, z_chis,
5049
epsrel=epsrel*0.01)
5150

5251
# Compute the approximate value
5352
actual = pp.projected_P_BBPS(r, M, z,
5453
Omega_b, Omega_m,
55-
Omega_lambda,
5654
epsrel=epsrel*0.01)
5755

5856
# Check that the relative difference is acceptable

0 commit comments

Comments
 (0)