Skip to content

Commit

Permalink
Useful error for transfer functions with non-monotonic scale factors (#…
Browse files Browse the repository at this point in the history
…971)

* fix 823
  • Loading branch information
damonge committed Aug 5, 2022
1 parent ec71862 commit aad5346
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pyccl/tests/test_tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,19 @@ def test_tracer_magnification_kernel_spline_vs_gsl_intergation(z_min, z_max,
if z_min > 0:
assert n[0] > 0

cosmo.cosmo.gsl_params.LENSING_KERNEL_SPLINE_INTEGRATION = True
ccl.gsl_params.LENSING_KERNEL_SPLINE_INTEGRATION = True
tr_mg = ccl.NumberCountsTracer(cosmo, False, dndz=(z, n),
bias=(z, b), mag_bias=(z, b))
w_mg_spline, _ = tr_mg.get_kernel(chi=None)
ccl.gsl_params.reload()

cosmo.cosmo.gsl_params.LENSING_KERNEL_SPLINE_INTEGRATION = False
ccl.gsl_params.LENSING_KERNEL_SPLINE_INTEGRATION = True
tr_mg = ccl.NumberCountsTracer(cosmo, False, dndz=(z, n),
bias=(z, b), mag_bias=(z, b))
w_mg_gsl, chi = tr_mg.get_kernel(chi=None)
tr_wl = ccl.WeakLensingTracer(cosmo, dndz=(z, n))
w_wl_gsl, _ = tr_wl.get_kernel(chi=None)
ccl.gsl_params.reload()

# Peak of kernel is ~1e-5
if n_z_samples >= 1000:
Expand Down Expand Up @@ -370,3 +372,17 @@ def test_tracer_chi_min_max():
tr.add_tracer(COSMO, kernel=(chi, wchi))
assert tr.chi_min == tr._trc[0].chi_min
assert tr.chi_max == tr._trc[1].chi_max


def test_tracer_increase_sf():
z = np.linspace(0, 3., 32)
one = np.ones(len(z))
chi = ccl.comoving_radial_distance(COSMO, 1./(1+z))
sf = 1./(1+z)
tr = ccl.Tracer()
with pytest.raises(ValueError):
tr.add_tracer(COSMO, kernel=(chi, one),
transfer_a=(sf, one))
# Check it works in the right order
tr.add_tracer(COSMO, kernel=(chi, one),
transfer_a=(sf[::-1], one))
4 changes: 4 additions & 0 deletions pyccl/tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ def add_tracer(self, cosmo, kernel=None,
ta_s = NoneArr
tk_s = NoneArr

if not (np.diff(a_s) > 0).all():
raise ValueError("Scale factor must be monotonically "
"increasing")

status = 0
ret = lib.cl_tracer_t_new_wrapper(cosmo.cosmo,
int(der_bessel),
Expand Down

0 comments on commit aad5346

Please sign in to comment.