{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Example of single-shot transform\n\nIn this example (as in the `sphx_glr_auto_examples_simple_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\nIn this case, we will use the simple, single shot functions. It should be noted\nthough, this simplicity comes at an increased overhead, and for multiple transforms\non the same grid, the approach in `sphx_glr_auto_examples_simple_example.py` is\nrecommended.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First import the ``qdht`` function and other packages.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pyhank import qdht\nimport numpy as np\nimport scipy.special\nimport matplotlib.pyplot as plt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create a grid for $r$ points and calculate the jinc function.\nThe calculation fails at $r = 0$, so we have to set that manually to the limit of $1/2$.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "r = np.linspace(0, 100, 1024)\nf = np.zeros_like(r)\nf[1:] = scipy.special.jv(1, r[1:]) / r[1:]\nf[r == 0] = 0.5\n\nplt.figure()\nplt.plot(r, f)\nplt.xlabel('Radius /m')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now take the Hankel transform using ``qdht``:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "kr, ht = qdht(r, f)\n\nplt.figure()\nplt.plot(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.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}