Skip to main content

Hankel Transformations using method of Ogata 2005

Project description

This is a very simple module designed to implement the Hankel transformation following the method of Ogata 2005.

It is a fast and accurate way of integrating functions of the form f(x)J(x), where f is an arbitrary slowly decreasing function, and J(x) is an arbitrary Bessel function of the first kind.

Installation

Either clone the repository at github.com/steven-murray/hankel and use python setup.py install, or simply install using pip install hankel.

The only dependencies are numpy, scipy and mpmath (as of v0.2.0).

Usage

This implementation is set up to allow efficient calculation of multiple functions f(x). To do this, the format is class-based, with the main object taking as arguments the order of the Bessel function, and the number and size of the integration steps. For example, to integrate the function J_0(x) (ie. f(x) = 1, cf. Ogata’s paper) one would do the following:

from hankel import HankelTransform
f = lambda x: 1  #Define the input function f(x)
h = HankelTransform(nu=0,N=120,h=0.03)  #Create the HankelTransform instance
h.transform(f)  #Should give [1.0000000000003544, -9.8381428368537518e-15]

The correct answer is 1, so we have done quite well. The second element of the returned result is an estimate of the error (it is the last term in the summation). Here we used 120 steps of size 0.03. Different applications will need to tune these parameters to get best results. In the above example, one may modify the function f and re-call h.transform(f) without re-instantiating. This avoids unnecessary recalculation.

Also included in the module is a subclass called SphericalHankelTransform. This is dedicated to integrating functions of the form f(x)j(x), where j(x) is a spherical Bessel function of arbitrary order. It is called in exactly the same way. An example:

from hankel import SphericalHankelTransform
f = lambda x: x/(x**3+1)  #Define the input function f(x)
h = SphericalHankelTransform(nu=0,N=500,h=0.005)  #Create the HankelTransform instance
h.transform(f)  #Should give [0.61092293340214776, -1.4163951324130801e-14]

Mathematica gives the answer as 0.610913.

Limitations

An implementation-specific limitation is that the method is not perfectly efficient in all cases. Care has been taken to make it efficient in the general sense. However, for specific orders and functions, simplifications may be made which reduce the number of trigonometric functions evaluated. For instance, for a zeroth-order spherical transform, the weights are analytically always identically 1.

In terms of limitations of the method, they are very dependent on the form of the function chosen. Notably, functions which tend to infinity at x=0 will be poorly approximated in this method, and will be highly dependent on the step-size parameter, as the information at low-x will be lost between 0 and the first step. As an example consider the simple function f(x) = 1 with a zeroth order spherical bessel function. This tends to 1 at x=0, rather than 0:

f = lambda x: 1
h = SphericalHankelTransform(0,120,0.03)
h.transform(f) #[1.5461236955707951, -3.5905712375161296e-16]

The true answer is pi/2, which is a difference of about 3%. Modifying the step size and number of steps to gain accuracy we find:

h = SphericalHankelTransform(0,10000,0.0001)
h.transform(f) #[1.5706713512229455, -0.00010492204442285768]

This has much better than percent accuracy, but uses almost 100 times the amount of steps. The key here is the reduction of h to “get inside” the low-x information. This limitation is amplified for cases where the function really does tend to infinity at x=0, rather than a finite positive number, such as f(x) = 1/x.

History

v0.2.2 (29 April 2016)

  • Compatibility with Python 3 (thanks to @diazona)

  • Can now use with array-value functions (thanks to @diazona)

v0.2.1 (18 Feb 2016)

  • Fixed pip install by changing readme –> README

  • updated docs to show dependence on mpmath

v0.2.0 (10 Sep 2014)

  • Non-integer orders supported through mpmath.

v0.1.0

  • First working version. Only integer orders (and 1/2) supported.

References

Based on the algorithm provided in

H. Ogata, A Numerical Integration Formula Based on the Bessel Functions, Publications of the Research Institute for Mathematical Sciences, vol. 41, no. 4, pp. 949-970, 2005.

Also draws inspiration from

Fast Edge-corrected Measurement of the Two-Point Correlation Function and the Power Spectrum Szapudi, Istvan; Pan, Jun; Prunet, Simon; Budavari, Tamas (2005) The Astrophysical Journal vol. 631 (1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hankel-0.2.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

hankel-0.2.2-py2-none-any.whl (7.8 kB view details)

Uploaded Python 2

File details

Details for the file hankel-0.2.2.tar.gz.

File metadata

  • Download URL: hankel-0.2.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hankel-0.2.2.tar.gz
Algorithm Hash digest
SHA256 df4f04f862f7830b5365f7c216b01a19ab4523c64850db979c66201a812f66e7
MD5 a4f2247545c5367b0615a503584a575c
BLAKE2b-256 84ee3ad2075035ea84ff772354ca82c04ce0627e3e73ac0d42e3161f885a5c81

See more details on using hashes here.

File details

Details for the file hankel-0.2.2-py2-none-any.whl.

File metadata

File hashes

Hashes for hankel-0.2.2-py2-none-any.whl
Algorithm Hash digest
SHA256 d85ccaf46ceed9963e1fd67e8fe7f1abfa92172e563bc353cba692fccd85ff79
MD5 6d760a793af00d3fb3db4b56b3c03b7d
BLAKE2b-256 520ad2d41c0f1b1dda0b93e0e7f67fc298a525f86f7249c33bf74729f75fa366

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page