pyccl.pk2d module

class pyccl.pk2d.Pk2D(self, *, a_arr=None, lk_arr=None, pk_arr=None, is_logp=True, extrap_order_lok=1, extrap_order_hik=2)[source]

Bases: CCLObject

A power spectrum class holding the information needed to reconstruct an arbitrary function of wavenumber and scale factor.

Note

The Pk2D class is a wrapper around CCL’s bicubic interpolators. Addition, subtraction, multiplication, division returning new objects or in-place is supported between Pk2D objects and other Pk2D objects, integers, or floats. When the second object is also of type Pk2D, the a- and k-range changes to the most restrictive range. Exponentiation is also supported for integers and floats.

Note

The power spectrum can be evaluated by directly calling the instance pk(k, a). This is vectorized in both k and a.

Parameters:
  • a_arr (array) – An array holding values of the scale factor

  • lk_arr (array) – An array holding values of the natural logarithm of the wavenumber (in \(\mathrm{Mpc}^{-1}\)).

  • pk_arr (array) – A 2-D array of shape (na, nk), of the values of the power spectrum at a_arr and lk_arr. Input array could be flattened, provided that its size is nk*na. The array can hold the values of the natural logarithm of the power spectrum, depending on the value of is_logp. Users must ensure that the power spectrum is sufficiently well sampled (i.e. the resolution of a_arr and lk_arr is high enough to sample the main features in the power spectrum). CCL uses bicubic interpolation to evaluate the power spectrum at any intermediate point in k and a.

  • extrap_order_lok (int) – {0, 1, 2}. Extrapolation order to be used on k-values below the minimum the splines. Note that extrapolation is either in \(\log(P(k))\) or in \(P(k)\), depending on the value of is_logp.

  • extrap_order_hik (int) – {0, 1, 2}. Extrapolation order to be used on k-values above the maximum of the splines. Note that extrapolation is either in \(\log(P(k))\) or in \(P(k)\), depending on the value of is_logp.

  • is_logp (bool) – If True, pkarr holds the natural logarithm of the power spectrum. Otherwise, the true value of the power spectrum is expected. If is_logp is True, arrays are interpolated in log-space.

__call__(k, a, cosmo=None, *, derivative=False)[source]

Evaluate the power spectrum or its logarithmic derivative at a single value of the scale factor.

Parameters:
  • k (float or array) – Wavenumber value(s) in units of \({\ rm Mpc}^{-1}\).

  • a (float or array) – Value of the scale factor

  • cosmo (Cosmology) – Cosmology object. Used to evaluate the power spectrum outside of the interpolation range in a, thorugh the linear growth factor. If cosmo is None, attempting to evaluate the power spectrum outside of the interpolation range will raise an error.

  • derivative (bool) – If False, evaluate the power spectrum. If True, evaluate the logarithmic derivative of the power spectrum, \(d\log P(k)/d\log k\).

Returns:

P(k, a) – Value(s) of the power spectrum. or its derivative.

Return type:

(float or array)

classmethod from_function(pkfunc, *, is_logp=True, spline_params=None, extrap_order_lok=1, extrap_order_hik=2)[source]

Generates a Pk2D object from a function that calculates a power spectrum.

Parameters:
  • pkfunc (callable) – Function with signature f(k, a) which takes vectorized input in k (wavenumber in \(\mathrm{Mpc}^{-1}\)) and a scale factor`a``, and returns the value of the corresponding quantity. pkfunc will be sampled at the values of k and a used internally by CCL to store the linear and non-linear power spectra.

  • spline_params (SplineParameters) – optional spline parameters. Used to determine sampling rates in scale factor and wavenumber. Custom parameters can be passed via the Cosmology object with cosmo.cosmo.spline_params (C API), or with an instance of ccl.parameters.SplineParameters (Python API). If None, it defaults to the global accuracy parameters in CCL at the moment this function is called.

Returns:

Pk2D. Power spectrum object.

property has_psp
property extrap_order_lok
property extrap_order_hik
classmethod from_model(cosmo, model)[source]

Pk2D constructor returning the power spectrum associated with a given numerical model.

Parameters:
Returns:

Pk2D. The power spectrum of the input model.

apply_halofit(cosmo)[source]

Apply the “HALOFIT” transformation of Takahashi et al. 2012 on the linear power spectrum represented by this Pk2D object, and return the result as a Pk2D object.

Parameters:

cosmo (Cosmology) – a Cosmology object.

Returns:

Pk2D object containing the non-linear power spectrum after applying HALOFIT.

copy()[source]

Return a copy of this Pk2D object.

get_spline_arrays()[source]

Get the spline data arrays internally stored by this object to interpolate the power spectrum.

Returns:

Tuple containing

  • a_arr: Array of scale factors.

  • lk_arr: Array of natural logarithm of wavenumber k.

  • pk_arr: Array of the power spectrum \(P(k, a)\). The shape is (a_arr.size, lk_arr.size).

pyccl.pk2d.parse_pk2d(cosmo, p_of_k_a='delta_matter:delta_matter', *, is_linear=False)[source]

Return the C-level f2d spline associated with a Pk2D object.

Parameters:
  • cosmo (Cosmology) – A Cosmology object.

  • p_of_k_a (Pk2D or str) – if a Pk2D object, its f2d spline will be used. If a string, the linear or non-linear power spectrum stored by cosmo under this name will be used. Defaults to the matter power spectrum stored in cosmo.

  • is_linear (bool) – if True, and if p_of_k_a is a string or None, the linear version of the corresponding power spectrum will be used (otherwise it’ll be the non-linear version).

pyccl.pk2d.parse_pk(cosmo, p_of_k_a=None)[source]

Helper to retrieve the right Pk2D object.

Parameters:
  • cosmo (Cosmology) – a Cosmology object.

  • p_of_k_a (Pk2D, str or None) – 3D Power spectrum to return. If a Pk2D, it is just returned. If None or “linear”, the linear power spectrum stored in cosmo is returned. If “nonlinear”, the nonlinear matter power spectrum stored in cosmo is returned.

Returns:

Pk2D object corresponding to p_of_k_a.