API Reference

This page provides the auto-generated documentation for the main classes.

Aletheia Emulator

class aletheiacosmo.AletheiaEmu[source]

Bases: object

Emulator for the non-linear matter power spectrum and the halo mass function.

This class provides predictions for the non-linear matter power spectrum, P_NL(k) and the halo multiplicity function f(nu) 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 P_NL(k) emulation method get_pnl() 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.

The emulation of f(nu) is handled by get_fnu(), using the same emulation strategy and the same simulation suite, and reuse the cosmology validation, the reference-redshift solver and the growth-history machinery of P_NL; only the trained models, the memory-kernel width and the region of validity differ. The method get_fnu() returns the differential mass function dn/dlnM based on the f(nu) emulation.

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

gp_fnu

The trained GP model for ln[f(nu) / f_ref(nu)].

Type:

sklearn.gaussian_process.GaussianProcessRegressor

gp_dfdx

The trained GP model for the response of f(nu) to xtilde.

Type:

sklearn.gaussian_process.GaussianProcessRegressor

reference_spline_hmf

A splrep representation of ln f_ref as a function of ln nu.

Type:

tuple

nu_range

Bounding box of the region of validity in nu: the loosest (min, max) peak height reached anywhere in SIGMA12_RANGE. It is a summary only – the check applied to a prediction is the sigma12-dependent window returned by nu_range_at().

Type:

tuple of float

SIGMA12_RANGE

The (min, max) clustering amplitude the emulator is trained for.

Type:

tuple of float

REFERENCE_COSPAR

Parameters of the reference cosmology that defines the evolution-mapping reference growth history.

Type:

dict

MEMORY_SCALE_HMF

Width of the mass-function memory kernel, in units of ln D.

Type:

float

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', 'gp_dfdx': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/Aletheia_GP_dfdxt_skl1.7.skops?ref_type=heads&inline=false', 'gp_fnu': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/Aletheia_GP_fnu_skl1.7.skops?ref_type=heads&inline=false', 'reference': 'https://gitlab.mpcdf.mpg.de/arielsan/aletheia/-/raw/main/src/aletheiacosmo/data/fnu_reference_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', 'builtins.int']
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

static gaussian_kernel(tau, tau_prime, tau_s)[source]

Computes a normalized Gaussian kernel.

get_fnu(nu, cospar, z)[source]

Calculates the halo multiplicity function f(nu).

This is the main method of the HMF emulator. It takes a set of peak heights, a cosmology, and a redshift, and returns the emulated f(nu), defined such that dn/dlnM = f(nu) * rho_b / M * dln(nu)/dlnM.

Parameters:
  • nu (array_like) – Array of peak heights, nu = delta_c / sigma(M, z). Must lie within the window the emulator is trained for at the sigma12 of this cosmology and redshift, nu_range_at().

  • 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 multiplicity function.

Returns:

The halo multiplicity function, f(nu), dimensionless.

Return type:

np.ndarray

Raises:

ValueError – If the input cosmology fails the validation checks (sigma12 outside [0.2, 1.0] or shape parameters outside the 5-sigma Planck box), or if any nu-value falls outside the sigma12-dependent window the emulator is trained for.

Notes

The calculation involves several steps: 1. A Cosmology object is created to compute sigma12(z). 2. Inputs are validated: shape parameters and sigma12 first, then nu

against the window that sigma12 implies.

  1. The ratio f/f_ref and the response dR/dxtilde are predicted by GPs.

  2. xtilde is computed for the target cosmology and for the reference cosmology at the redshift z0 where it has the same sigma12.

  3. All components are combined into the final predicted f(nu).

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.

nM_dlogM(M, cospar, z)[source]

Computes the differential mass function dn/dlnM at redshift z.

Parameters:
  • M (array_like) – Halo masses at which the mass function is evaluated, in Msun.

  • 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 mass function.

Returns:

dn/dlnM, in Mpc^-3.

Return type:

np.ndarray

Raises:

ValueError – If the masses map onto peak heights outside the window the emulator is trained for at this sigma12, or if the cosmology fails validation. The accessible mass range shrinks towards high redshift.

Notes

