[Paper Review] hankl: A lightweight Python implementation of the FFTLog algorithm for Cosmology
hankl is a lightweight, open-source Python library that implements the FFTLog algorithm for efficient and accurate computation of Hankel transforms in cosmology. It enables fast, high-precision transformations between power spectra and correlation functions using logarithmically spaced grids and C-optimized numerical routines, achieving errors below 4×10⁻⁵ in test cases.
We introduce hankl, a lightweight Python implementation of the FFTLog algorithm for Cosmology. The FFTLog algorithm is an extension of the Fast Fourier Transform (FFT) for logarithmically spaced periodic sequences. It can be used to efficiently compute Hankel transformations, which are paramount for many modern cosmological analyses that are based on the power spectrum or the 2-point correlation function multipoles. The code is well-tested, open source, and publicly available.
Motivation & Objective
- To address the numerical challenges of computing Hankel transforms in cosmological analyses, which involve highly oscillatory Bessel function kernels.
- To provide a lightweight, well-tested, and open-source Python tool for efficient computation of Hankel transforms in cosmology.
- To enable accurate and fast transformations between power spectra and 2-point correlation functions in configuration and Fourier space.
- To support cosmological multipoles (e.g., monopole and quadrupole) by implementing the relevant Hankel transform forms with proper scaling and Bessel function handling.
- To combine ease of use with high performance by leveraging NumPy, SciPy, and C-level computation via optimized low-level routines.
Proposed method
- The FFTLog algorithm is applied to discretize Hankel transforms on logarithmically spaced grids, converting the integral into a convolution that can be computed via FFT.
- The method uses the transformation form f(k) = ∫₀^∞ F(r)(kr)^q J_μ(kr) k dr, enabling efficient computation of power spectrum to correlation function mappings.
- The implementation handles arbitrary power-law biases (kr)^±q and supports general Hankel transforms of order μ, including the standard form g(k) = ∫₀^∞ G(r) J_μ(kr) k dr.
- The code uses logarithmic variable transformations (ln r, ln k) to map the Hankel transform into a Fourier-like convolution, enabling FFT-based evaluation.
- hankl is built on NumPy and SciPy, with performance-critical components compiled to C-level speed, ensuring high efficiency for cosmological simulations.
- The library supports cosmologically relevant transforms such as those between P_ℓ(k) and ξ_ℓ(s), including multipoles via Legendre expansion and Bessel function integration.
Experimental results
Research questions
- RQ1How can the Hankel transform be computed efficiently and accurately in cosmological analyses involving oscillatory Bessel functions?
- RQ2What is the optimal way to discretize Hankel transforms on logarithmic grids to minimize numerical error?
- RQ3Can a lightweight Python library achieve C-level performance for cosmological Hankel transforms while remaining user-friendly and modular?
- RQ4How accurately can the FFTLog algorithm reproduce known analytical solutions for Hankel transforms in cosmological contexts?
- RQ5To what extent can hankl be used to transform cosmological power spectrum multipoles into correlation function multipoles with high fidelity?
Key findings
- The hankl library achieves absolute differences of less than 4×10⁻⁵ between numerically computed Hankel transforms and exact analytical results for test functions.
- The method successfully computes Hankel transforms for cosmologically relevant cases, including monopole and quadrupole power spectra and their corresponding correlation functions.
- The transformation from power spectrum multipoles P₀(k) and P₂(k) to correlation function multipoles ξ₀(s) and ξ₂(s) is accurately reproduced using the FFTLog-based approach.
- The code is well-tested, open-source, and publicly available at https://github.com/minaskar/hankl with comprehensive documentation at https://hankl.readthedocs.io.
- The implementation supports arbitrary Bessel function orders and power-law scaling, enabling flexible use across diverse cosmological modeling tasks.
- The performance is optimized via NumPy/SciPy integration and C-level computation, ensuring high-speed execution suitable for large-scale cosmological data analysis.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.