Commit d402d819 authored by Leon Merten Lohse's avatar Leon Merten Lohse
Browse files

add hankel interpolation without storing matrix

parent 072dcf4e
Pipeline #175724 passed with stages
in 56 seconds
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -14,16 +14,16 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget"
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -42,34 +42,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "30964ee649ba42c5ab2fa05d2154b9fc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<matplotlib.colorbar.Colorbar at 0x7f63670f0760>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"im = ax.imshow(np.abs(u0)**2)\n",
......@@ -78,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -93,34 +68,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "23f19735628d4950b531701abc47cc97",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f63670b6040>]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Transfer function propagator\n",
"propTF = vac.FresnelTFPropagator(u0.shape, Fpix)\n",
......@@ -134,34 +84,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5d2350996be84baca24e88907df4bb4e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f6366c49190>]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"propIR = vac.FresnelIRPropagator(u0.shape, Fpix)\n",
"\n",
......@@ -175,34 +100,9 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "97d69f31092f40cd9663bd3957fea08d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<matplotlib.colorbar.Colorbar at 0x7f6366baf5b0>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"mask2 = (xx**2 + yy**2 < radius**2)\n",
"\n",
......@@ -216,34 +116,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b38903e3dade436f8f78d4bba1a36a07",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f6366be86d0>]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"propTF2 = vac.FresnelTFPropagator(u0.shape, 2*Fpix)\n",
"\n",
......@@ -259,12 +134,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hankel Propagatoin"
"## Hankel Propagation"
]
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -273,49 +148,32 @@
"maskcs = (xx_hankel**2 < radius**2)\n",
"u02r = maskcs * 1+0j\n",
"\n",
"propCS = vac.FresnelPropagatorCS(n_hankel, 10*Fpix)\n",
"propCS = vac.FresnelPropagatorCS(n_hankel, 2*Fpix)\n",
"u2rprop = propCS(u02r)\n",
"interp = fresnel.hankel.interp1d(u2rprop, n_hankel, 0.25)\n",
"\n",
"xx_new = np.linspace(-0.25, 0.25, n)\n",
"resample = fresnel.hankel.ResampleTransform(n_hankel, xx_new, 0.25)\n",
"u2rprop_new = resample(u2rprop)"
"u2rprop_new = interp(xx_new)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f6fa3c27696247898bded22328e56d11",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f636679ea00>]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.plot(xx_new, np.abs(u2rprop_new)**2)"
"ax.plot(xx_new, np.abs(u2rprop_new)**2)\n",
"#ax.plot(np.abs(u2rprop)**2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......@@ -340,7 +198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.7"
"version": "3.9.1"
}
},
"nbformat": 4,
......
......@@ -36,7 +36,7 @@ def hankelMatrix(N, order=0):
.. [1] N. Baddour and U. Chouinard, “Theory and operational rules for the discrete Hankel transform,” Journal of the Optical Society of America A, vol. 32, no. 4, p. 611, Mar. 2015. https://doi.org/10.1364/JOSAA.32.000611
"""
jn = np.array(scipy.special.jn_zeros(order, N + 1))
jn = np.asarray(scipy.special.jn_zeros(order, N + 1))
k = np.expand_dims(np.arange(N), axis=0)
m = np.expand_dims(np.arange(N), axis=1)
......@@ -69,7 +69,7 @@ def hankelSamples(N, xmax=1, order=0):
real space sampling grid
"""
jn = np.array(scipy.special.jn_zeros(order, N + 1))
jn = np.asarray(scipy.special.jn_zeros(order, N + 1))
return jn[:-1] * xmax / jn[N]
......@@ -93,7 +93,7 @@ def hankelFreq(N, kmax=0.5, order=0):
frequency sampling grid
"""
jn = np.array(scipy.special.jn_zeros(order, N + 1))
jn = np.asarray(scipy.special.jn_zeros(order, N + 1))
return jn[:-1] * kmax / jn[N]
......@@ -142,7 +142,7 @@ class ResampleTransform:
def __init__(self, N, samplesout, xmax=1, order=0, eps=1e-10):
jn = np.array(scipy.special.jn_zeros(order, N + 1))
jn = np.asarray(scipy.special.jn_zeros(order, N + 1))
jN = jn[N]
K = jN / xmax
......@@ -168,3 +168,35 @@ class ResampleTransform:
def __call__(self, f):
return self.matrix @ f
class interp1d:
def __init__(self, values, N, xmax=1, order=0, eps=1e-10):
self.eps = eps
jn = np.asarray(scipy.special.jn_zeros(order, N + 1))
jN = jn[N]
self.x = jn[:-1] * xmax / jN
self.y = values
self.K = jN / xmax
self.order = order
self.coeff = 2 * self.x / self.K / scipy.special.jn(order + 1, self.K * self.x)
def __call__(self, xnew):
factor = scipy.special.jn(self.order, self.K * xnew)
ynew = np.zeros(shape=xnew.shape, dtype=self.y.dtype)
for i in range(ynew.size):
diff = self.x ** 2 - xnew[i] ** 2
min_idx = np.argmin(np.abs(diff))
if np.abs(diff[min_idx]) <= self.eps:
ynew[i] = self.y[min_idx]
else:
ynew[i] = factor[i] * np.dot(self.coeff, self.y / diff)
return ynew
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment