{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Simple example of PyHank usage\n\nIn this example (as in the `sphx_glr_auto_examples_one_shot_example.py`)\nwe will check the band limit of a jinc function: $f(r) = \\frac{J_1(r)}{r}$.\nThe (0 order) Hankel transform of this should be the top hat function.\n\nHere we create a :class:`.HankelTransform` object and use its\n:meth:`~.HankelTransform.qdht` method.\nIn this simple case, the simpler, single shot functions used in\n`sphx_glr_auto_examples_one_shot_example.py` may be simpler\nto use. It should be noted, however, that they are not well suited for\nmultiple transforms on the same grid and the approach taken here is\nrecommended.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First import the :class:`.HankelTransform` class and other packages\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pyhank import HankelTransform\nimport scipy.special\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create a :class:`.HankelTransform` object which holds the grid for $r$ and\n$k_r$ points and calculate the jinc function.\n\nNote that although the calculation fails at $r = 0$, ``transformer.r`` does\nnot include $r=0$.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "transformer = HankelTransform(order=0, max_radius=100, n_points=1024)\nf = scipy.special.jv(1, transformer.r) / transformer.r\n\nplt.figure()\nplt.plot(transformer.r, f)\nplt.xlabel('Radius /m')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now take the Hankel transform using :meth:`.HankelTransform.qdht`\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ht = transformer.qdht(f)\n\nplt.figure()\nplt.plot(transformer.kr, ht)\nplt.xlim([0, 5])\nplt.xlabel('Radial wavevector /m$^{-1}$')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "As expected, this is a top-hat function bandlimited to $k<1$, except for numerical error.\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}