Comparison with CLASS#
This notebook checks DISCO-CMB against CLASS for a flat \(\Lambda\)CDM cosmology with one massive neutrino and reionization. It compares the unlensed TT, TE and EE spectra, the lensing potential spectrum and the lensed TT, TE, EE and BB spectra.
CLASS (classy) and matplotlib are installed as part of the project’s dev group.
import matplotlib.pyplot as plt
import numpy as np
from classy import Class
from discoeb import LCDM_MNU
from discocmb import Grid, lensed_spectra, solve_cmb
L_CHECK = 2500 # the comparison stops here
The cosmology has one neutrino flavour of mass 0.06 eV beside 2.046 massless ones, and reionization at \(z_\mathrm{re} = 7.67\):
h = 0.67742
OMEGA_M, OMEGA_B = (
0.3099,
0.0488911,
) # matter (CDM and baryons, not the massive neutrino), and baryons
cosmology = LCDM_MNU.from_density_parameters(
Omega_m=OMEGA_M,
Omega_b=OMEGA_B,
H_0=100.0 * h,
A_s=2.1064e-9,
n_s=0.96822,
T_cmb=2.7255,
Y_He=0.248,
N_eff=2.046, # the massless flavours
N_mnu=1,
m_nu=0.06, # eV
z_re=7.67,
)
DISCO-CMB#
The default grid projects 125 multipoles to \(\ell = 3400\), and a spline gives every other one. Its solved modes reach \(3\,\mathrm{Mpc}^{-1}\) for the Limber integral of the lensing potential, and its distance grid stretches with each cosmology’s distance to last scattering. solve_cmb returns \(C_\ell\) in units of \(T_\mathrm{cmb}^2\), which lensed_spectra lenses with the Wigner tables of the grid.
grid = Grid.from_fiducial(cosmology)
ells, cl, _ = solve_cmb(cosmology, grid=grid)
lensed = lensed_spectra(cl, grid)
norm = (cosmology.T_cmb * 1.0e6) ** 2 # C_l in muK^2
disco = {
"unlensed": {
**{
name: norm * np.asarray(getattr(cl, name)[0]) for name in ("tt", "te", "ee")
},
"pp": np.asarray(cl.pp[0]),
},
"lensed": {
name: norm * np.asarray(getattr(lensed, name)[0])
for name in ("tt", "te", "ee", "bb")
},
}
CLASS#
CLASS runs the same cosmology with RECFAST and reio_camb, its implementation of CAMB’s tanh model of reionization, which DISCO-EB follows too. It gets the massive neutrino’s temperature \((4/11)^{1/3} T_\mathrm{cmb}\), which DISCO-EB uses exactly, and the massless flavours as N_ur. At its default time sampling of the sources CLASS’s own \(C_2^{\psi\psi}\) is 1.2 per cent low, so the sampling step is 0.01.
reference = Class()
reference.set(
{
"output": "tCl,pCl,lCl",
"lensing": "yes",
"l_max_scalars": grid.lmax + 100,
"h": h,
"Omega_b": OMEGA_B,
"omega_cdm": cosmology.omega_c,
"A_s": cosmology.A_s,
"n_s": cosmology.n_s,
"k_pivot": cosmology.k_p,
"T_cmb": cosmology.T_cmb,
"YHe": cosmology.Y_He,
"N_ur": cosmology.N_eff,
"N_ncdm": 1,
"m_ncdm": cosmology.m_nu,
"T_ncdm": (4.0 / 11.0) ** (1.0 / 3.0),
"recombination": "recfast",
"reio_parametrization": "reio_camb",
"z_reio": cosmology.z_re,
"perturbations_sampling_stepsize": 0.01,
}
)
reference.compute()
raw, lensed_class = reference.raw_cl(L_CHECK), reference.lensed_cl(L_CHECK)
classy = {
"unlensed": {
**{name: raw[name] * norm for name in ("tt", "te", "ee")},
"pp": raw["pp"],
},
"lensed": {name: lensed_class[name] * norm for name in ("tt", "te", "ee", "bb")},
}
Comparison#
The top rows show \(D_\ell = \ell(\ell+1) C_\ell / 2\pi\), and \([\ell(\ell+1)]^2 C_\ell^{\psi\psi} / 2\pi\) for the lensing potential. The bottom rows show the difference from CLASS in per cent of CLASS’s spectrum, and for TE, which crosses zero, in per cent of \(\sqrt{C_\ell^{TT} C_\ell^{EE}}\). The grey band is \(\pm 0.5\) per cent.
ell = np.arange(2, L_CHECK + 1)
def error(row: str, name: str) -> np.ndarray:
"""The difference from CLASS in per cent."""
ours, theirs = disco[row][name][ell], classy[row][name][ell]
if name == "te":
theirs_scale = np.sqrt(classy[row]["tt"][ell] * classy[row]["ee"][ell])
return 100.0 * (ours - theirs) / theirs_scale
return 100.0 * (ours / theirs - 1.0)
print(f"{'spectrum':>12} {'largest difference [%], l <= 2000':>34} {'l <= 2500':>10}")
for row in ("unlensed", "lensed"):
fig, axes = plt.subplots(2, 4, figsize=(14, 5), sharex=True, height_ratios=(2, 1))
for j, name in enumerate(disco[row]):
power = 2 if name == "pp" else 1
scale = (ell * (ell + 1.0)) ** power / (2.0 * np.pi)
axes[0, j].plot(
ell, scale * disco[row][name][ell], color="C0", label="DISCO-CMB"
)
axes[0, j].plot(
ell, scale * classy[row][name][ell], color="k", ls=":", lw=1, label="CLASS"
)
label = r"$\psi\psi$" if name == "pp" else name.upper()
axes[0, j].set_title(f"{row} {label}")
err = error(row, name)
axes[1, j].plot(ell, err, color="C0", lw=0.8)
axes[1, j].axhspan(-0.5, 0.5, color="gray", alpha=0.3)
axes[1, j].set_ylim(-2.0, 2.0)
axes[1, j].set_xscale("log")
axes[1, j].set_xlabel(r"$\ell$")
print(
f"{row + ' ' + name:>12} {np.abs(err[ell <= 2000]).max():34.2f} {np.abs(err).max():10.2f}"
)
axes[0, 0].legend(frameon=False)
axes[1, 0].set_ylabel("difference [%]")
fig.tight_layout()
plt.show()
spectrum largest difference [%], l <= 2000 l <= 2500
unlensed tt 0.17 0.18
unlensed te 0.22 0.22
unlensed ee 0.29 0.29
unlensed pp 0.24 0.24
lensed tt 0.12 0.15
lensed te 0.22 0.22
lensed ee 0.29 0.29
lensed bb 0.65 3.21
Every unlensed and lensed TT, TE and EE spectrum and the lensing potential lie within 0.3 per cent of CLASS to \(\ell = 2500\). Lensed BB is within 0.7 per cent to \(\ell = 2000\) and falls 3 per cent short at \(\ell = 2500\).