dsf.hankel.hankel module

Public layer for all Hankel transform operations.

This module provides the HankelTransform class, an interface for the HankelTransformFFTLog, HankelTransformMatrixDirect, and HankelTransformMatrixZeros classes. It provides public methods to compute projected and spherical correlation functions, as well as covariance matrices, from these underlying Hankel transform implementations.

Each of the three available backends can be useful for different purposes.

  • HankelTransformFFTLog: Supports projected and spherical 1D correlation functions. Fastest option for most 1D applications.

  • HankelTransformMatrixZeros: Supports projected 1D and 2D Hankel transforms using zero-crossing methods. Requires fine-tuning of the zero-crossing points upon generation. Can exhibit ringing at small scales.

  • HankelTransformMatrixDirect: Supports projected 1D and 2D Hankel transforms using direct matrix operator methods. Requires fine-tuning of the k-sampling upon generation. Robust against ringing at small scales, but can exhibit minor ringing at large scales.

The mathematical conventions for the projected and spherical transforms are as follows:

\(\gamma_t(\theta) = \int \frac{\ell d\ell}{2\pi} C(\ell )J_\mu(\ell \theta)\).

\(\xi(r) = \int \frac{k^2 dk}{2\pi^2} P(k) j_\mu(kr)\).

class dsf.hankel.hankel.HankelTransform(backend='fftlog', **kwargs)[source]

Bases: object

Class for performing Hankel transforms using different algorithms.

Parameters:

backend (HankelBackend)

bin_radial_matrix(r, matrix, r_bins)[source]

Average a radial matrix or tensor into radial bins.

Parameters:
  • r (NDArray[float64] | list[float] | tuple[float, ...]) – Radial grid associated with each axis of matrix.

  • matrix (NDArray[float64]) – Radial matrix or tensor to bin.

  • r_bins (NDArray[float64] | list[float] | tuple[float, ...]) – Radial bin edges.

Returns:

Radial bin centers and binned matrix or tensor.

Return type:

tuple[NDArray[float64], NDArray[float64]]

correlation_matrix(covariance)[source]

Return the correlation matrix associated with a covariance matrix.

Parameters:

covariance (NDArray[float64]) – Covariance matrix.

Returns:

Dimensionless correlation matrix.

Return type:

NDArray[float64]

diagonal_error(covariance)[source]

Return one-sigma errors from a covariance matrix.

Parameters:

covariance (NDArray[float64]) – Covariance matrix.

Returns:

Square root of the covariance diagonal.

Return type:

NDArray[float64]

projected_correlation(radial_input=None, spectrum=None, order=0, **kwargs)[source]

Compute a projected radial statistic from one spectrum.

Parameters:
  • radial_input (NDArray[float64] | list[float] | tuple[float, ...] | None) – Radial input grid for tabulated spectra.

  • spectrum (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]] | None) – Spectrum values or callable spectrum.

  • order (float | int) – Bessel order to use.

  • **kwargs – Extra arguments passed to callable spectra.

Returns:

Radial grid, in inverse units of radial_input, and the projected radial statistic.

Return type:

tuple[NDArray[float64], NDArray[float64]]

projected_correlation_interpolated(theta, radial_input, spectrum, order=0, grid_spacing='linear', **kwargs)[source]
Compute a projected radial statistic from one spectrum at given theta values.

The statistic is interpolated from the internal Hankel grid to the requested theta values.

Parameters:
  • theta (NDArray[float64]) – Theta values for interpolation (in radians).

  • radial_input (NDArray[float64]) – Radial input grid for tabulated spectra.

  • spectrum (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]]) – Spectrum values or callable spectrum.

  • order (float | int) – Bessel order to use.

  • grid_spacing (str) – Interpolate in “linear” or “log” space.

  • **kwargs – Extra arguments passed to callable spectra.

Returns:

Requested radial grid and projected radial statistic.

Return type:

tuple[NDArray[float64], NDArray[float64]]

projected_covariance(k_pk=None, pk1=None, pk2=None, order=0, **kwargs)[source]

Compute a projected covariance matrix from two spectra.

Parameters:
  • k_pk (NDArray[float64] | list[float] | tuple[float, ...] | None) – Wavenumber grid for tabulated spectra.

  • pk1 (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]] | None) – First spectrum values or callable spectrum.

  • pk2 (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]] | None) – Second spectrum values or callable spectrum.

  • order (float | int) – Bessel order to use.

  • **kwargs – Extra arguments passed to callable spectra.

Returns:

Radial grid (units of radians) and projected covariance matrix.

Return type:

tuple[NDArray[float64], NDArray[float64]]

spherical_correlation(k_pk=None, pk=None, order=0, **kwargs)[source]

Compute a spherical radial statistic from one spectrum.

Parameters:
  • k_pk (NDArray[float64] | list[float] | tuple[float, ...] | None) – Wavenumber grid for tabulated spectra.

  • pk (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]] | None) – Spectrum values or callable spectrum.

  • order (float | int) – Bessel order to use.

  • **kwargs – Extra arguments passed to callable spectra.

Returns:

Radial grid and spherical radial statistic. The units of the radial grid are the inverse of the units of k.

Return type:

tuple[NDArray[float64], NDArray[float64]]

spherical_correlation_interpolated(r, k_pk, pk, order=0, grid_spacing='linear', **kwargs)[source]
Compute a spherical radial statistic from one spectrum at given radial values.

The statistic is interpolated from the internal Hankel grid to the requested radial values.

Parameters:
  • r (NDArray[float64]) – radial values for interpolation (in Mpc).

  • k_pk (NDArray[float64]) – Wavenumber grid for tabulated spectra (in 1/Mpc).

  • pk (NDArray[float64] | list[float] | tuple[float, ...] | Callable[[...], NDArray[float64]]) – Spectrum values or callable spectrum.

  • order (float | int) – Bessel order to use.

  • grid_spacing (str) – Interpolate in “linear” or “log” space.

  • **kwargs – Extra arguments passed to callable spectra.

Returns:

Radial grid and spherical radial statistic.

Return type:

tuple[NDArray[float64], NDArray[float64]]