- Compute integral transforms:
$$G(y) = \int_0^\infty F(x) K(xy) \frac{dx}x;$$ - Inverse transform without analytic inversion;
- Integral kernels as derivatives:
$$G(y) = \int_0^\infty F(x) K'(xy) \frac{dx}x;$$ - Transform input array along any axis of
ndarray
; - Output the matrix form;
- 1-to-n transform for multiple kernels (TODO):
$$G(y_1, \cdots, y_n) = \int_0^\infty \frac{dx}x F(x) \prod_{a=1}^n K_a(xy_a);$$ - Easily extensible for other kernels;
- Support NumPy and JAX.
mcfit
computes integral transforms of the form
mcfit
implements the FFTLog algorithm.
The idea is to take advantage of the convolution theorem in
pip install mcfit
See docstring of mcfit.mcfit
, which also applies to other
subclasses of transformations.
Also see doc/mcfit.tex
for more explanations.
One can perform the following pair of Hankel transforms
def F_fun(x): return 1 / (1 + x*x)**1.5
def G_fun(y): return numpy.exp(-y)
from mcfit import Hankel
x = numpy.logspace(-3, 3, num=60, endpoint=False)
F = F_fun(x)
H = Hankel(x, lowring=True)
y, G = H(F, extrap=True)
numpy.allclose(G, G_fun(y), rtol=1e-8, atol=1e-8)
y = numpy.logspace(-4, 2, num=60, endpoint=False)
G = G_fun(y)
H_inv = Hankel(y, lowring=True)
x, F = H_inv(G, extrap=True)
numpy.allclose(F, F_fun(x), rtol=1e-10, atol=1e-10)
Cosmologists often need to transform a power spectrum to its correlation function
from mcfit import P2xi
k, P = numpy.loadtxt('P.txt', unpack=True)
r, xi = P2xi(k)(P)
and the other way around
from mcfit import xi2P
r, xi = numpy.loadtxt('xi.txt', unpack=True)
k, P = xi2P(r)(xi)
Similarly for the quadrupoles
k, P2 = numpy.loadtxt('P2.txt', unpack=True)
r, xi2 = P2xi(k, l=2)(P2)
Also useful to the cosmologists is the tool below that computes the
variance of the overdensity field as a function of radius, from which
from mcfit import TophatVar
R, var = TophatVar(k, lowring=True)(P, extrap=True)
from scipy.interpolate import CubicSpline
varR = CubicSpline(R, var)
sigma8 = numpy.sqrt(varR(8))