Skip to content

CAMB Output

Complete workflow: configure CAMB, compute, wrap with CambOutput, plot all observables.

Optional dependency

This example requires the camb Python package:

pip install cplots[camb]
The code blocks below show the actual calls verbatim but are not executed during the docs build because camb is an optional dependency.


Setup

import camb
import numpy as np
import cplots

pars = camb.set_params(
    H0=67.4, ombh2=0.022, omch2=0.12,
    mnu=0.06, omk=0, tau=0.054,
    As=2.1e-9, ns=0.965,
    lmax=2500,
    redshifts=[0.0, 0.5, 1.0],
    WantTransfer=True,
)
results = camb.get_results(pars)

out = cplots.CambOutput(results)

Background evolution

bg = out.background()
cplots.BackgroundEvolution(bg).show()

Plot only H(z) and luminosity distance:

bg = out.background(
    quantities=["H [km/s/Mpc]", "lum. dist."],
    labels={"lum. dist.": r"$d_L$ [Mpc]"},
)
cplots.BackgroundEvolution(bg).show()

Matter power spectrum

Linear P(k) at z=0 in h/Mpc units:

pk = out.pk(z=0.0, k_min=1e-4, k_max=1.0, n_k=300)
cplots.PKSpectrum(pk).show()

Because pk() uses an interpolator internally, z does not need to appear in the pre-computed redshift list passed to set_params:

fig = cplots.Figure()
for z in [0.0, 0.3, 0.7, 1.5]:
    pk = out.pk(z=z, n_k=300)
    fig.add(cplots.PKSpectrum(pk, label=f"z={z}"))
fig.show()

CMB angular power spectra

TT, EE, and TE spectra with the standard ℓ(ℓ+1)/2π scaling:

cls = out.cl(spectra=["tt", "ee", "te"], lensed=True, ell_factor=True)
cplots.ClSpectrum(cls).show()

Unlensed TT only, in K²:

cls = out.cl(spectra=["tt"], lensed=False, units="K2")
cplots.ClSpectrum(cls).show()

Primordial power spectrum

Computed analytically from the inflation parameters (As, ns, pivot_scalar) — no extra CAMB output flag needed:

prim = out.primordial()
cplots.PKSpectrum(prim).show()

Thermodynamics

Not available for CAMB

thermodynamics() raises NotImplementedError for CambOutput. CAMB does not expose a visibility table equivalent to CLASS's thermodynamics output. Use ClassOutput if you need thermodynamic background quantities.