Skip to content

Commit 5fffc62

Browse files
authored
Merge pull request #481 from ArgonneCPAC/ra_dec_bugfix
Update `lc_cores-decomposition.txt` for Last Journey to fix bug in `{ra, dec}` of synthetic halos
2 parents 3976fa3 + a351bb1 commit 5fffc62

8 files changed

Lines changed: 1305 additions & 1481 deletions

File tree

diffsky/data_loaders/hacc_utils/data/LastJourney/lc_cores-decomposition.txt

Lines changed: 1200 additions & 1472 deletions
Large diffs are not rendered by default.

diffsky/data_loaders/hacc_utils/data_validation/validate_lc_mock.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,31 @@ def check_lc_cores_decomposition(fn_lc_mock, bn=BNAME_LC_PATCH_DECOMPOSITION):
326326
msg.append(s)
327327

328328
try:
329-
lightcone_utils.read_lc_ra_dec_patch_decomposition(fn)
329+
_res = lightcone_utils.read_lc_ra_dec_patch_decomposition(fn)
330+
patch_decomposition_from_mock, sky_frac_from_mock, solid_angles_from_mock = _res
330331
except: # noqa
331332
s = f"Failure to read {fn} with read_lc_ra_dec_patch_decomposition"
332333
msg.append(s)
333334

335+
metadata = load_lc_mock.load_mock_metadata(fn_lc_mock)
336+
sim_name = metadata["nbody_info"]["sim_name"]
337+
_res = lightcone_utils.read_hacc_lc_patch_decomposition(sim_name)
338+
patch_decomposition_from_src, sky_frac_from_src, solid_angles_from_src = _res
339+
340+
try:
341+
assert len(patch_decomposition_from_mock) == len(patch_decomposition_from_src)
342+
assert len(sky_frac_from_mock) == len(sky_frac_from_src)
343+
assert len(solid_angles_from_mock) == len(solid_angles_from_src)
344+
345+
assert np.allclose(
346+
patch_decomposition_from_mock, patch_decomposition_from_src, rtol=1e-4
347+
)
348+
assert np.allclose(sky_frac_from_mock, sky_frac_from_src, rtol=1e-4)
349+
assert np.allclose(solid_angles_from_mock, solid_angles_from_src, rtol=1e-4)
350+
except AssertionError:
351+
s = f"Inconsistency between {fn} and file stored in source code"
352+
msg.append(s)
353+
334354
return msg
335355

336356

diffsky/data_loaders/hacc_utils/lc_mock.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ def load_diffsky_param_collection_merging(drn_mock, mock_version_name):
227227
return param_collection
228228

229229

230+
def infer_lc_patch_stepnum_from_bname(bn_mock):
231+
stepnum, lc_patch = bn_mock.split("-")[1].split(".")[:2]
232+
return int(stepnum), int(lc_patch)
233+
234+
230235
def write_diffsky_param_collection(drn_mock, mock_version_name, param_collection):
231236
""""""
232237
bn = BNPAT_PARAM_COLLECTION.format(mock_version_name)

diffsky/data_loaders/hacc_utils/tests/test_lc_mock.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,15 @@ def test_add_dbk_phot_quantities_to_mock():
220220
getattr(fbulge_params, pname),
221221
rtol=0.01,
222222
)
223+
224+
225+
def test_infer_lc_patch_stepnum_from_bname():
226+
bn = "lc_cores-453.0.diffsky_gals.synthetic_halos.hdf5"
227+
stepnum, lc_patch = lcmp_repro.infer_lc_patch_stepnum_from_bname(bn)
228+
assert stepnum == 453
229+
assert lc_patch == 0
230+
231+
bn = "lc_cores-453.0.diffsky_gals.hdf5"
232+
stepnum, lc_patch = lcmp_repro.infer_lc_patch_stepnum_from_bname(bn)
233+
assert stepnum == 453
234+
assert lc_patch == 0

