ClassWAP API Reference

The ClassWAP class is the central interface for the CosmoWAP package. It combines cosmology and survey biases and processes and stores them to provide a framework for computing power spectra and bispectra.

Core Class

class cosmo_wap.main.ClassWAP(cosmo, survey_params=None, compute_bias=False, hmf='Tinker10', hod='YP', emulator=False, verbose=True, params=None, fast=False, nonlin=False)

Initialise CosmoWAP from a CLASS cosmology and (optionally) survey parameters.

Interpolates cosmological background quantities (e.g. D, f, H etc) from CLASS, computes linear P(k) and optionally non-linear P(k) using halofit or an emulator. If survey parameters are passed, computes bias functions for given survey(s) and optionally derives higher order bias functions from HMF/HOD relations.

Parameters:

  • cosmo: Class instance from the CLASS Python wrapper (classy)

  • survey_params: Either a single SurveyParams instance or a list of two such instances for multi-tracer analysis

  • compute_bias: Boolean flag. If True, derive higher order bias functions and scale-dependent PNG biases from the HMF/HOD

  • hmf: Halo Mass Function to use if compute_bias is True. Options are 'Tinker10' (default, analytic Lagrangian biases), 'ST' (Sheth-Tormen), or 'Tinker2010' (numeric Lagrangian biases)

  • hod: HOD model to use if compute_bias is True. 'YP' (default) for Yankelevich & Porciani 2018, or 'Smith_BGS' for the DESI BGS HOD from Smith et al. 2024. Automatically selected for BGS surveys

  • emulator: If True, initialise a CosmoPower emulator internally. Pass a pre-loaded Emulator instance to reuse it across multiple ClassWAP objects

  • verbose: Print progress messages when computing bias functions

  • params: Pre-computed cosmological parameters dict (h, Omega_m, …) to load directly instead of querying CLASS — useful for speeding up MCMC sampling

  • fast: If True (and nonlin is False), skip building the non-linear P(k,z) grid

  • nonlin: If True, always build the non-linear halofit/emulator P(k,z) grid

Attributes:

  • cosmo: The CLASS cosmology instance

  • survey: List of survey objects (up to 3 for bispectrum multi-tracer). Access via survey[0], survey[1], etc.

  • multi_tracer: Boolean flag indicating if multiple distinct tracers are in use

  • h: Hubble parameter in units of 100 km/s/Mpc

  • Omega_m, Omega_b, Omega_cdm: Density parameters

  • A_s, n_s: Primordial power spectrum amplitude and spectral index

  • z_min, z_max: Redshift range of the survey(s) (intersection if multi-tracer)

  • z_survey: Array of redshift values within the survey range

  • f_sky: Sky fraction of the survey(s)

  • Pk, Pk_d, Pk_dd: Linear power spectrum and its first two k-derivatives (CubicSpline)

  • Pk_NL: 2D interpolated nonlinear power spectrum P(k,z) (if built)

  • D: Linear growth factor (CubicSpline in z)

  • f: Linear growth rate (CubicSpline in z)

  • H_c: Conformal Hubble parameter in h/Mpc (CubicSpline in z)

  • dH_c: First derivative of H_c with respect to redshift

  • comoving_dist: Comoving distance in Mpc/h (CubicSpline in z)

  • d_to_z: Inverse mapping from comoving distance to redshift

  • Om_m: Matter density parameter as a function of redshift

Methods:

get_class_powerspectrum(kk, zz=0)

Return the linear power spectrum from CLASS.

Parameters:
  • kk (array-like) – Wavevectors in h/Mpc

  • zz (float) – Redshift

Returns:

Linear power spectrum in (Mpc/h)^3

get_Pk_NL(kk, zz)

Build 2D (k,z) interpolated nonlinear power spectrum. Uses halofit via CLASS or HMCode via the CosmoPower emulator. Factors out D(z)^2 dependence and falls back to linear P(k) on large scales.

Parameters:
  • kk (array-like) – Wavevectors in h/Mpc

  • zz (array-like) – Array of redshifts

Returns:

Callable f(k, z) returning nonlinear P(k) at given (k,z)

pk(k)

Linear power spectrum with a k^{-3} power-law extrapolation beyond K_MAX.

