hmfast.cosmology.Cosmology
- class hmfast.cosmology.Cosmology(emulator_set='lcdm:v1', H0=68.0, omega_cdm=0.12, omega_b=0.02246576, A_s=2.1053e-09, n_s=0.965, tau=0.0544, m_ncdm=0.06, N_ur=3.046, w0=-0.95, f_ede=0.1, z_c=3162.278, theta_i=1.57, r=0.01, T_cmb=2.7255, deg_ncdm=1.0)[source]
Bases:
objectCosmology model and emulator interface.
Provides access to cosmological parameters and emulator-based predictions for distances, Hubble parameter, power spectra, CMB spectra, and derived parameters. Note that using parameters outside the emulator training bounds will result in NaN outputs.
- Attributes:
- emulator_setstr
Emulator-set identifier selecting the corresponding emulator set. Allowed values are
"lcdm:v1","mnu:v1","neff:v1","wcdm:v1","ede:v1","mnu-3states:v1", and"ede:v2".- H0float
Hubble constant at \(z = 0\) in units of \(\mathrm{km} \, \mathrm{s}^{-1} \, \mathrm{Mpc}^{-1}\).
- omega_cdmfloat
Physical cold dark matter density, \(\omega_{\mathrm{cdm}} = \Omega_{\mathrm{cdm}} h^2\).
- omega_bfloat
Physical baryon density, \(\omega_b = \Omega_b h^2\).
- A_sfloat
Amplitude of the primordial scalar power spectrum, \(A_s\).
- n_sfloat
Scalar spectral index of primordial perturbations, \(n_s\).
- taufloat
Optical depth to reionization, \(\tau\).
- m_ncdmfloat
Total non-cold dark matter mass, used if a massive-neutrino cosmological model is selected.
- N_urfloat
Effective number of ultra-relativistic species, \(N_{\mathrm{ur}}\), used if a model with additional radiation degrees of freedom is selected.
- w0float
Present-day dark energy equation-of-state parameter \(w_0\), used if a cosmological model with dark energy equation-of-state parameter \(w_0\) is selected.
- f_edefloat
Maximum fractional contribution of early dark energy, \(f_{\mathrm{ede}}\), used if an early dark energy cosmological model is selected.
- z_cfloat
Critical redshift for the early dark energy transition, \(z_c\), used if an early dark energy cosmological model is selected.
- theta_ifloat
Initial scalar field displacement for the early dark energy model, \(\theta_i\), in radians, used if an early dark energy cosmological model is selected.
- rfloat
Tensor-to-scalar ratio, used if a cosmological model including primordial tensors is selected.
- T_cmbfloat
CMB temperature today in Kelvin, used when non-emulator background quantities require it.
- deg_ncdmfloat
Degeneracy factor for the non-cold dark matter species, used if a massive-neutrino cosmological model is selected.
Methods
Get angular diameter distance \(D_A(z)\) at redshift \(z\) from the emulator.
cl(type, l)Evaluate the CMB power spectrum of the specified type at requested multipoles l using the emulator.
Comoving volume element per unit redshift and solid angle.
Get critical density \(\rho_{\mathrm{crit}}(z)\) at redshift \(z\).
delta_c(z[, prescription])Spherical-collapse threshold \(\delta_c(z)\).
Get derived cosmological parameters from the emulator.
Linear growth factor \(D(z)\), normalized to \(D(0)=1\).
growth_rate(z)Linear growth rate
Get Hubble parameter \(H(z)\) at redshift \(z\) from the emulator.
omega_m(z)Matter density parameter excluding neutrinos.
pk(k, z[, linear])Get the matter power spectrum \(P(k, z)\) interpolated at requested wavenumbers k and redshifts z.
sigma8(z)Get \(\sigma_8(z)\) at redshift \(z\) from the emulator.
sigma_m(m, z)Evaluate \(\sigma(M, z)\) on a physical mass-redshift grid.
sigma_r(r, z)Evaluate \(\sigma(R, z)\) on a physical radius-redshift grid.
update([H0, omega_cdm, omega_b, A_s, n_s, ...])Return a new Cosmology instance with updated parameters.
Compute the dimensionless velocity dispersion
- update(H0=None, omega_cdm=None, omega_b=None, A_s=None, n_s=None, tau=None, m_ncdm=None, N_ur=None, w0=None, f_ede=None, z_c=None, theta_i=None, r=None, T_cmb=None, deg_ncdm=None)[source]
Return a new Cosmology instance with updated parameters.
Each parameter defaults to None. Only those not None are updated.
- Parameters:
- H0, omega_cdm, omega_b, A_s, n_s, tau, m_ncdm, N_ur, w0, f_ede, z_c, theta_i, r, T_cmb, deg_ncdmfloat or None
Cosmological parameters to update. In particular, \(\tau\) is the optical depth to reionization and \(\theta_i\) is the initial early-dark-energy scalar field displacement.
- Returns:
- Cosmology
New instance with updated parameters.
- sigma_m(m, z)[source]
Evaluate \(\sigma(M, z)\) on a physical mass-redshift grid.
The variance is defined by
\[\sigma^2(M, z) = \frac{1}{2\pi^2} \int_0^\infty dk\, k^2\, P_{\mathrm{L}}(k, z)\, \hat{W}^2(kR),\]with Fourier-space top-hat window
\[\hat{W}(x) = \frac{3}{x^3}\left[\sin x - x \cos x\right].\]- Parameters:
- mfloat or jnp.ndarray
Halo mass or mass grid in physical \(M_\odot\).
- zfloat or jnp.ndarray
Redshift or redshift grid.
- Returns:
- float or jnp.ndarray
Values of \(\sigma(M, z)\) with shape \((N_m, N_z)\), where singleton dimensions get squeezed before return.
- sigma_r(r, z)[source]
Evaluate \(\sigma(R, z)\) on a physical radius-redshift grid.
The variance is defined by
\[\sigma^2(R, z) = \frac{1}{2\pi^2} \int_0^\infty dk\, k^2\, P_{\mathrm{L}}(k, z)\, \hat{W}^2(kR),\]with Fourier-space top-hat window
\[\hat{W}(x) = \frac{3}{x^3}\left[\sin x - x \cos x\right].\]- Parameters:
- rfloat or jnp.ndarray
Comoving top-hat radius or radius grid in physical \(\mathrm{Mpc}\).
- zfloat or jnp.ndarray
Redshift or redshift grid.
- Returns:
- float or jnp.ndarray
Values of \(\sigma(R, z)\) with shape \((N_r, N_z)\), where singleton dimensions get squeezed before return.
- hubble_parameter(z)[source]
Get Hubble parameter \(H(z)\) at redshift \(z\) from the emulator.
- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Hubble parameter(s) in \(\mathrm{km} \, \mathrm{s}^{-1} \, \mathrm{Mpc}^{-1}\)
- angular_diameter_distance(z)[source]
Get angular diameter distance \(D_A(z)\) at redshift \(z\) from the emulator.
- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Angular diameter distance(s) in \(\mathrm{Mpc}\).
- sigma8(z)[source]
Get \(\sigma_8(z)\) at redshift \(z\) from the emulator.
\(\sigma_8(z)\) is the dimensionless root-mean-square linear matter fluctuation amplitude in spheres of radius \(8 \, \mathrm{Mpc}/h\).
- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Dimensionless \(\sigma_8\) value(s)
- critical_density(z)[source]
Get critical density \(\rho_{\mathrm{crit}}(z)\) at redshift \(z\).
\[\rho_{\mathrm{crit}}(z) = \frac{3 H(z)^2}{8 \pi G}\]- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Critical density in \(M_\odot \, \mathrm{Mpc}^{-3}\)
- omega_m(z)[source]
Matter density parameter excluding neutrinos.
\[\Omega_m(z) = \frac{\Omega_{m,\mathrm{no\nu},0}(1+z)^3}{\Omega_{m,0}(1+z)^3 + \Omega_{\Lambda,0} + \Omega_{r,0}(1+z)^4}\]- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- float or jnp.ndarray
Dimensionless matter density at redshift \(z\)
- delta_c(z, prescription='EdS')[source]
Spherical-collapse threshold \(\delta_c(z)\).
Supported prescriptions are:
"EdS"for the Einstein-de Sitter exact value, \(\delta_c = \frac{3}{20}(12\pi)^{2/3}\)."EdS_approx"for the standard Einstein-de Sitter approximation, \(\delta_c = 1.686\)."NS97"for the Nakamura and Suto (1997) fit,\[\delta_c(z) = \frac{3}{20}(12\pi)^{2/3} \left[1 + 0.012299 \, \log_{10}(\Omega_m(z))\right].\]
- Parameters:
- zfloat or jnp.ndarray
Redshift(s).
- prescriptionstr, optional
Collapse-threshold prescription. Supported values are
"EdS","EdS_approx", and"NS97". Input is case-insensitive.
- Returns:
- float or jnp.ndarray
Collapse threshold evaluated at \(z\).
- growth_factor(z)[source]
Linear growth factor \(D(z)\), normalized to \(D(0)=1\).
- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Dimensionless linear growth factor at \(z\), with shape \((N_z,)\), where singleton dimensions get squeezed before return.
- growth_rate(z)[source]
Linear growth rate
\[f(z) = \frac{d \ln D}{d \ln a}\]- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Dimensionless linear growth rate at \(z\), with shape \((N_z,)\), where singleton dimensions get squeezed before return.
- velocity_dispersion(z)[source]
Compute the dimensionless velocity dispersion
\[\frac{1}{3} \frac{v_\mathrm{rms}^2}{c^2}\]from the linear growth factor and matter power spectrum.
- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- jnp.ndarray
Dimensionless velocity dispersion at \(z\), equal to \(\frac{1}{3} \frac{v_\mathrm{rms}^2}{c^2}\), with shape \((N_z,)\), where singleton dimensions get squeezed before return.
- comoving_volume_element(z)[source]
Comoving volume element per unit redshift and solid angle.
\[\frac{dV}{dz\,d\Omega} = \frac{(1+z)^2\, D_A(z)^2 \, c}{H(z)}\]- Parameters:
- zfloat or jnp.ndarray
Redshift(s)
- Returns:
- float or jnp.ndarray
\(\frac{dV}{dz\,d\Omega}\) in \(\mathrm{Mpc}^3 \, \mathrm{sr}^{-1}\)
- pk(k, z, linear=True)[source]
Get the matter power spectrum \(P(k, z)\) interpolated at requested wavenumbers k and redshifts z.
- Parameters:
- kfloat or jnp.ndarray
Wavenumber(s) in \(\mathrm{Mpc}^{-1}\) to evaluate the power spectrum at.
- zfloat or jnp.ndarray
Redshift(s) at which to evaluate the power spectrum.
- linearbool
True for linear \(P(k)\), False for nonlinear \(P(k)\).
- Returns:
- Pjnp.ndarray
Power spectrum values with shape \((N_k, N_z)\), where singleton dimensions get squeezed before return.
- cl(type, l)[source]
Evaluate the CMB power spectrum of the specified type at requested multipoles l using the emulator. This method can be used to evaluate \(C_\ell^{TT}\), \(C_\ell^{EE}\), \(C_\ell^{TE}\), and \(C_\ell^{\phi\phi}\) by passing the appropriate type argument.
- Parameters:
- typestr
Power-spectrum specifier, e.g. ‘TT’, ‘EE’, ‘TE’, or ‘PP’. Case-insensitive.
- lint or array-like
Multipole(s) at which to evaluate C_ell.
- Returns:
- jnp.ndarray
C_ell for the requested type evaluated at l. Out-of-range l return NaN.
- derived_parameters()[source]
Get derived cosmological parameters from the emulator.
- Returns:
- dict
Dictionary of derived parameters with the following keys:
‘100*theta_s’ : Sound horizon angle (in units of 1/100 radians)
‘sigma8’ : Dimensionless RMS linear matter fluctuation in 8 Mpc/h spheres
‘YHe’ : Primordial helium fraction
‘z_reio’ : Redshift of reionization
‘Neff’ : Effective number of relativistic species
‘tau_rec’ : Conformal time at recombination (maximum visibility)
‘z_rec’ : Redshift at recombination (maximum visibility)
‘rs_rec’ : Comoving sound horizon at recombination [Mpc]
‘chi_rec’ : Comoving distance to recombination [Mpc]
‘tau_star’ : Conformal time at last scattering (optical depth = 1)
‘z_star’ : Redshift at last scattering (optical depth = 1)
‘rs_star’ : Comoving sound horizon at last scattering [Mpc]
‘chi_star’ : Comoving distance to last scattering [Mpc]
‘rs_drag’ : Comoving sound horizon at baryon drag [Mpc]