diffsky/experimental/lc_utils.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def mc_lightcone_random_ra_dec(ran_key, npts, ra_min, ra_max, dec_min, dec_max):
4444
Random coords on the sphere within the input range
4545
4646
"""
47-
phi_min = jnp.deg2rad(ra_min)
48-
phi_max = jnp.deg2rad(ra_max)
49-
50-
theta_min = jnp.deg2rad(90.0 - dec_max)
51-
theta_max = jnp.deg2rad(90.0 - dec_min)
47+
theta_min, theta_max, phi_min, phi_max = _get_theta_phi_minmax_from_ra_dec_minmax(
48+
ra_min, ra_max, dec_min, dec_max
49+
)
5250

5351
theta, phi = mc_lightcone_random_theta_phi(
5452
ran_key, npts, theta_min, theta_max, phi_min, phi_max
@@ -58,6 +56,28 @@ def mc_lightcone_random_ra_dec(ran_key, npts, ra_min, ra_max, dec_min, dec_max):
5856
return ra, dec
5957

6058

59+
@jjit
60+
def _get_ra_dec_minmax_from_theta_phi_minmax(theta_min, theta_max, phi_min, phi_max):
61+
ra_min = jnp.rad2deg(phi_min)
62+
ra_max = jnp.rad2deg(phi_max)
63+
64+
dec_min = 90.0 - jnp.rad2deg(theta_max)
65+
dec_max = 90.0 - jnp.rad2deg(theta_min)
66+
67+
return ra_min, ra_max, dec_min, dec_max
68+
69+
70+
@jjit
71+
def _get_theta_phi_minmax_from_ra_dec_minmax(ra_min, ra_max, dec_min, dec_max):
72+
phi_min = jnp.deg2rad(ra_min)
73+
phi_max = jnp.deg2rad(ra_max)
74+
75+
theta_min = jnp.deg2rad(90.0 - dec_max)
76+
theta_max = jnp.deg2rad(90.0 - dec_min)
77+
78+
return theta_min, theta_max, phi_min, phi_max
79+
80+
6181
@partial(jjit, static_argnames=["npts"])
6282
def mc_lightcone_random_theta_phi(
6383
ran_key, npts, theta_min, theta_max, phi_min, phi_max

diffsky/experimental/tests/test_lc_utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ def test_get_z_obs_from_z_true():
6060
dz = z_obs - z_true
6161
assert np.allclose(np.mean(dz), 0.0, atol=1e-3)
6262
assert np.std(z_obs - z_true) < 0.01
63+
64+
65+
def test_consistent_ra_dec_theta_phi_minmax():
66+
ran_key = jran.key(0)
67+
68+
n_tests = 1_000
69+
for __ in range(n_tests):
70+
ran_key, theta_key, phi_key = jran.split(ran_key, 3)
71+
theta_min, theta_max = np.sort(
72+
jran.uniform(theta_key, minval=0, maxval=np.pi, shape=(2,))
73+
)
74+
phi_min, phi_max = np.sort(
75+
jran.uniform(phi_key, minval=0, maxval=2 * np.pi, shape=(2,))
76+
)
77+
ra_min, ra_max, dec_min, dec_max = lcu._get_ra_dec_minmax_from_theta_phi_minmax(
78+
theta_min, theta_max, phi_min, phi_max
79+
)
80+
81+
assert np.all(ra_min < ra_max)
82+
assert np.all(ra_min >= 0.0)
83+
assert np.all(ra_min <= 360.0)
84+
assert np.all(ra_max >= 0.0)
85+
assert np.all(ra_max <= 360.0)
86+
87+
assert np.all(dec_min < dec_max)
88+
assert np.all(dec_min >= -90.0)
89+
assert np.all(dec_min <= 90.0)
90+
assert np.all(dec_max >= -90.0)
91+
assert np.all(dec_max <= 90.0)
92+
93+
theta_min2, theta_max2, phi_min2, phi_max2 = (
94+
lcu._get_theta_phi_minmax_from_ra_dec_minmax(
95+
ra_min, ra_max, dec_min, dec_max
96+
)
97+
)
98+
assert np.allclose(theta_min, theta_min2, rtol=1e-4)
99+
assert np.allclose(theta_max, theta_max2, rtol=1e-4)
100+
assert np.allclose(phi_min, phi_min2, rtol=1e-4)
101+
assert np.allclose(phi_max, phi_max2, rtol=1e-4)

scripts/LJ_LC_MOCKS/poboy_testing_lj_mock_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
machine: "poboy"
2-
z_min: 0.0
3-
z_max: 0.06
2+
z_min: 0.08
3+
z_max: 0.1
44
istart: 0
55
iend: 2
66
batch_size: 200

scripts/LJ_LC_MOCKS/testing_lj_mock_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ machine: "lcrc"
22
z_min: 0.08
33
z_max: 0.1
44
istart: 0
5-
iend: 1
5+
iend: 2
66
drn_out: "ci_test_output"
77
mock_nickname: "ci_test_mock"
88
cosmos_fit: "c260710"

0 commit comments

Comments
 (0)