Parameters:

k (array-like) – Wavevectors in h/Mpc

Returns:

P(k) in (Mpc/h)^3

setup_hod_hmf(compute_bias, hmf)

Precompute and cache cosmological quantities needed by the HOD/HMF pipeline. Called once during initialisation. When compute_bias is True, computes and stores R, sigmaR0/1/2, sig_R, delta_c, rho_crit, rho_m, and M (enclosed mass) on the ClassWAP instance.

Parameters:
  • compute_bias (bool) – Whether to precompute HOD/HMF quantities

  • hmf (str) – HMF model name

sigma_R_n(R, n, K_MIN=5e-5)

Compute \(\sigma^2_n(R)\) by integrating the power spectrum over k using a differential equation approach. Returns the z=0 values; redshift dependence is added via \(D(z)^2\) scaling in sig_R.

Parameters:
  • R (array-like) – Radii in Mpc/h

  • n (int) – Power of k in the integrand (0, -1, or -2)

Returns:

Array of \(\sigma^2_n(R)\)

update_survey(survey_params, verbose=True)

Set up (or update) survey bias functions for one or two tracers, including computing derivatives and shared survey properties.

Parameters:
  • survey_params – SurveyBase or list[SurveyBase]

  • verbose (bool) – Print progress messages

Returns:

self

get_PNGparams(zz, k1, k2, k3, ti=0, shape='Loc')

Get parameters needed for primordial non-Gaussianity bispectrum calculations.

Parameters:
  • zz (float) – Redshift

  • k1 (array-like) – First wavevector magnitude in h/Mpc

  • k2 (array-like) – Second wavevector magnitude in h/Mpc

  • k3 (array-like) – Third wavevector magnitude in h/Mpc

  • ti (int) – Tracer index (0 or 1)

  • shape (str) – Type of PNG (‘Loc’, ‘Eq’, or ‘Orth’)

Returns:

Tuple containing (bE01, bE11, Mk1, Mk2, Mk3)

get_PNGparams_pk(zz, k1, ti=0, shape='Loc')

Get parameters needed for PNG in power spectrum calculations.

Parameters:
  • zz (float) – Redshift

  • k1 (array-like) – Wavevector magnitude in h/Mpc

  • ti (int) – Tracer index (0 or 1)

  • shape (str) – Type of PNG (‘Loc’, ‘Eq’, or ‘Orth’)

Returns:

Tuple containing (bE01, Mk1)

compute_derivs_cosmo()

Compute derivatives of cosmology-dependent functions (f, D) with respect to log comoving distance. Called automatically during survey setup.

Returns:

self

compute_derivs_survey(ti=0)

Compute derivatives of survey-dependent bias functions (b1, b2, g2) with respect to log comoving distance for a given tracer.

Parameters:

ti (int) – Tracer index

Returns:

The tracer with populated deriv dict

get_derivs(zz, t_n=0)

Get derivatives of redshift-dependent parameters for radial evolution terms. Lazily calls compute_derivs_survey on first use.

Parameters:
  • zz (float) – Redshift

  • t_n (int) – Tracer index

Returns:

Tuple (fd, Dd, gd2, bd2, bd1, fdd, Ddd, gdd2, bdd2, bdd1)

get_beta_funcs(zz, ti=0)

Get beta coefficients for relativistic contributions. Computes and caches them on first call.

Parameters:
  • zz (float) – Redshift

  • ti (int) – Tracer index (0 or 1)

Returns:

List of beta coefficient arrays

get_beta_derivs(zz, ti=0)

Get derivatives of beta coefficients with respect to comoving distance.

Parameters:
  • zz (float) – Redshift

  • ti (int) – Tracer index (0 or 1)

Returns:

List of beta derivative arrays

solve_second_order_KC()

Compute second-order growth factors — redshift-dependent corrections to F2 and G2 kernels. Sets self.K_intp and self.C_intp attributes.

lnd_derivatives(functions_to_differentiate, ti=0)

Calculate derivatives of a list of functions with respect to log comoving distance.

Parameters:
  • functions_to_differentiate (list) – List of callables f(z)

  • ti (int) – Tracer index (determines redshift sampling)

Returns:

