Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .recipes.binned_grid import GridBinnedClusterRecipe
from .recipes.binned_parent import BinnedClusterRecipe

__version__ = "1.0.2"
__version__ = "1.0.4"
18 changes: 16 additions & 2 deletions crow/recipes/binned_exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,10 @@ def evaluate_theory_prediction_lensing_profile(
self,
z_edges,
log_proxy_edges,
radius_centers,
distance_centers,
sky_area: float,
average_on: None | ClusterProperty = None,
distance_units: str = "mpc",
) -> float:
"""Evaluate the theory prediction for this cluster recipe.

Expand All @@ -320,7 +321,20 @@ def evaluate_theory_prediction_lensing_profile(
"""
assert len(log_proxy_edges) == 2, "log_proxy_edges should be size 2"
assert len(z_edges) == 2, "z_edges should be size 2"

if distance_units.lower() == "arcmin":
distance_centers_rad = distance_centers * np.pi / (180.0 * 60.0)
z_bin_mean = (z_edges[1] + z_edges[0]) / 2.0
a = 1.0 / (1.0 + z_bin_mean)
radius_centers = (
self.cluster_theory.cosmo.angular_diameter_distance(a)
* distance_centers_rad
)
elif distance_units.lower() == "mpc":
radius_centers = distance_centers
else:
raise ValueError(
f"Unknown distance_units='{distance_units}'. Expected 'arcmin' or 'mpc'."
)
if self.purity == None:
self.integrator.integral_bounds = [
self.mass_interval,
Expand Down
18 changes: 16 additions & 2 deletions crow/recipes/binned_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,28 @@ def evaluate_theory_prediction_lensing_profile(
self,
z_edges: tuple[float, float],
log_proxy_edges: tuple[float, float],
radius_centers: np.ndarray,
distance_centers: np.ndarray,
sky_area: float,
average_on: None | ClusterProperty = None,
distance_units: str = "mpc",
) -> float:
r"""Evaluate the theoretical prediction for the average lensing profile
(..:math:`\langle\Delta\Sigma(R)\rangle` or ..:math:`\langle g_t(R)\rangle`)
in the provided bin."""

if distance_units.lower() == "arcmin":
distance_centers_rad = distance_centers * np.pi / (180.0 * 60.0)
z_bin_mean = (z_edges[1] + z_edges[0]) / 2.0
a = 1.0 / (1.0 + z_bin_mean)
radius_centers = (
self.cluster_theory.cosmo.angular_diameter_distance(a)
* distance_centers_rad
)
elif distance_units.lower() == "mpc":
radius_centers = distance_centers
else:
raise ValueError(
f"Unknown distance_units='{distance_units}'. Expected 'arcmin' or 'mpc'."
)
if not (average_on & (ClusterProperty.DELTASIGMA | ClusterProperty.SHEAR)):
# Raise a ValueError if the necessary flags are not present
raise ValueError(
Expand Down
3 changes: 2 additions & 1 deletion crow/recipes/binned_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ def evaluate_theory_prediction_lensing_profile(
self,
z_edges,
mass_proxy_edges,
radius_centers,
distance_centers,
sky_area: float,
average_on: None | ClusterProperty = None,
distance_units: str = "mpc",
) -> float:
"""Evaluate the theory prediction for this cluster recipe.

Expand Down
52 changes: 52 additions & 0 deletions tests/test_recipe_binned_shear_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,58 @@ def test_evaluates_theory_prediction_returns_value(
assert prediction_c > 0


def test_evaluates_theory_prediction_different_bins(
binned_exact_deltasigma: ExactBinnedClusterRecipe,
binned_grid_gt: GridBinnedClusterRecipe,
):

mass_proxy_edges = (2, 5)
mass_proxy_edges_err = (2, 5, 6)
z_edges = (0.5, 1)
z_edges_err = (0.5, 1.0, 1.2)
radius_center = np.atleast_1d(1.5)
sky_area = 360**2
average_on = ClusterProperty.DELTASIGMA

z_bin_mean = (z_edges[1] + z_edges[0]) / 2.0
a = 1.0 / (1.0 + z_bin_mean)
angular_center_arcmin = (
radius_center
/ binned_exact_deltasigma.cluster_theory.cosmo.angular_diameter_distance(a)
* 180.0
/ np.pi
* 60.0
)
# test exact deltasigma
prediction_rad = binned_exact_deltasigma.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, radius_center, sky_area, average_on, "mpc"
)
prediction_ang = binned_exact_deltasigma.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, angular_center_arcmin, sky_area, average_on, "arcmin"
)
rel_tol = 1.0e-4
assert np.all(np.abs(prediction_rad - prediction_ang) < rel_tol)
# test grid reduced shear
average_on = ClusterProperty.SHEAR
prediction_rad = binned_grid_gt.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, radius_center, sky_area, average_on, "mpc"
)
prediction_ang = binned_grid_gt.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, angular_center_arcmin, sky_area, average_on, "arcmin"
)
rel_tol = 1.0e-4
assert np.all(np.abs(prediction_rad - prediction_ang) < rel_tol)

with pytest.raises(ValueError, match="Unknown distance_units='rad'"):
binned_exact_deltasigma.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, radius_center, sky_area, average_on, "rad"
)
with pytest.raises(ValueError, match="Unknown distance_units='rad'"):
binned_grid_gt.evaluate_theory_prediction_lensing_profile(
z_edges, mass_proxy_edges, radius_center, sky_area, average_on, "rad"
)


def test_grid_shear_matches_exact_within_tolerance(
binned_exact_deltasigma: ExactBinnedClusterRecipe,
binned_grid_deltasigma: GridBinnedClusterRecipe,
Expand Down