abcmb.background module
- class abcmb.background.Background(pre_BG, recomb_output, params, ReionModel)[source]
Bases:
BackgroundPreRecombFull Background cosmology module for cosmological calculations.
Inherits all cosmology fields and methods from
BackgroundPreRecomb. Construction takes aBackgroundPreRecomband 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_listtupleA list of all fluids in the cosmology
lna_tau_tabjnp.arrayLog scale factor axis used to tabulate conformal time
tau_tabjnp.arrayTabulated conformal time.
tau0floatConformal time today in Mpc.
recomb_inputsRecombInputsBundle of background quantities (TCMB, nH, H) sampled on
RecModel.lna_axis_full; consumed by HyRex.
adjointdiffrax.adjointAdjoint mode for diffrax solves (static field).
xe_tabarray_with_paddingTabulated free electron fraction xe with reionization correction.
lna_xe_tabarray_with_paddingLog scale factor axis corresponding to tabulated xe values.
Tm_tabarray_with_paddingTabulated matter temperature Tm during recombination.
lna_Tm_tabarray_with_paddingLog scale factor axis corresponding to tabulated Tm values.
kappa_funcdiffrax.solutionOptical depth function (dense interpolation).
z_reionfloatRedshift of hydrogen reionization in the CAMB parameterization.
tau_reionfloatOptical depth to reionization.
lna_recfloatLog scale factor of recombination.
rA_recfloatComoving angular diameter distance at recombination in Mpc.
lna_transfer_startfloatLog scale factor at which to begin integrating transfer functions.
lna_visibility_stopfloatLog 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:
lnafloatLogarithm of scale factor
paramsdictCosmological parameters
Returns:
- float
Matter temperature (units: eV)
- expmkappa(lna)[source]
Compute exp(-optical depth).
Interpolates from pre-tabulated optical depth history.
Parameters:
lnafloatLogarithm 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:
zarrayRedshift array
kappa_darrayBaryon 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_bgarrayBackground redshift array
r_sarraySound horizon array
z_dfloatDecoupling 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:
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm 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)
- class abcmb.background.BackgroundPreRecomb(params, species_list, RecModel, adjoint=<class 'diffrax._adjoint.ForwardMode'>)[source]
Bases:
ModulePre-recombination background-cosmology object.
Holds everything HyRex needs to run on CPU: (conformal-time tabulation, species list, and HyRex input arrays via
RecombInputsobject).Attributes:
species_listtupleA list of all fluids in the cosmology
lna_tau_tabjnp.arrayLog scale factor axis used to tabulate conformal time
tau_tabjnp.arrayTabulated conformal time.
tau0floatConformal time today in Mpc.
recomb_inputsRecombInputsBundle of background quantities (TCMB, nH, H) sampled on
RecModel.lna_axis_full; consumed by HyRex.
adjointdiffrax.adjointAdjoint 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm of scale factor
paramsdictCosmological 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:
lnafloatLogarithm 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:
ModuleObject 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.
- class abcmb.background.ReionizationModelFromTau(BG, params)[source]
Bases:
ReionizationModelConcrete 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:
ReionizationModelConcrete 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.