ClassWAP API Reference
The ClassWAP class is the central interface for the CosmoWAP package. It combines cosmological calculations, survey parameters, and bias models to provide a comprehensive framework for computing power spectra and bispectra.
Core Class
- class main.ClassWAP(cosmo, survey_params, compute_bias=False, HMF='Tinker2010', nonlin=False, growth2=False)
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 indicating whether to compute bias parameters using the Peak Background Split approach
HMF: Halo Mass Function to use if compute_bias is True. Options are ‘Tinker2010’ (default) or ‘ST’ (Sheth-Tormen)
nonlin: Boolean flag to use nonlinear HALOFIT power spectra
growth2: Boolean flag to include second-order growth corrections to F2 and G2 kernels
Attributes:
cosmo: The CLASS cosmology instance
survey: First survey (or only survey if single tracer)
survey1: Second survey (same as survey for single tracer)
Om_0: Matter density parameter today
h: Hubble parameter in units of 100 km/s/Mpc
z_min, z_max: Redshift range of the survey(s)
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 derivatives
Pk_NL: Nonlinear power spectrum (if nonlin=True)
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(k, z=0)
Return the nonlinear power spectrum using HALOFIT.
- Parameters:
k (array-like) – Wavevectors in h/Mpc
z (float) – Redshift
- Returns:
Nonlinear power spectrum in (Mpc/h)^3
- get_params(k1, k2, k3=None, theta=None, zz=0, tracer=None, nonlin=False, growth2=False)
Get all necessary parameters for bispectrum calculations.
- Parameters:
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 (optional)
theta (array-like) – Outside angle θ (optional)
zz (float) – Redshift
tracer (object) – Survey tracer to use (defaults to self.survey)
nonlin (bool) – Whether to use nonlinear power spectra
growth2 (bool) – Whether to use second-order growth corrections
- Returns:
Tuple of parameters needed for bispectrum calculations
- get_params_pk(k1, zz)
Get all necessary parameters for power spectrum calculations.
- Parameters:
k1 (array-like) – Wavevector magnitude in h/Mpc
zz (float) – Redshift
- Returns:
Tuple of parameters needed for power spectrum calculations
- get_PNGparams(zz, k1, k2, k3, tracer=None, shape='Loc')
Get parameters needed for primordial non-Gaussianity 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
tracer (object) – Survey tracer to use (defaults to self.survey)
shape (str) – Type of PNG (‘Loc’, ‘Eq’, or ‘Orth’)
- Returns:
Tuple containing (bE01, bE11, Mk1, Mk2, Mk3) for PNG calculations
- get_PNGparams_pk(zz, k1, tracer=None, shape='Loc')
Get parameters needed for PNG in power spectrum calculations.
- Parameters:
zz (float) – Redshift
k1 (array-like) – Wavevector magnitude in h/Mpc
tracer (object) – Survey tracer to use (defaults to self.survey)
shape (str) – Type of PNG (‘Loc’, ‘Eq’, or ‘Orth’)
- Returns:
Tuple containing (bE01, Mk1) for PNG calculations
- get_derivs(zz, tracer=None)
Get derivatives of redshift-dependent parameters for radial evolution terms.
- Parameters:
zz (float) – Redshift
tracer (object) – Survey tracer to use (defaults to self.survey)
- Returns:
Tuple of first and second derivatives of bias parameters and growth factors
- get_beta_funcs(zz, tracer=None)
Get beta coefficients for relativistic contributions.
- Parameters:
zz (float) – Redshift
tracer (object) – Survey tracer to use (defaults to self.survey)
- Returns:
List of beta coefficients for relativistic terms
- solve_second_order_KC()
Compute second-order growth factors for F2 and G2 kernels.
- lnd_derivatives(functions_to_differentiate)
Calculate derivatives of functions with respect to log comoving distance.
- Parameters:
functions_to_differentiate (list) – List of functions to differentiate
- Returns:
List of derivative functions
- Pk_phi(k, k0=0.05, units=True)
Compute the power spectrum of the Bardeen potential Φ in the matter-dominated era.
- Parameters:
k (array-like) – Wavevector magnitude in h/Mpc
k0 (float) – Pivot scale in h/Mpc
units (bool) – Whether to include dimensionful units
- Returns:
Power spectrum of the Bardeen potential
- M(k, z)
Compute the scaling factor between primordial and late-time power spectra.
- Parameters:
k (array-like) – Wavevector magnitude in h/Mpc
z (float) – Redshift
- Returns:
Transfer function M(k, z)
Helper Functions
The ClassWAP class uses several cosmological functions that are provided through attributes:
H_c: Conformal Hubble parameter in h/Mpc
dH_c, ddH_c: First and second derivatives of H_c with respect to redshift
comoving_dist: Comoving distance in Mpc/h
d_to_z: Inverse function mapping comoving distance to redshift
f_intp: Linear growth rate
D_intp: Linear growth factor
dD_dz: Derivative of the growth factor with respect to redshift
conf_time: Conformal time in Mpc/h
Om: Matter density parameter as a function of redshift
rho_crit, rho_m: Critical density and matter density in h³M⊙/Mpc³
Survey and Bias Parameters
The ClassWAP instance provides access to survey parameters through the survey and survey1 attributes. These include:
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.