The mass-to-peak-height conversion is Cosmology.mass_to_nu(): sigma(R) from CAMB at z=0 for the input cosmology, scaled to the requested redshift with the linear growth factor, exactly as in HMF_Fiorilli25. Call it on a Cosmology built from cospar to pick masses that land inside nu_range_at(), or to label a mass axis in peak height. Masses are always M200b, the single mass definition the emulator is trained for.

nu_range_at(sigma12)[source]

Peak heights the emulator is trained for at a given sigma12.

The window is the nu coverage of the f(nu) GP, which carries the leading term of the prediction. It narrows as sigma12 falls, from a width of about 2.2 at sigma12 = 1 down to less than 0.1 at sigma12 = 0.2.

Parameters:

sigma12 (float) – The clustering amplitude of the target cosmology at the redshift of interest. Assumed to lie in SIGMA12_RANGE, which is checked separately; the polynomials are not meaningful outside it.

Returns:

The (min, max) valid peak height at this sigma12.

Return type:

tuple of float

Cosmology Module

class aletheiacosmo.Cosmology(cospar, KMIN=0.0001, KMAX=4.0, NPOINTS=700)[source]

Bases: object

Manages 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:

GrowthCalculator

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

rho_bar

The present-day mean comoving matter density, in Msun / Mpc^3. It sets the Lagrangian radius of a halo of given mass.

Type:

float

DELTA_C = 1.6864701998411453
RHO_100 = 277536627245.708
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_dewiggled_pk(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_linear_pk(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

get_nowiggle_pk(k)[source]

Interpolates the no-wiggle power spectrum P_nw(k) to any given k.

Parameters:

k (float or ndarray) – Wavenumber(s) in units of 1/Mpc.

Returns:

The interpolated no-wiggle power spectrum in units of Mpc^3.

Return type:

float or ndarray

get_sigma12(z)[source]

Scales the value of sigma_12(z=0) to a given redshift using the growth factor.

Parameters:

z (float) – The target redshift.

Returns:

The value of sigma_12 at redshift z.

Return type:

float

mass_to_nu(x, z, inverse=False)[source]

Converts halo masses to peak heights, or peak heights back to masses.

The mapping uses sigma(R) from CAMB at z=0 for this cosmology, evaluated at the Lagrangian radius of each mass and scaled to the requested redshift with the linear growth factor, with nu = delta_c / sigma(M, z).

Parameters:
  • x (array_like) – Halo masses, in Msun; or peak heights, if inverse is True.

  • z (float) – The redshift at which the conversion is made.

  • inverse (bool, optional) – If True, convert peak heights to masses instead. Default is False.

Returns:

Peak heights, or halo masses in Msun. A scalar input gives a scalar back.

Return type:

np.ndarray

Raises:

ValueError – If inverse is True and a peak height falls outside the range spanned by the tabulated sigma(R), i.e. the Lagrangian radius it implies is outside 10^-2 to 50 Mpc.

sigma0_splines()[source]

Splines of sigma(R) at z=0, built once per cosmology.

Returns sigma as a function of R, ln sigma as a function of ln R (whose derivative turns f(nu) into dn/dlnM), and the inverse ln R as a function of ln sigma. They are cached on the instance, since building them costs a CAMB sigma(R) evaluation on a 3000-point grid.

Growth Module

class aletheiacosmo.GrowthCalculator(cospar, ln_a_min=-7.0, ln_a_max=0.53, num_steps=1701)[source]

Bases: object

Computes 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_c’ : float, the physical cold dark matter density, Omega_c * h^2. ‘omega_b’ : float, the physical baryon density, Omega_b * h^2. ‘omega_k’ : float, the physical curvature density parameter, Omega_k * 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

fgrowth(z)[source]

Computes the logarithmic growth rate, f(z) = d(ln D) / d(ln a).

Parameters:

z (float or ndarray) – Redshift(s).

Returns:

The growth rate f(z).

Return type:

float or ndarray

static func(y)[source]
g(z)[source]

Computes the growth suppression factor g(z) = D(z) * (1+z).

This quantity is equivalent to g(a) = D(a) / a.

Parameters:

z (float or ndarray) – Redshift(s).

Returns:

The value of the modified growth function g(z).

Return type:

float or ndarray