CLASS Output¶
Complete workflow: configure CLASS, compute, wrap with ClassOutput, plot all observables.
Optional dependency
This example requires the classy Python package:
classy is an optional dependency.
Setup¶
from classy import Class
import cplots
cosmo = Class()
cosmo.set({
"h": 0.6736,
"Omega_b": 0.02237,
"Omega_cdm": 0.1200,
"A_s": 2.100e-9,
"n_s": 0.9649,
"tau_reio": 0.0544,
"output": "tCl pCl lCl mPk",
"lensing": "yes",
"P_k_max_h/Mpc": 1.0,
"z_max_pk": 2.0,
"l_max_scalars": 2500,
})
cosmo.compute()
out = cplots.ClassOutput(cosmo)
Background evolution¶
Plot only H(z) and luminosity distance:
bg = out.background(
quantities=["H [1/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:
Multiple redshifts on the same axes:
import cplots
fig = cplots.Figure()
for z in [0.0, 0.5, 1.0, 2.0]:
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²:
Primordial power spectrum¶
Thermodynamics¶
Visibility function against redshift:
Multiple thermodynamic quantities:
thermo = out.thermodynamics(quantities=["g [Mpc^-1]", "Tb [K]"])
cplots.BackgroundEvolution(thermo).show()
Cleanup¶
Always free CLASS memory when done: