Skip to content

Commit

Permalink
Add tests; Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsinfan1996 committed Aug 6, 2023
1 parent ec50ff2 commit 8d46860
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clmm/theory/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def __init__(
self.set_cosmo(None)

def _use_projected_quad(self, use_quad):
if hasattr(self.hdpm, '_projected_quad'):
if hasattr(self.hdpm, 'projected_quad'):
self.hdpm_opts["einasto"]["projected_quad"] = use_quad
self._update_halo_density_profile()
else:
raise NotImplementedError(
"_projected_quad is not available on this version of CCL.")
"projected_quad is not available on this version of CCL.")

# Functions implemented by child class

Expand Down
12 changes: 12 additions & 0 deletions tests/test_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ def test_profiles(modeling_data, profile_init):
assert_raises(
ValueError, mod.eval_excess_surface_density, 1e-12, cfg["SIGMA_PARAMS"]["z_cl"]
)
if mod.backend == "ccl" and profile_init == "einasto":
if hasattr(mod.hdpm, 'projected_quad'):
mod.use_projected_quad(True)
assert_allclose(
mod.eval_surface_density(
cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], verbose=True
),
cfg["numcosmo_profiles"]["Sigma"],
reltol*1e-1,
)
delattr(mod.hdpm, "projected_quad")
assert_raises(NotImplementedError, mod.use_projected_quad, True)

# Functional interface tests
# alpha_ein is None unless testing Einasto with the NC and CCL backend
Expand Down
26 changes: 26 additions & 0 deletions tests/test_theory_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_unimplemented(modeling_data):
assert_raises(NotImplementedError, mod._update_halo_density_profile)
assert_raises(NotImplementedError, mod._set_einasto_alpha, 0.5)
assert_raises(NotImplementedError, mod._get_einasto_alpha)
assert_raises(NotImplementedError, mod._use_projected_quad, True)
assert_raises(NotImplementedError, mod.eval_3d_density, [0.3], 0.3)
assert_raises(NotImplementedError, mod.eval_surface_density, [0.3], 0.3)
assert_raises(NotImplementedError, mod.eval_mean_surface_density, [0.3], 0.3)
Expand Down Expand Up @@ -91,6 +92,16 @@ def test_instantiate(modeling_data):
assert_raises(ValueError, mod.set_halo_density_profile, halo_profile_model="bla")
assert_raises(ValueError, mod.set_halo_density_profile, massdef="blu")

if theo.be_nick in ["nc", "ccl"]:
mod.set_halo_density_profile(massdef="virial")
assert_equal(mod.massdef, "virial")

# reset
mod.massdef = "mean"

mod.massdef = "virial"
assert_equal(mod.massdef, "virial")

if theo.be_nick == "nc":
import gi

Expand Down Expand Up @@ -150,3 +161,18 @@ def test_einasto(modeling_data):
mod.eval_reduced_tangential_shear(0.1, 0.1, 0.5, verbose=True)
mod.eval_magnification(0.1, 0.1, 0.5, verbose=True)
mod.eval_magnification_bias(0.1, 2, 0.1, 0.5, verbose=True)


def test_use_projected_quad(modeling_data):
"""Test use_projected_quad method"""
mod = theo.Modeling()
assert_raises(NotImplementedError, mod.use_projected_quad, True)

if theo.be_nick == "ccl":
assert_raises(NotImplementedError, mod.use_projected_quad, True)
mod.set_halo_density_profile("hernquist")
assert_raises(NotImplementedError, mod.use_projected_quad, True)
mod.set_halo_density_profile("einasto")
mod.use_projected_quad(True)
else:
assert_raises(NotImplementedError, mod.use_projected_quad, True)

0 comments on commit 8d46860

Please sign in to comment.