Cosmology (spectroxide.cosmology)#
Flat ΛCDM background quantities, cosmology presets and the typed
Cosmology dataclass. The Green’s-function and PDE-table
modules pull from this module rather than redefining cosmology
themselves; users can either pass a Cosmology instance or a
plain dict with the same keys to anything that takes a cosmo=
argument.
Quick example#
from spectroxide.cosmology import (
Cosmology, hubble, cosmic_time, ionization_fraction,
DEFAULT_COSMO, PLANCK2018_COSMO,
)
# Background rates with the default (Chluba 2013) parameters
H = hubble(1e5) # 1/s
t = cosmic_time(1e5) # s
X_e = ionization_fraction(1100.0) # free electrons / H atom
# Use a typed Cosmology instance
p18 = Cosmology.planck2018()
H_p18 = hubble(1e5, p18.to_dict())
Flat ΛCDM background quantities.
Cosmology presets, the Hubble rate, photon and baryon densities, the Saha + Peebles three-level-atom recombination history, and helpers derived from them (free-electron density, baryon-photon ratio, cosmic time). The Green’s-function and PDE-table modules pull from this module rather than redefining cosmology themselves.
References
Peebles (1968), ApJ 153, 1.
Pequignot, Petitjean & Boisson (1991), A&A 251, 680 (case-B α).
Chluba & Thomas (2011), MNRAS 412, 748 (TLA fudge factor F = 1.125).
Planck Collaboration (2016), A&A 594, A13 (Planck 2015 parameters).
Planck Collaboration (2020), A&A 641, A6 (Planck 2018 VI parameters).
Cosmology dataclass#
Typed parameter container with class-method presets and a to_dict
helper for routines that expect a plain mapping.
Flat ΛCDM parameters. |
|
Chluba 2013 parameters (code default). |
|
Planck 2015 best-fit parameters. |
|
Planck 2018 best-fit parameters. |
|
Convert to a dict accepted by |
- class spectroxide.cosmology.Cosmology[source]#
Bases:
objectFlat ΛCDM parameters. Densities are fractions Ω, not ωh².
- Parameters:
Examples
>>> Cosmology.planck2018().h 0.6736
- Cosmology.to_dict()[source]#
Convert to a dict accepted by
spectroxide.solver.solve()(cosmo=) andspectroxide.solver.run_sweep()(cosmo_params=).
Presets#
Plain-dict cosmology presets. Each contains the keys h, omega_b,
omega_m, y_p, t_cmb, n_eff.
Preset |
Parameters |
|---|---|
|
Chluba (2013): h=0.71, Ω_b=0.044, Ω_m=0.26, Y_p=0.24, T_CMB=2.726, N_eff=3.046. |
|
Planck 2015 (matches CosmoTherm DI files): h=0.6727, Ω_b=0.04917, Ω_m=0.3139, Y_p=0.2467. |
|
Planck 2018 (Planck VI 2020, TT,TE,EE+lowE+lensing): h=0.6736, Ω_b=0.04930, Ω_m=0.3153, Y_p=0.2454. |
- spectroxide.cosmology.DEFAULT_COSMO = {'h': 0.71, 'n_eff': 3.046, 'omega_b': 0.044, 'omega_m': 0.26, 't_cmb': 2.726, 'y_p': 0.24}[source]#
Chluba (2013) Green’s-function paper parameters.
- spectroxide.cosmology.PLANCK2015_COSMO = {'h': 0.6727, 'n_eff': 3.046, 'omega_b': 0.049169, 'omega_m': 0.313906, 't_cmb': 2.726, 'y_p': 0.2467}[source]#
Planck 2015 (Planck XIII, Table 4).
T_CMBfollows CosmoTherm’s DI files (Fixsen 1996 = 2.726 K), not the Planck paper value 2.7255 K — use this for CT comparisons andCosmology.planck2015()otherwise.
Background quantities#
Flat ΛCDM Hubble rate, densities, and integrated quantities.
Hubble rate |
|
Cosmic time |
|
Photon energy density |
|
Present-day photon density parameter |
|
Hydrogen number density |
|
Free-electron number density |
|
Baryon-to-photon energy density ratio |
- spectroxide.cosmology.hubble(z, cosmo=None)[source]#
Hubble rate
H(z)for a flat ΛCDM background.\[H(z) = H_0 \sqrt{\Omega_m (1+z)^3 + \Omega_r (1+z)^4 + \Omega_\Lambda},\]with
Ω_rincluding the photon andN_effneutrino contributions.- Parameters:
z (float or array_like) – Redshift.
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.
- Returns:
float or ndarray of float64 – Hubble rate in inverse seconds (1/s).
- spectroxide.cosmology.cosmic_time(z, cosmo=None, z_upper=1000000000.0, n_points=128)[source]#
Cosmic time
t(z)by quadrature ofdt/dz = −1/((1+z) H(z)).Integrates from
z_upper(effectively early-time t = 0) down tozusing the midpoint rule inln(1+z).- Parameters:
z (float) – Redshift at which to evaluate
t(z).cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.z_upper (float, optional) – Upper integration limit (default
1e9). Increase for very early-Universe applications (e.g., neutrino decoupling).n_points (int, optional) – Number of quadrature points (default 128). Increase for higher accuracy at small
z.
- Returns:
float – Cosmic time in seconds (s).
- spectroxide.cosmology.rho_gamma(z, cosmo=None)[source]#
Photon energy density
ρ_γ(z) = (π²/15) (k_B T(z))⁴ / (ℏc)³.- Parameters:
z (float or array_like) – Redshift.
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.
- Returns:
float or ndarray of float64 – Photon energy density in J/m³.
- spectroxide.cosmology.omega_gamma(cosmo=None)[source]#
Present-day photon density parameter
Ω_γ.\[\Omega_\gamma = \rho_{\gamma,0} / \rho_{crit,0}, \qquad \rho_{\gamma,0} = \frac{\pi^2}{15} \frac{(k_B T_0)^4}{(\hbar c)^3}.\]- Parameters:
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.- Returns:
float – Dimensionless photon density parameter.
- spectroxide.cosmology.n_hydrogen(z, cosmo=None)[source]#
Hydrogen number density
n_H(z).Computed from the baryon density assuming primordial mass fraction
Y_pof helium:n_H(z) = (1 − Y_p) ρ_b(z) / m_p.- Parameters:
z (float or array_like) – Redshift.
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.
- Returns:
float or ndarray of float64 – Number density in 1/m³.
- spectroxide.cosmology.n_electron(z, cosmo=None, x_e=None)[source]#
Free-electron number density
n_e(z) = X_e(z) · n_H(z).- Parameters:
z (float or array_like) – Redshift.
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.x_e (float or array_like, optional) – Ionization fraction. If None (default), uses the cached Saha+Peebles recombination history from
ionization_fraction().
- Returns:
float or ndarray of float64 – Number density in 1/m³.
- spectroxide.cosmology.baryon_photon_ratio(z, cosmo=None)[source]#
Baryon-to-photon energy density ratio
R(z) = 3 ρ_b / (4 ρ_γ).Used in the photon-baryon sound speed and pre-recombination perturbation theory.
- Parameters:
z (float or array_like) – Redshift.
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.
- Returns:
float or ndarray of float64 – Dimensionless baryon-to-photon energy density ratio.
Recombination#
Free-electron fraction X_e(z): Saha for helium, Peebles three-level
atom for hydrogen with fudge factor F = 1.125 (Chluba & Thomas
2011). The ODE table is cached per cosmology.
Free-electron fraction |
- spectroxide.cosmology.ionization_fraction(z, cosmo=None)[source]#
Free-electron fraction
X_e(z) = n_e / n_H.Uses Saha equilibrium for helium (He II at 54.4 eV, He I at 24.6 eV) and the Peebles three-level atom ODE for hydrogen recombination, with fudge factor F = 1.125 (Chluba & Thomas 2011). The ODE table is cached per cosmology for fast repeated lookups.
- Parameters:
z (float or array_like) – Redshift(s).
cosmo (Mapping, optional) – Cosmological parameters. Defaults to
DEFAULT_COSMO.
- Returns:
float or ndarray of float64 – Total free-electron fraction (H + He) per hydrogen atom. Returns a Python float when
zis a scalar, otherwise an array shaped likez.