Table of Contents
Fetching ...

nanoCMB: A minimal CMB power spectrum calculator in Python

Adam Moss

TL;DR

NanoCMB is presented, a minimal but accurate calculator for the unlensed CMB temperature and polarisation angular power spectra of flat $\Lambda$CDM cosmologies, designed as a pedagogical bridge between textbook treatments and research-level Boltzmann solvers.

Abstract

We present nanoCMB, a minimal but accurate calculator for the unlensed CMB temperature and polarisation angular power spectra ($C_\ell^{TT}$, $C_\ell^{EE}$, $C_\ell^{TE}$) of flat $Λ$CDM cosmologies. Written in $\sim$1400 lines of readable Python, the code implements the full line-of-sight integration method: RECFAST recombination, coupled Einstein--Boltzmann perturbation equations in synchronous gauge with a tight-coupling approximation, precomputed spherical Bessel function tables, and optimally constructed non-uniform grids in wavenumber and conformal time. Despite its brevity, nanoCMB achieves sub-percent agreement with CAMB across the multipole range $2 \le \ell \le 2500$, running in $\sim$10 seconds on a modern laptop. The entire calculation lives in a single, easily modifiable Python script, designed as a pedagogical bridge between textbook treatments and research-level Boltzmann solvers, with every approximation and numerical choice made explicit. We describe the physics, equations, and computational methods in detail, with code snippets illustrating each stage of the calculation. The code is publicly available at https://github.com/adammoss/nanoCMB.

nanoCMB: A minimal CMB power spectrum calculator in Python

TL;DR

NanoCMB is presented, a minimal but accurate calculator for the unlensed CMB temperature and polarisation angular power spectra of flat CDM cosmologies, designed as a pedagogical bridge between textbook treatments and research-level Boltzmann solvers.

Abstract

We present nanoCMB, a minimal but accurate calculator for the unlensed CMB temperature and polarisation angular power spectra (, , ) of flat CDM cosmologies. Written in 1400 lines of readable Python, the code implements the full line-of-sight integration method: RECFAST recombination, coupled Einstein--Boltzmann perturbation equations in synchronous gauge with a tight-coupling approximation, precomputed spherical Bessel function tables, and optimally constructed non-uniform grids in wavenumber and conformal time. Despite its brevity, nanoCMB achieves sub-percent agreement with CAMB across the multipole range , running in 10 seconds on a modern laptop. The entire calculation lives in a single, easily modifiable Python script, designed as a pedagogical bridge between textbook treatments and research-level Boltzmann solvers, with every approximation and numerical choice made explicit. We describe the physics, equations, and computational methods in detail, with code snippets illustrating each stage of the calculation. The code is publicly available at https://github.com/adammoss/nanoCMB.
Paper Structure (46 sections, 39 equations, 8 figures, 5 tables)

This paper contains 46 sections, 39 equations, 8 figures, 5 tables.

Figures (8)

  • Figure 1: Hubble parameter comparison. Left:$H(z)$ from nanoCMB (red dashed) and CAMB (black solid). Right: ratio, showing agreement at the $10^{-4}$ level.
  • Figure 2: Thermodynamic quantities from nanoCMB (red dashed) compared to CAMB (black solid). Top row: ionisation fraction $x_e(z)$. Second row: reionisation window at $z < 30$. Third row: visibility function near recombination. Bottom row: Thomson opacity $\dot{\kappa}$. Right panels show ratios, demonstrating sub-percent agreement.
  • Figure 3: Perturbation evolution at $k = 0.05\,$Mpc$^{-1}$. Top panels show $\delta_\gamma$, $\delta_c$, $v_b$, $\delta_b$, $\pi_\gamma$, and $k\eta$ from nanoCMB (red dashed) and CAMB (black solid). Bottom panels show ratios, with the $\pm$1% band shaded.
  • Figure 4: Temperature transfer functions $\Delta_\ell^T(k)$ at four representative multipoles. Top panels show nanoCMB (red dashed) and CAMB (black solid); bottom panels show residuals.
  • Figure 5: Top panels: Node density $dN/d\ln k$ for the optimal (blue solid) and uniform-in-$\ln k$ (orange dashed) grids, for the ODE grid ($N = 200$, top) and $C_\ell$ grid ($N = 4000$, bottom). Vertical dotted lines mark the acoustic scale $1/r_s$ and the Silk damping scale $k_D$. Bottom panel:$TT$ RMS residual versus CAMB as a function of the number of ODE $k$-modes, showing the convergence advantage of the optimal grid.
  • ...and 3 more figures