User Guide and API

Hankel Transformations and FFTLog

The FFTLog algorithm can be thought of as the Fast Fourier Transform (FFT) of a logarithmically spaced periodic sequence (= Hankel Transform).

hankl consists of two modules, the General FFTLog module and the Cosmology one. The latter is suited for modern cosmological application and relies heavily on the former to perform the Hankel transforms.

The user can find more information about the FFTLog algorithm here .

Here we will provide some usefull suggestions:

  • Accuracy of the method usually improves as the range of integration is enlarged. FFTlog prefers an interval that spans many orders of magnitude.
  • Resulution is important. Low resolution will introduce sharp features which in turn will cause ringing.
  • When possible, use the provided preprocessing tools to zero/constant pad or extrapolate the function along a larger interval.
  • FFTLog works better when the input arrays have size that is a power of 2. You can easily manage this by enabling extrapolation (ext).
  • Use the lowringing value of kr (or xy).

For more information about how to use hankl see the API below and visit the Examples page.

Cosmology module

hankl.P2xi(k, P, l, n=0, lowring=False, ext=0, range=None, return_ext=False, stirling_cutoff=200.0)

Hankel Transform Power Spectrum Multipole to Correlation Function Multipole.

\[\xi_{l}^{(n)}(r) = i^{l} \int_{0}^{\infty} k^{2} dk / (2 \pi^{2}) (kr)^{-n} P_{l}^{(n)}(k) j_{l}(ks)\]
Parameters:
  • k (array) – Array of uniformly logarithmically spaced wavenumbers.
  • P (array) – Array of respective Power Spectrum values.
  • l (int) – Degree of Power Spectrum multipole.
  • n (int) – Order of expansion (Default is 0, plane-parallel).
  • lowring (bool) – If True then use low-ringing value of kr (Default is False).
  • ext (int or tuple or list) –

    Controls the extrapolation mode. When ext is an integer then the same extrapolation method will be used for both ends of the input array. Alternatively, when ext is an tuple (ext_left, ext_right) or a list [ext_left, ext_right] then different methods can be used for the two ends of the the input array.

    • if ext=0 then no extrapolation is performed (Default).
    • if ext=1 then zero padding is performed.
    • if ext=2 then constant padding is performed.
    • if ext=3 then Power-Law extrapolation is performed.
  • range (tuple or list) – The minimum extrapolation range in the form of a tuple (k_min, k_max) or list [k_min, k_max]. When range=None (Default) then the extended range is chosen automatically such that its array-size is the next power of two.
  • return_ext (bool) – When False (Default) the result is cropped to fit the original k range.
  • stirling_cutoff (float) – Cutoff threshold, above which the Stirling approximation is used to compute the Gamma function ratio (Default is 200).
Returns:

r, xi – Array of uniformly logarithmically spaced r values and respective array of xi_{l}^{(n)}(r) values.

Return type:

array, array

hankl.xi2P(r, xi, l, n=0, lowring=False, ext=0, range=None, return_ext=False, stirling_cutoff=200.0)

Hankel Transform Correlation Function Multipole to Power Spectrum Multipole.

\[P_{l}^{(n)}(k) = 4 \pi (-i)^{l} \int_{0}^{\infty} r^{2} dr (kr)^{n} \xi_{l}^{(n)}(r) j_{l}(kr)\]
Parameters:
  • r (array) – Array of uniformly logarithmically spaced separations.
  • xi (array) – Array of respective two point correlation function values.
  • l (int) – Degree of Power Spectrum multipole.
  • n (int) – Order of expansion (Default is 0, plane-parallel).
  • lowring (bool) – If True then use low-ringing value of kr (Default is False).
  • ext (int or tuple or list) –

    Controls the extrapolation mode. When ext is an integer then the same extrapolation method will be used for both ends of the input array. Alternatively, when ext is an tuple (ext_left, ext_right) or a list [ext_left, ext_right] then different methods can be used for the two ends of the the input array.

    • if ext=0 then no extrapolation is performed (Default).
    • if ext=1 then zero padding is performed.
    • if ext=2 then constant padding is performed.
    • if ext=3 then Power-Law extrapolation is performed.
  • range (tuple or list) – The minimum extrapolation range in the form of a tuple (k_min, k_max) or list [k_min, k_max]. When range=None (Default) then the extended range is chosen automatically such that its array-size is the next power of two.
  • return_ext (bool) – When False (Default) the result is cropped to fit the original k range.
  • stirling_cutoff (float) – Cutoff threshold, above which the Stirling approximation is used to compute the Gamma function ratio (Default is 200).
Returns:

k, P – Array of uniformly logarithmically spaced k values and array of respective P_{l}^{(n)}(k) values.

Return type:

array, array

General FFTLog module

hankl.FFTLog(x, f_x, q, mu, xy=1.0, lowring=False, ext=0, range=None, return_ext=False, stirling_cutoff=200.0)

Hankel Transform based on the FFTLog algorithm of [1] and [2].

Defined as:

\[f(y)= \int_0^\infty F(x) (xy)^{q} J_\mu(xy) y dx\]
Parameters:
  • x (array) – Array of uniformly logarithmically spaced x values.
  • f_x (array) – Array of respective F(x) values.
  • q (float) – Exponent of power law bias; q may be any real number, positive (for forward transform) or negative (for inverse transform).
  • mu (float) – Index of J_mu in Hankel transform; mu may be any real number, positive or negative.
  • xy (float) – Input value of xy (Default is 1).
  • lowring (bool) – If True, then use low-ringing value of xy closest to input value of xy (Default is False).
  • ext (int or tuple or list) –

    Controls the extrapolation mode. When ext is an integer then the same extrapolation method will be used for both ends of the input array. Alternatively, when ext is an tuple (ext_left, ext_right) or a list [ext_left, ext_right] then different methods can be used for the two ends of the the input array.

    • if ext=0 then no extrapolation is performed (Default).
    • if ext=1 then zero padding is performed.
    • if ext=2 then constant padding is performed.
    • if ext=3 then Power-Law extrapolation is performed.
  • range (tuple or list) – The minimum extrapolation range in the form of a tuple (x_min, x_max) or list [x_min, x_max]. When range=None (Default) then the extended range is chosen automatically such that its array-size is the next power of two.
  • return_ext (bool) – When False (Default) the result is cropped to fit the original x range.
  • stirling_cutoff (float) – Cutoff threshold, above which the Stirling approximation is used to compute the Gamma function ratio (Default is 200).
Returns:

y, f(y) – Array of uniformly logarithmically spaced y values and array of respecive f(y) values.

Return type:

array, array

References

[1] J. D. Talman. Numerical Fourier and Bessel Transforms in Logarithmic Variables. Journal of Computational Physics, 29:35-48, October 1978.

[2] A. J. S. Hamilton. Uncorrelated modes of the non-linear power spectrum. MNRAS, 312:257-284, February 2000.