API Reference
This page provides the auto-generated documentation for the main classes.
Aletheia Emulator
- class aletheiacosmo.AletheiaEmu[source]
Bases:
objectEmulator for the non-linear matter power spectrum.
This class provides predictions for the non-linear matter power spectrum, P_NL(k), for a given cosmology and redshift. It is based on a set of Gaussian Process (GP) models trained on high-fidelity N-body simulations.
The emulation method combines a de-wiggled linear power spectrum with a GP prediction for the non-linear boost factor, B(k), and a response function, dR/dxtide, that captures the effects of different growth of structure histories.
- gp_B
The trained GP model for the non-linear boost factor.
- Type:
sklearn.gaussian_process.GaussianProcessRegressor
- gp_dRdx
The trained GP model for the response to xtilde.
- Type:
sklearn.gaussian_process.GaussianProcessRegressor
- correction_function
A 2D spline object for correcting resolution effects in the prediction.
- Type:
scipy.interpolate.RectBivariateSpline
- planck_means
Mean values of [omega_b, omega_c, n_s] from Planck 2018.
- Type:
np.ndarray
- eigenvecs
Eigenvectors of the Planck 2018 covariance matrix.
- Type:
np.ndarray
- planck_sigmas
Standard deviations along each eigenvector direction.
- Type:
np.ndarray
- CACHE_DIR = PosixPath('/root/.cache/AletheiaCosmo')
- MODEL_URLS = {'correction': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/resolution_correction_skl1.7.skops?ref_type=heads&inline=false', 'gp_B': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/Aletheia_GP_B_skl1.7.skops?ref_type=heads&inline=false', 'gp_dRdx': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/Aletheia_GP_dRdxt_skl1.7.skops?ref_type=heads&inline=false'}
- PLANCK_FILE = 'planck_2018_lcdm_parcov.dat'
- TRUSTED_TYPES = ['numpy.ndarray', 'builtins.dict', 'builtins.tuple', 'builtins.list', 'builtins.str', 'numpy.float64', 'numpy.random.mtrand.RandomState', 'sklearn.gaussian_process.kernels.Matern', 'sklearn.gaussian_process._gpr.GaussianProcessRegressor', 'scipy.interpolate._fitpack2.RectBivariateSpline']
- static create_cosmo_dict(h, omega_b=None, omega_c=None, omega_k=0.0, Omega_b=None, Omega_c=None, Omega_k=0.0, A_s=2.1e-09, n_s=0.96, w_0=-1.0, w_a=0.0, model='LCDM', density_type='physical')[source]
Creates a standardized cosmology dictionary for the Aletheia Emulator.
- Parameters:
h (float) – The Hubble parameter. Required for all conversions.
omega_b (float, optional) – Physical baryon/CDM densities.
omega_c (float, optional) – Physical baryon/CDM densities.
omega_k (float, optional) – Physical baryon/CDM densities.
Omega_b (float, optional) – Fractional baryon/CDM densities.
Omega_c (float, optional) – Fractional baryon/CDM densities.
Omega_nu (float, optional) – Fractional baryon/CDM densities.
... (other parameters with defaults)
model (str, optional) – Cosmological model, e.g., ‘LCDM’ or ‘w0waCDM’.
density_type (str, optional) – ‘physical’ (little omega) or ‘fractional’ (big Omega).
- Returns:
A validated dictionary ready for the emulator.
- Return type:
dict
- get_pnl(kvec, cospar, z)[source]
Calculates the non-linear matter power spectrum.
This is the main method of the emulator. It takes a set of wavenumbers, a cosmology, and a redshift, and returns the emulated P_NL(k).
- Parameters:
kvec (array_like) – Array of wavenumbers, k, in units of 1/Mpc. Must be within the emulator’s valid range [0.006, 2.0] 1/Mpc.
cospar (dict) – A dictionary of cosmological parameters such as the one created by create_cosmo_dict.
z (float) – The redshift at which to calculate the power spectrum.
- Returns:
The non-linear matter power spectrum, P_NL(k), in units of Mpc^3.
- Return type:
np.ndarray
- Raises:
ValueError – If any k-values in kvec are outside the emulator’s valid training range [0.006, 2.0] 1/Mpc.
ValueError – If the input cosmology fails the validation checks (e.g., sigma12 is out of range [0.2, 1.0] or shape parameters are out of the 5-sigma Planck box).
Notes
The calculation involves several steps: 1. Input parameters are validated (k-range, sigma12, shape). 2. A Cosmology object is created to compute linear spectra. 3. The non-linear boost B(k) and response dR/dxi are predicted by GPs. 4. The parameter xtilde is computed for the target and a reference cosmology. 5. All components are combined and a final resolution correction is applied. 6. A warning is logged if the resolution correction is > 1% at any scale.
Cosmology Module
- class aletheiacosmo.Cosmology(cospar, KMIN=0.0001, KMAX=4.0, NPOINTS=700)[source]
Bases:
objectManages the computation of linear, no-wiggle, and de-wiggled power spectra.
This class serves as a wrapper around CAMB to compute a baseline linear power spectrum at z=0. It uses the GrowthCalculator class to scale these spectra to different redshifts. It also contains methods to derive the smooth ‘no-wiggle’ and BAO-damped ‘de-wiggled’ power spectra, which are essential inputs for the emulator.
The typical workflow is to initialize the class, then call the main compute_all_spectra method, which handles the internal chain of calculations.
- Parameters:
cospar (dict) – A dictionary of cosmological parameters. Expected keys are: ‘h’, ‘omega_b’, ‘omega_c’, ‘n_s’, ‘A_s’, ‘w_0’, ‘w_a’, ‘omega_k’.
- growth
An instance of the GrowthCalculator for this cosmology.
- Type:
- plin_spline
A spline representation (t, c, k) of the linear power spectrum.
- Type:
tuple
- pnw_spline
A spline representation of the no-wiggle power spectrum.
- Type:
tuple
- pdw_spline
A spline representation of the de-wiggled power spectrum.
- Type:
tuple
- compute_all_spectra(target_sigma12_z0)[source]
A method to run the full calculation pipeline.
This function calls the internal methods in the correct order to generate the linear, no-wiggle, and de-wiggled power spectra.
- Parameters:
target_sigma12_z0 (float) – The target amplitude for the z=0 linear power spectrum, specified by the value of sigma_12.
- get_pdw(k)[source]
Interpolates the de-wiggled power spectrum P_dw(k) to any given k.
- Parameters:
k (float or ndarray) – Wavenumber(s) in units of 1/Mpc.
- Returns:
The interpolated de-wiggled power spectrum in units of Mpc^3.
- Return type:
float or ndarray
- get_plin(k)[source]
Interpolates the linear power spectrum P_lin(k) to any given k.
- Parameters:
k (float or ndarray) – Wavenumber(s) in units of 1/Mpc.
- Returns:
The interpolated linear power spectrum in units of Mpc^3.
- Return type:
float or ndarray
Growth Module
- class aletheiacosmo.GrowthCalculator(cospar, ln_a_min=-7.0, ln_a_max=0.53, num_steps=1701)[source]
Bases:
objectComputes the linear growth of structure for a given cosmology.
This class solves the differential equation for the linear growth factor for a flat or non-flat universe with a w0-wa dark energy model. It pre-computes the solution over a range of scale factors and uses spline interpolation to provide fast and accurate values for various growth-related quantities like D(z), f(z), and derived parameters required by the emulator.
- Parameters:
cospar (dict) – A dictionary of cosmological parameters. Expected keys are: ‘h’ : float, the Hubble parameter H0 / 100. ‘omega_k’ : float, the curvature density parameter, omega_k. ‘omega_c’ : float, the physical cold dark matter density, omega_c * h^2. ‘omega_b’ : float, the physical baryon density, omega_b * h^2. ‘w_0’ : float, the dark energy equation of state parameter. ‘w_a’ : float, the dark energy equation of state evolution parameter.
- ga_spline
A spline for the modified growth function g(ln a) = D(a)/a.
- Type:
scipy.interpolate.CubicSpline
- dga_spline
A spline for the derivative dg/d(ln a).
- Type:
scipy.interpolate.CubicSpline
- xz_spline
An inverse spline to find redshift z as a function of ln(D).
- Type:
scipy.interpolate.CubicSpline
- Dgrowth(z)[source]
Computes the linear growth factor D(z).
The growth factor is normalized such that D(a) = a during the matter-dominated era at high redshift.
- Parameters:
z (float or ndarray) – Redshift(s).
- Returns:
The linear growth factor D(z).
- Return type:
float or ndarray
- X(z)[source]
Computes the combination X(z) = Omega_m(z) / f(z)^2.
This quantity is a key input parameter for the emulator’s response to dark energy and modified gravity.
- Parameters:
z (float or ndarray) – Redshift(s).
- Returns:
The value of X(z).
- Return type:
float or ndarray
- X_tau(tau)[source]
Computes x(z)=Omega_m(z)/f(z)^2 as a function of the time variable tau = ln(D(z)).
- Parameters:
tau (float or ndarray) – The time variable, defined as the natural logarithm of the linear growth factor, ln(D).
- Returns:
The value of X at the redshift corresponding to the given tau.
- Return type:
float or ndarray
- dgdlna(z)[source]
Computes the derivative of the suppression factor, dg/d(ln a).
- Parameters:
z (float or ndarray) – Redshift(s).
- Returns:
The value of the derivative dg/d(ln a).
- Return type:
float or ndarray