-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from European-XFEL/dev
0.9.1
- Loading branch information
Showing
65 changed files
with
2,562 additions
and
3,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# EXtra-foam azimuthal integration benchmark" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os.path as osp\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"from pyFAI.azimuthalIntegrator import AzimuthalIntegrator as PyfaiAzimuthalIntegrator\n", | ||
"from scipy.signal import find_peaks\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"import extra_foam\n", | ||
"print(extra_foam.__version__)\n", | ||
"\n", | ||
"from extra_foam.algorithms import AzimuthalIntegrator, ConcentricRingsFinder\n", | ||
"from extra_foam.algorithms import mask_image_data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def load_image(filepath):\n", | ||
" img = np.load(osp.join(osp.expanduser('~'), filepath))\n", | ||
" mask = np.zeros_like(img, dtype=bool)\n", | ||
" mask_image_data(img, out=mask)\n", | ||
" _, ax = plt.subplots(figsize=(12, 12))\n", | ||
" ax.imshow(img)\n", | ||
" \n", | ||
" return img, mask\n", | ||
"\n", | ||
"# img, mask = load_image(\"jf_ring.npy\")\n", | ||
"img, mask = load_image(\"jf_ring_6modules.npy\")\n", | ||
"# img, mask = load_image(\"lpd.npy\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dist = 1 # sample distance\n", | ||
"npt = 1024 # number of integration points\n", | ||
"pixel1, pixel2 = 0.75e-6, 0.75e-6 # pixel size (y, x)\n", | ||
"cy, cx = 537, 1132 \n", | ||
"poni1, poni2 = cy * pixel1, cx * pixel2 # integration center (y, x)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# %%timeit\n", | ||
"\n", | ||
"pyfai_integrator = PyfaiAzimuthalIntegrator(\n", | ||
" dist=dist, poni1=poni1, poni2=poni2, pixel1=pixel1, pixel2=pixel2, wavelength=1e-10)\n", | ||
"\n", | ||
"q_gt, I_gt = pyfai_integrator.integrate1d(img, npt, mask=mask, unit=\"q_A^-1\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# %%timeit\n", | ||
"\n", | ||
"integrator = AzimuthalIntegrator(\n", | ||
" dist=dist, poni1=poni1, poni2=poni2, pixel1=pixel1, pixel2=pixel2, wavelength=1e-10)\n", | ||
"\n", | ||
"q, I = integrator.integrate1d(img, npt=npt)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_, ax = plt.subplots(figsize=(12, 6))\n", | ||
"\n", | ||
"ax.plot(1e-10 * q, I, '-', label='EXtra-foam')\n", | ||
"ax.plot(q_gt, I_gt, '--', label='pyFAI')\n", | ||
"ax.set_xlabel(\"q (1/A)\", fontsize=16)\n", | ||
"ax.set_ylabel(\"I (arb.)\", fontsize=16)\n", | ||
"ax.legend(fontsize=16)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# %%timeit\n", | ||
"\n", | ||
"min_count = 500\n", | ||
"prominence = 100\n", | ||
"distance = 10\n", | ||
"\n", | ||
"finder = ConcentricRingsFinder(pixel2, pixel1)\n", | ||
"cx, cy = finder.search(img, cx, cy, min_count=min_count)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"q, s = finder.integrate(img, cx, cy, min_count=min_count)\n", | ||
"\n", | ||
"i_peaks = find_peaks(s, distance=distance, prominence=prominence)[0]\n", | ||
"\n", | ||
"_, ax = plt.subplots(figsize=(12, 6))\n", | ||
"\n", | ||
"ax.plot(q, s, '-')\n", | ||
"ax.plot(q[i_peaks], s[i_peaks], 'x')\n", | ||
"ax.set_xlabel(\"Radial (pixel)\", fontsize=16)\n", | ||
"ax.set_ylabel(\"I (arb.)\", fontsize=16)\n", | ||
"\n", | ||
"print(\"Optimized cx = \", cx, \", cy = \", cy)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "foam-gcc6", | ||
"language": "python", | ||
"name": "foam-gcc6" | ||
}, | ||
"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.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.