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:
CCLObjectA power spectrum class holding the information needed to reconstruct an arbitrary function of wavenumber and scale factor.
Note
The
Pk2Dclass is a wrapper around CCL’s bicubic interpolators. Addition, subtraction, multiplication, division returning new objects or in-place is supported betweenPk2Dobjects and otherPk2Dobjects, integers, or floats. When the second object is also of typePk2D, 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 bothkanda.- 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 ata_arrandlk_arr. Input array could be flattened, provided that its size isnk*na. The array can hold the values of the natural logarithm of the power spectrum, depending on the value ofis_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 ofis_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 ofis_logp.is_logp (
bool) – If True,pkarrholds the natural logarithm of the power spectrum. Otherwise, the true value of the power spectrum is expected. Ifis_logpisTrue, 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 (
floator array) – Wavenumber value(s) in units of \({\ rm Mpc}^{-1}\).a (
floator array) – Value of the scale factorcosmo (
Cosmology) – Cosmology object. Used to evaluate the power spectrum outside of the interpolation range ina, thorugh the linear growth factor. IfcosmoisNone, attempting to evaluate the power spectrum outside of the interpolation range will raise an error.derivative (
bool) – IfFalse, evaluate the power spectrum. IfTrue, 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:
(
floator 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 signaturef(k, a)which takes vectorized input ink(wavenumber in \(\mathrm{Mpc}^{-1}\)) and a scale factor`a``, and returns the value of the corresponding quantity.pkfuncwill be sampled at the values ofkandaused 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 theCosmologyobject withcosmo.cosmo.spline_params(C API), or with an instance ofccl.parameters.SplineParameters(Python API). IfNone, 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]
Pk2Dconstructor returning the power spectrum associated with a given numerical model.- Parameters:
cosmo (
Cosmology) – A Cosmology object.model (
str) –Model to use. These models allowed:
'bbks'(Bardeen et al. 1986).'eisenstein_hu'(Eisenstein & Hu 1997).'eisenstein_hu_nowiggles'(Eisenstein & Hu 1997, no-wiggles version).
- 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
Pk2Dobject, and return the result as aPk2Dobject.
- 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
Pk2Dobject.- Parameters:
cosmo (
Cosmology) – A Cosmology object.p_of_k_a (
Pk2Dorstr) – if aPk2Dobject, its f2d spline will be used. If a string, the linear or non-linear power spectrum stored bycosmounder this name will be used. Defaults to the matter power spectrum stored in cosmo.is_linear (
bool) – ifTrue, and ifp_of_k_ais a string orNone, the linear version of the corresponding power spectrum will be used (otherwise it’ll be the non-linear version).