Skip to content

JCGoran/fftlog-python

Repository files navigation

1D FFTlog in Python

Stupid simple implementation of the FFTlog algorithm in Python, first described in Hamilton, 2000.

In essence, the code computes the following integral:

or, in Latex (in case the above doesn't display properly):

I_\ell^n(y)
=
\frac{1}{2 \pi^2}
\int_0^\infty
\text{d}x\,
x^2\,
\frac{j_\ell(x y)}{(x y)^n}\,
f(x)

where j_\ell are the spherical Bessel functions of degree \ell, and f(x) is the input function, usually taken to be the matter power spectrum.

Code is heavily based on twoFAST.jl, and has been verified with their implementation on the reference power spectrum.

Installation

Clone the repo:

git clone https://github.com/JCGoran/repo

You need the numpy and scipy packages for the FFTlog module to work.

You can install them using pip from the requirements.txt file:

pip3 install -r requirements.txt

You can add a --user flag to the above if you don't want to install those packages system-wide.

Usage

See the provided example.py file; note that it needs the matplotlib package to perform the plotting.

An abridged version would be:

  1. Import the module:
import fftlog
  1. Input: two arrays, x, and f(x); f(x) must be sampled on a large enough range of x, otherwise spurious oscillations may appear in the output.

  2. To create an FFTlog:

# prepares the FFTlog with ell = 0, n = 0, with 2048 sampling points
result = fftlog.FFTlog(x, y, 0, 0, 2048)

# performs the transformation in place with min(y_output) = 1
result.transform(1)
# alternatively, you can instead directly assign the output with:
# x_transform, y_transform = result.transform(1)

License

GPL 3.0

TODO

Make PyPI package.

About

FFTlog in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages