Skip to content

Commit

Permalink
Merge pull request #857 from LSSTDESC/camb_DEmodel
Browse files Browse the repository at this point in the history
Camb dark energy model
  • Loading branch information
tassia-ferreira committed May 24, 2021
2 parents 66397c7 + 6f7ec26 commit d095320
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pyccl/boltzmann.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,20 @@ def get_camb_pk_lin(cosmo, nonlin=False):
cp.ombh2 * (camb.constants.COBE_CMBTemp / cp.TCMB) ** 3,
delta_neff)

camb_de_models = ['DarkEnergyPPF', 'ppf', 'DarkEnergyFluid', 'fluid']
camb_de_model = extra_camb_params.get('dark_energy_model', 'fluid')
if camb_de_model not in camb_de_models:
raise ValueError("The only dark energy models CCL supports with"
" camb are fluid and ppf.")
cp.set_classes(
dark_energy_model=camb.dark_energy.DarkEnergyFluid
dark_energy_model=camb_de_model
)

if camb_de_model not in camb_de_models[:2] and cosmo['wa'] and \
(cosmo['w0'] < -1 - 1e-6 or
1 + cosmo['w0'] + cosmo['wa'] < - 1e-6):
raise ValueError("If you want to use w crossing -1,"
" then please set the dark_energy_model to ppf.")
cp.DarkEnergy.set_params(
w=cosmo['w0'],
wa=cosmo['wa']
Expand Down Expand Up @@ -256,6 +267,13 @@ def get_isitgr_pk_lin(cosmo):
*e.args)
raise

# Get extra CAMB parameters that were specified
extra_camb_params = {}
try:
extra_camb_params = cosmo["extra_parameters"]["camb"]
except (KeyError, TypeError):
pass

# z sampling from CCL parameters
na = lib.get_pk_spline_na(cosmo.cosmo)
status = 0
Expand Down Expand Up @@ -318,7 +336,7 @@ def get_isitgr_pk_lin(cosmo):

delta_neff = cosmo['Neff'] - 3.046 # used for BBN YHe comps

# ISiTGR built on CAMB which defines a neutrino degeneracy
# ISiTGR built on CAMB which defines a neutrino degeneracy
# factor as T_i = g^(1/4)*T_nu
# where T_nu is the standard neutrino temperature from first order
# computations
Expand Down Expand Up @@ -351,9 +369,19 @@ def get_isitgr_pk_lin(cosmo):
cp.ombh2 * (isitgr.constants.COBE_CMBTemp / cp.TCMB) ** 3,
delta_neff)

camb_de_models = ['DarkEnergyPPF', 'ppf', 'DarkEnergyFluid', 'fluid']
camb_de_model = extra_camb_params.get('dark_energy_model', 'fluid')
if camb_de_model not in camb_de_models:
raise ValueError("The only dark energy models CCL supports with"
" camb are fluid and ppf.")
cp.set_classes(
dark_energy_model=isitgr.dark_energy.DarkEnergyFluid
dark_energy_model=camb_de_model
)
if camb_de_model not in camb_de_models[:2] and cosmo['wa'] and \
(cosmo['w0'] < -1 - 1e-6 or
1 + cosmo['w0'] + cosmo['wa'] < - 1e-6):
raise ValueError("If you want to use w crossing -1,"
" then please set the dark_energy_model to ppf.")
cp.DarkEnergy.set_params(
w=cosmo['w0'],
wa=cosmo['wa']
Expand Down
1 change: 1 addition & 0 deletions pyccl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class Cosmology(object):
* `HMCode_logT_AGN`
* `kmax`
* `lmax`
* `dark_energy_model`
Consult the CAMB documentation for their usage. These parameters are passed
in a :obj:`dict` to `extra_parameters` as::
Expand Down
22 changes: 22 additions & 0 deletions pyccl/tests/test_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,25 @@ def test_input_nonlin_raises():
nonlinear_model='halofit')
assert 'a:b' in cosmo_input._pk_nl
assert cosmo_input.has_nonlin_power


def test_camb_de_model():
"""Check that the dark energy model for CAMB has been properly defined."""
with pytest.raises(ValueError):
cosmo = ccl.CosmologyVanillaLCDM(
transfer_function='boltzmann_camb',
extra_parameters={"camb": {"dark_energy_model": "pf"}})
ccl.linear_matter_power(cosmo, 1, 1)

"""Check that w is not less than -1, if the chosen dark energy model for
CAMB is fluid."""
with pytest.raises(ValueError):
cosmo = ccl.CosmologyVanillaLCDM(
transfer_function='boltzmann_camb', w0=-1, wa=-1)
ccl.linear_matter_power(cosmo, 1, 1)

"""Check that ppf is running smoothly."""
cosmo = ccl.CosmologyVanillaLCDM(
transfer_function='boltzmann_camb', w0=-1, wa=-1,
extra_parameters={"camb": {"dark_energy_model": "ppf"}})
assert np.isfinite(ccl.linear_matter_power(cosmo, 1, 1))

0 comments on commit d095320

Please sign in to comment.