List of CubicSpline derivative functions

Pk_phi(k, k0=0.05)

Power spectrum of the Bardeen potential Phi in the matter-dominated era.

Parameters:
  • k (array-like) – Wavevector magnitude in h/Mpc

  • k0 (float) – Pivot scale in 1/Mpc (default 0.05)

Returns:

P_phi(k) in (Mpc/h)^3

M(k, z)

Scaling factor between the primordial scalar power spectrum and the late-time matter power spectrum in linear theory.

Parameters:
  • k (array-like) – Wavevector magnitude in h/Mpc

  • z (float) – Redshift

Returns:

M(k, z)

Cosmological Functions

The ClassWAP class provides the following interpolated cosmological functions as attributes. All are CubicSpline objects callable with redshift z unless stated otherwise.

  • H_c: Conformal Hubble parameter in h/Mpc

  • dH_c: First derivative of H_c with respect to redshift, in h/Mpc

  • comoving_dist: Comoving distance in Mpc/h

  • d_to_z: Inverse function mapping comoving distance (Mpc/h) to redshift

  • f: Linear growth rate (dimensionless)

  • D: Linear growth factor (normalised to unity at z=0)

  • Om_m: Matter density parameter as a function of redshift (dimensionless)

  • Pk: Linear power spectrum P(k) at z=0 in (Mpc/h)^3, callable with k in h/Mpc

  • Pk_d, Pk_dd: First and second k-derivatives of Pk

  • Pk_NL: 2D interpolated nonlinear power spectrum, callable as Pk_NL(k, z) with k in h/Mpc. D(z)^2 dependence is factored out

  • c: Speed of light in km/s

When compute_bias=True, the following are also available (cached by setup_hod_hmf):

  • R: Radius grid in Mpc/h (logspaced)

  • sigmaR0, sigmaR1, sigmaR2: \(\sigma^2_n(R)\) at z=0 for n=0, -1, -2

  • sig_R: Dict of callables sig_R["0"](z), sig_R["1"](z), sig_R["2"](z) returning \(\sigma^2_n(z,R)\)

  • delta_c: Critical overdensity for spherical collapse (1.686)

  • rho_crit: Critical density as a function of redshift in \(h^2 M_\odot / \mathrm{Mpc}^3\)

  • rho_m: Matter density as a function of redshift in \(h^2 M_\odot / \mathrm{Mpc}^3\)

  • M: Enclosed mass as a function of redshift \(M(z) = (4\pi/3) \rho_m(z) R^3\) in \(M_\odot/h\)

Survey and Bias Parameters

The ClassWAP instance provides access to survey parameters through the survey list. Each element includes:

  • b_1: Linear bias

  • b_2: Second-order bias

  • g_2: Tidal bias

  • be_survey: Evolution bias

  • Q_survey: Magnification bias

  • n_g: Number density

  • f_sky: Sky fraction

  • z_range: Redshift range

For primordial non-Gaussianity, each tracer has attributes for the different PNG types:

  • tracer.loc: Scale-dependent bias parameters for local PNG

  • tracer.eq: Scale-dependent bias parameters for equilateral PNG

  • tracer.orth: Scale-dependent bias parameters for orthogonal PNG

Each of these contains:

  • b_01: First-order scale-dependent bias parameter

  • b_11: Second-order scale-dependent bias parameter

Example Usage

Here’s a basic example of using ClassWAP:

import cosmo_wap as cw
from cosmo_wap.lib import utils

# Initialize cosmology with CLASS
cosmo = utils.get_cosmo(h=0.67, Omega_m=0.31, k_max=1.0, z_max=4.0)

# Get survey parameters
survey = cw.SurveyParams.Euclid(cosmo)

# Initialize ClassWAP
cosmo_funcs = cw.ClassWAP(cosmo, survey)

# Access cosmological functions
z = 1.0
print(f"Growth rate f(z=1) = {cosmo_funcs.f(z):.3f}")
print(f"Growth factor D(z=1) = {cosmo_funcs.D(z):.3f}")

# Access survey parameters
print(f"Linear bias b1(z=1) = {cosmo_funcs.survey[0].b_1(z):.3f}")

For more detailed examples, see the Getting Started page.