Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joezuntz committed Aug 13, 2024
2 parents 0fd28a0 + 5ce26de commit 1485d50
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- name: Install likelihood python dependencies from pip
shell: bash -l {0}
run: |
pip install "act_dr6_lenslike>=1.0.2"
pip install "act_dr6_lenslike>=1.0.2" "git+https://github.com/carronj/planck_PR4_lensing"
- name: Run Tests
shell: bash -l {0}
Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
python -m pip install --upgrade pip wheel setuptools
pip install "cosmosis==3.9.2" "nautilus-sampler==1.0.1" "scipy<1.14"
pip install -v --no-cache-dir --no-binary=mpi4py,camb mpi4py camb
pip install fitsio astropy fast-pt "Cython>=3.0" jupyter sacc
pip install fitsio astropy fast-pt "Cython>=3.0" jupyter sacc "git+https://github.com/carronj/planck_PR4_lensing"
- name: Install likelihood python dependencies
run: |
Expand Down
7 changes: 7 additions & 0 deletions examples/npipe-priors.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[cosmological_parameters]
n_s = gaussian 0.96 0.02
ombh2 = gaussian 0.0222 0.0005


[planck]
a_planck = gaussian 1.0 0.0025
42 changes: 42 additions & 0 deletions examples/npipe-values.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[planck]
a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels


[cosmological_parameters]
cosmomc_theta = 0.9 1.040909 1.2 ; this is actually 100 * theta_mc
;h0 = 0.4 0.7 1.0
omch2 = 0.05 0.12 0.2
log1e10As = 2.9 3.0448 3.1 ; structure amplitude parameter

ombh2 = 0.020 0.0222 0.025
n_s = 0.9 0.96 1.02


omega_k = 0.0 ;spatial curvature

;reionization
tau = 0.055 ;reionization optical depth


;neutrinos
mnu = 0.06
nnu = 3.046
num_massive_neutrinos = 1

;helium
yhe = 0.245341 ;helium mass fraction


k_s = 0.05 ;Power spectrum pivot scale
n_run = 0.0 ;running of scalar spectrum
r_t = 0.0 ;tensor to scalar ratio
n_t = 0.0 ;tensor spectral index

;dark energy equation of state
w = -1.0 ;equation of state of dark energy
wa = 0.0 ;equation of state of dark energy (redshift dependency)


[halo_model_parameters]
A = 3.13
eta = 0.603
59 changes: 59 additions & 0 deletions examples/npipe.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[runtime]
sampler = test
root = ${PWD}
verbosity = standard

[nautilus]
n_live = 1000
verbose = T



[test]
save_dir=output/npipe
fatal_errors=T


[output]
filename = output/npipe.txt

[DEFAULT]
; This value is used below as %(planck_path)s
planck_path = likelihood/planck2018/baseline/plc_3.0


[pipeline]
; these names refer to sections later in the file:
modules = consistency camb planck_npipe
values = examples/npipe-values.ini
priors = examples/npipe-priors.ini
debug=T
timing=F
extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m cosmological_parameters/h0

[planck_npipe]
;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE)
;without CMB lensing
file = likelihood/planck-npipe/npipe_interface.py
use_marginalized = T

; The consistency module translates between our chosen parameterization
; and any other that modules in the pipeline may want (e.g. camb)
[consistency]
file = ./utility/consistency/consistency_interface.py
cosmomc_theta = T


[camb]
file = boltzmann/camb/camb_interface.py
mode = cmb
lmax = 2800 ;max ell to use for cmb calculation
feedback=0 ;amount of output to print
AccuracyBoost=1.1 ;CAMB accuracy boost parameter
do_tensors = True ;include tensor modes
do_lensing = true ;lensing is required w/ Planck data
NonLinear = lens
accurate_massive_neutrino_transfers = T
theta_H0_range = "40 100"
halofit_version = mead

49 changes: 49 additions & 0 deletions likelihood/planck-npipe/npipe_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from cosmosis.datablock import option_section
try:
from planckpr4lensing import PlanckPR4LensingMarged, PlanckPR4Lensing
except ImportError:
raise ImportError("Please install the planckpr4lensing with: pip install git+https://github.com/carronj/planck_PR4_lensing")
import numpy as np



def setup(options):
marged = options.get_bool(option_section, "use_marginalized", default=True)
if marged:
calculator = PlanckPR4LensingMarged()
print("Using primary CMB-marginalized PR4 likelihood. TT, EE, TE, BB, will not be used")
else:
calculator = PlanckPR4Lensing()
print("NOT using primary CMB-marginalized PR4 likelihood. TT, EE, TE, BB, will be used")
return calculator, marged



def execute(block, config):
calculator, marged = config
ell = block['cmb_cl', 'ell']
A = block['planck', 'a_planck']

# Convert from D_ell to the PP pre-factor, ell**2 (ell+1)**2 / 2pi
pp = block['cmb_cl', 'pp'] * ell * (ell + 1.)
cl = {"pp":pp}

# If we are not using the marginalized version, we need to provide the full set of Cls
# If we are using the marginalized version these are pre-marginalized over
if not marged:
cl["tt"] = block['cmb_cl', 'tt']
cl["te"] = block['cmb_cl', 'te']
cl["ee"] = block['cmb_cl', 'ee']
cl["bb"] = block['cmb_cl', 'bb']


# npipe wants to start at zero
if ell[0] == 2:
ell = np.concatenate([[0, 1], ell])
for key in cl:
cl[key] = np.concatenate([[0.0, 0.0], cl[key]])

block["likelihoods", "npipe_like"] = calculator.log_likelihood(cl, A_planck=A)


return 0
8 changes: 8 additions & 0 deletions tests/test_cosmosis_standard_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def test_hsc_real(capsys):
run_cosmosis("examples/hsc-y3-shear-real.ini")
check_likelihood(capsys, "-122.5")

def test_npipe(capsys):
try:
import planckpr4lensing
except ImportError:
pytest.skip("Planck PR4 lensing likelihood not found")
run_cosmosis("examples/npipe.ini")
check_likelihood(capsys, "-4.22", "-4.23")

def test_desi(capsys):
run_cosmosis("examples/desi.ini")
check_likelihood(capsys, "-11.25")

0 comments on commit 1485d50

Please sign in to comment.