Skip to content

Commit 3cc6648

Browse files
committed
test all simulated profiles, does not take long
1 parent 7f8669c commit 3cc6648

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

tests/test_pressure_profile.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import math
33
import numpy as np
44
import os
5+
import pandas as pd
6+
import pytest
57
import random
68

79

@@ -24,7 +26,9 @@ def get_cosmology(n):
2426
omega_m = float(val)
2527
if name == 'omega_lambda':
2628
omega_lambda = float(val)
27-
return (omega_b, omega_m, omega_lambda), z_chis, chis
29+
if name == 'h0':
30+
h0 = float(val)
31+
return (omega_b, omega_m, omega_lambda, h0), z_chis, chis
2832

2933

3034
def sample_rMz():
@@ -39,7 +43,7 @@ def sample_rMz():
3943

4044

4145
def do_test_projection_approximation(n, epsrel=1e-4):
42-
(Omega_b, Omega_m, Omega_lambda), z_chis, chis = get_cosmology(n)
46+
(Omega_b, Omega_m, Omega_lambda, h0), z_chis, chis = get_cosmology(n)
4347
r, M, z = sample_rMz()
4448

4549
# Compute the 'true' value
@@ -57,6 +61,11 @@ def do_test_projection_approximation(n, epsrel=1e-4):
5761
assert abs((expected - actual) / expected) < epsrel
5862

5963

64+
def test_projection_approximation_0():
65+
for i in range(8):
66+
do_test_projection_approximation(0)
67+
68+
6069
def test_projection_approximation_1():
6170
for i in range(8):
6271
do_test_projection_approximation(1)
@@ -85,3 +94,42 @@ def test_projection_approximation_5():
8594
def test_projection_approximation_6():
8695
for i in range(8):
8796
do_test_projection_approximation(6)
97+
98+
99+
def test_pressure():
100+
(Omega_b, Omega_m, Omega_lambda, h0), z_chis, chis = get_cosmology(0)
101+
profiles = pd.read_csv(os.path.join(os.path.dirname(__file__),
102+
'data_for_testing/y_profiles.csv'))
103+
for ibin in profiles.ibin.unique():
104+
bin_ = profiles[profiles.ibin == ibin]
105+
Xh = 0.76
106+
# TODO better way to get this?
107+
row1 = next(bin_.iterrows())[1]
108+
M200, z = row1.M200, row1.z
109+
for r, P in zip(bin_.r, bin_.P):
110+
ourP = pp.P_BBPS(r * h0**(2/3), M200, z, Omega_b, Omega_m)
111+
# Convert to dimensionless `y` (see pp.projected_y_BBPS)
112+
ourP *= 1.61574202e+15
113+
# Make unitful
114+
ourP *= h0**(8/3)
115+
# Adjust P_{gas} to P_{electron}
116+
ourP *= (2 * Xh + 2) / (5 * Xh + 3)
117+
assert abs((ourP - P) / P) < 5e-3
118+
119+
120+
@pytest.mark.skip(reason='fiducial table used different integration method')
121+
def test_y_projection():
122+
(Omega_b, Omega_m, Omega_lambda, h0), z_chis, chis = get_cosmology(0)
123+
profiles = pd.read_csv(os.path.join(os.path.dirname(__file__),
124+
'data_for_testing/y_profiles.csv'))
125+
for ibin in profiles.ibin.unique():
126+
bin_ = profiles[profiles.ibin == ibin]
127+
# TODO better way to get this?
128+
row1 = next(bin_.iterrows())[1]
129+
M200, z = row1.M200, row1.z
130+
for r, y in zip(bin_.r, bin_.y):
131+
oury = pp.projected_y_BBPS(r * h0**(2/3), M200, z, Omega_b, Omega_m)
132+
# Convert to dimensionless `y` (see pp.projected_y_BBPS)
133+
oury *= h0**(8/3)
134+
assert abs((oury - y) / y) < 1e-2
135+
# TODO check projected

0 commit comments

Comments
 (0)