abcmb.background module

class abcmb.background.Background(pre_BG, recomb_output, params, ReionModel)[source]

Bases: BackgroundPreRecomb

Full Background cosmology module for cosmological calculations.

Inherits all cosmology fields and methods from BackgroundPreRecomb. Construction takes a BackgroundPreRecomb and the recombination output from HyRex, then applies reionization and integrates the optical depth.

This factorization allows HyRex to always run on CPU (its faster backend).

Attributes:

  • species_list tuple

    A list of all fluids in the cosmology

  • lna_tau_tab jnp.array

    Log scale factor axis used to tabulate conformal time

  • tau_tab jnp.array

    Tabulated conformal time.

  • tau0 float

    Conformal time today in Mpc.

  • recomb_inputs RecombInputs

    Bundle of background quantities (TCMB, nH, H) sampled on RecModel.lna_axis_full; consumed by HyRex.

  • adjoint diffrax.adjoint

    Adjoint mode for diffrax solves (static field).

  • xe_tab array_with_padding

    Tabulated free electron fraction xe with reionization correction.

  • lna_xe_tab array_with_padding

    Log scale factor axis corresponding to tabulated xe values.

  • Tm_tab array_with_padding

    Tabulated matter temperature Tm during recombination.

  • lna_Tm_tab array_with_padding

    Log scale factor axis corresponding to tabulated Tm values.

  • kappa_func diffrax.solution

    Optical depth function (dense interpolation).

  • z_reion float

    Redshift of hydrogen reionization in the CAMB parameterization.

  • tau_reion float

    Optical depth to reionization.

  • lna_rec float

    Log scale factor of recombination.

  • rA_rec float

    Comoving angular diameter distance at recombination in Mpc.

  • lna_transfer_start float

    Log scale factor at which to begin integrating transfer functions.

  • lna_visibility_stop float

    Log scale factor at which to stop integrating T1, T2, and E sources due to small visibility functions. Only used for l<400.

Methods:

  • rho_tot :

    Compute total energy density (units: eV cm^{-3})

  • P_tot :

    Compute total pressure (units: eV cm^{-3})

  • H :

    Compute Hubble parameter (units: s^{-1})

  • aH :

    Compute conformal Hubble parameter (units: Mpc^{-1})

  • aH_prime :

    Compute derivative of conformal Hubble (units: Mpc^{-1})

  • d2adtau2_over_a :

    Compute second derivative of scale factor (units: Mpc^{-2})

  • tau :

    Compute conformal time (units: Mpc)

  • xe :

    Compute free electron fraction (units: dimensionless)

  • Tm :

    Compute matter temperature (units: eV)

  • tau_c :

    Compute Thomson scattering time (units: Mpc)

  • expmkappa :

    Compute exp(-kappa) (units: dimensionless)

  • visibility :

    Compute visibility function (units: Mpc^{-1})

  • z_d :

    Compute baryon decoupling redshift (units: dimensionless)

  • rs_d :

    Compute sound horizon at decoupling (units: Mpc)

Tm(lna, params)[source]

Compute matter temperature.

Interpolates from pre-tabulated recombination history with early-time approximation and late-time boundary conditions.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Matter temperature (units: eV)

expmkappa(lna)[source]

Compute exp(-optical depth).

Interpolates from pre-tabulated optical depth history.

Parameters:

  • lna float

    Logarithm of scale factor

Returns:

float

exp(-(optical depth)) (units: dimensionless)

find_z_at_kappad_equals_one(z, kappa_d)[source]

Find redshift where baryon optical depth equals unity.

Interpolates to find z_d such that κ_d(z_d) = 1, marking the approximate time of baryon decoupling.

Parameters:

  • z array

    Redshift array

  • kappa_d array

    Baryon optical depth array

Returns:

float

Decoupling redshift (units: dimensionless)

interp_rs_at_z(z_bg, r_s, z_d)[source]

Interpolate sound horizon at decoupling redshift.

Parameters:

  • z_bg array

    Background redshift array

  • r_s array

    Sound horizon array

  • z_d float

    Decoupling redshift

Returns:

float

Sound horizon at decoupling (units: Mpc)

rs_d(params)[source]

Compute sound horizon at decoupling.

Finds value of sound horizon at baryon decoupling redshift z_d.

Parameters:

  • params dict

    Cosmological parameters

Returns:

float

Sound horizon at decoupling (units: Mpc)

tau_c(lna, params)[source]

Compute Thomson scattering time.

Calculates Thomson scattering time scale τc = 1/(a × ne × σT).

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Thomson scattering time (units: Mpc)

visibility(lna, params)[source]

Compute visibility function.

Calculates visibility function g(x) = -aH(x) × κ’(x) × exp(-κ(x)) where ‘ = d/dx and x = ln a. Represents probability that a CMB photon observed today was last scattered at time x.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Visibility function (units: Mpc^{-1})

Notes:

Used in computing source functions for CMB anisotropies.

xe(lna)[source]

Compute free electron fraction.

Interpolates from pre-tabulated recombination history with boundary conditions for early and late times.

Parameters:

  • lna float

    Logarithm of scale factor

Returns:

float

Free electron fraction (units: dimensionless)

Notes:

The logic flow is equivalent to:

if lna < self.lna_xe_tab.arr[0]: return self.xe_tab[0] elif lna > self.lna_xe_tab.lastval: return self.xe_tab.lastval else: return jnp.interp(lna, self.lna_xe_tab, self.xe_tab)

z_d(params)[source]

Compute baryon decoupling redshift.

