Skip to content

Commit

Permalink
Check for range of background splines when using halofit with wa != 0. (
Browse files Browse the repository at this point in the history
#957)

* Check for range of background splines when using halofit with wa != 0.

* Make sure distances are computed.
  • Loading branch information
tilmantroester committed Aug 2, 2022
1 parent 8ab4e64 commit 70d2bbe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pyccl/pk2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from . import ccllib as lib

from .errors import CCLWarning
from .pyutils import check, _get_spline2d_arrays
from .errors import CCLError, CCLWarning
from .pyutils import check, _get_spline1d_arrays, _get_spline2d_arrays


class Pk2D(object):
Expand Down Expand Up @@ -170,6 +170,21 @@ def apply_halofit(Pk2D, cosmo, pk_linear):
pk_linear (:class:`Pk2D`): a :class:`Pk2D` object containing
the linear power spectrum to transform.
"""
if cosmo["wa"] != 0:
# HALOFIT translates (w0, wa) to a w0_eff. This requires computing
# the comoving distance to the CMB, which requires the background
# splines being sampled to sufficiently high redshifts.
cosmo.compute_distances()
_, a = _get_spline1d_arrays(cosmo.cosmo.data.achi)
if min(a) > 1/(1 + 3000):
raise CCLError("Comoving distance spline does not cover "
"sufficiently high redshifts for HALOFIT. "
"HALOFIT translates (w0, wa) to a w0_eff. This "
"requires computing the comoving distance to "
"the CMB, which requires the background "
"splines being sampled to sufficiently high "
"redshifts. If using the calculator mode, "
"check the support of the background data.")
pk2d = Pk2D(empty=True)
status = 0
ret = lib.apply_halofit(cosmo.cosmo, pk_linear.psp, status)
Expand Down
21 changes: 21 additions & 0 deletions pyccl/tests/test_halofit_highz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pyccl as ccl
import pytest

from pyccl.errors import CCLError

COSMO = ccl.Cosmology(
Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96,
transfer_function='bbks', matter_power_spectrum='halofit')
Expand Down Expand Up @@ -29,3 +31,22 @@ def test_halofit_highz(cosmo):
)

assert np.all(pkratl >= pkrath), (zl, zh, pkratl, pkrath)


def test_halofit_background_check():
cosmo = ccl.Cosmology(Omega_c=0.25, Omega_b=0.05, h=0.7,
n_s=0.97,
sigma8=0.8,
w0=-1.04, wa=-0.1,
matter_power_spectrum="halofit",
transfer_function="eisenstein_hu")

cosmo.cosmo.spline_params.A_SPLINE_MIN = 0.4
cosmo.cosmo.spline_params.A_SPLINE_MINLOG = 0.3
cosmo.cosmo.spline_params.A_SPLINE_MIN_PK = 0.4
cosmo.cosmo.spline_params.A_SPLINE_MINLOG_PK = 0.3

k = np.geomspace(1e-3, 1, 10)

with pytest.raises(CCLError):
ccl.nonlin_matter_power(cosmo, k, a=0.5)

0 comments on commit 70d2bbe

Please sign in to comment.