Finds redshift where κ_d = 1 as estimate of when baryons decouple from photons.

Parameters:

  • params dict

    Cosmological parameters

Returns:

float

Decoupling redshift (units: dimensionless)

class abcmb.background.BackgroundPreRecomb(params, species_list, RecModel, adjoint=<class 'diffrax._adjoint.ForwardMode'>)[source]

Bases: Module

Pre-recombination background-cosmology object.

Holds everything HyRex needs to run on CPU: (conformal-time tabulation, species list, and HyRex input arrays via RecombInputs object).

Attributes:

  • species_list tuple

    A list of all fluids in the cosmology

  • lna_tau_tab jnp.array

    Log scale factor axis used to tabulate conformal time

  • tau_tab jnp.array

    Tabulated conformal time.

  • tau0 float

    Conformal time today in Mpc.

  • recomb_inputs RecombInputs

    Bundle of background quantities (TCMB, nH, H) sampled on RecModel.lna_axis_full; consumed by HyRex.

  • adjoint diffrax.adjoint

    Adjoint mode for diffrax solves (static field).

Methods:

  • rho_tot :

    Compute total energy density (units: eV cm^{-3})

  • P_tot :

    Compute total pressure (units: eV cm^{-3})

  • H :

    Compute Hubble parameter (units: s^{-1})

  • aH :

    Compute conformal Hubble parameter (units: Mpc^{-1})

  • aH_prime :

    Compute derivative of conformal Hubble (units: Mpc^{-1})

  • d2adtau2_over_a :

    Compute second derivative of scale factor (units: Mpc^{-2})

  • tau :

    Compute conformal time (units: Mpc)

  • nH :

    Compute hydrogen number density (units: cm^{-3})

  • TCMB :

    Compute CMB temperature (units: eV)

  • R_ratio_lna :

    Compute baryon drag ratio (units: dimensionless)

H(lna, params)[source]

Compute Hubble parameter.

Uses Einstein equation H = sqrt(8πG/3 ρ_tot) to account for novel species without well-defined density parameters.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Hubble parameter (units: s^{-1})

P_tot(lna, params)[source]

Compute total pressure.

Sums pressure over all species in the universe.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Total pressure (units: eV cm^{-3})

R_ratio_lna(lna, params)[source]

Compute baryon drag ratio.

Calculates R = 3ρ_b/(4ρ_γ), the ratio of baryon to photon energy densities that appears in baryon drag calculations.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Baryon drag ratio (units: dimensionless)

TCMB(lna, params)[source]

Compute CMB temperature.

Calculates CMB temperature at given redshift using T ∝ 1/a scaling.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

CMB temperature (units: eV)

aH(lna, params)[source]

Compute conformal Hubble parameter.

Calculates conformal Hubble H = a*H = da/dτ where τ is conformal time. Uses Mpc units for perturbation calculations.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Conformal Hubble parameter (units: Mpc^{-1})

aH_prime(lna, params)[source]

Compute derivative of conformal Hubble parameter.

Uses second Friedmann equation to compute d(aH)/d(ln a). See Eq.(20) of arXiv:9506072.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Derivative of conformal Hubble (units: Mpc^{-1})

d2adtau2_over_a(lna, params)[source]

Compute second derivative of scale factor.

Calculates d²a/dτ²/a where τ is conformal time. Appears in perturbation evolution equations.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Second derivative of scale factor (units: Mpc^{-2})

nH(lna, params)[source]

Compute hydrogen number density.

Calculates total hydrogen number density at given redshift.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Hydrogen number density (units: cm^{-3})

rho_tot(lna, params)[source]

Compute total energy density.

Sums energy density over all species in the universe.

Parameters:

  • lna float

    Logarithm of scale factor

  • params dict

    Cosmological parameters

Returns:

float

Total energy density (units: eV cm^{-3})

tau(lna)[source]

Compute conformal time.

Interpolates from pre-tabulated conformal time history. Conformal time τ satisfies dτ = dt/a where t is cosmic time.

Parameters:

  • lna float

    Logarithm of scale factor

Returns:

float

Conformal time (units: Mpc)

Notes:

IDEA: Make Background a repeatedly initiated module with both species_list and params stored. Upon initiation, a full history of conformal time is calculated with diffrax and stored for interpolation. This can be done by approximating early time with radiation approximation, and starting diffrax integration at the early time with appropriate initial conditions.

class abcmb.background.ReionizationModel(z_reion: float64, tau_reion: float64)[source]

Bases: Module

Object for computing the reionization correction to the free electron fraction. Provides the base methods

xe_reion : calculates the tanh electron fraction correction at redshifts lna, given z_reion and params tau_reion_fn : calculates the optical depth to reionization.

At the moment we only support the CAMB tanh parameterization, but we need different approaches based on whether the use inputs the optical depth tau_reion or the reionization redshift z_reion.

xe_reion(lna, z_reion, params)[source]

Passing in an lna array should get you the correct tanh patching based on the reionization parameter.

class abcmb.background.ReionizationModelFromTau(BG, params)[source]

Bases: ReionizationModel

Concrete extension of the base ReionizationModel Class. This object is used when the user inputs the optical depth and wishes to infer the redshift. The init finder will use an optimistix root finder to find the appropriate redshift. Then the appropriate tanh correction may be called and returned, as well as the inferred reionization redshift.

class abcmb.background.ReionizationModelFromZ(BG, params)[source]

Bases: ReionizationModel

Concrete extension of the base ReionizationModel Class. This object is used when the user direcly inputs the redshift of reionization. In this case the tanh correction and the optical depth can be computed directly, and simply returned.