Skip to content

Commit

Permalink
Merge pull request #257 from European-XFEL/dev
Browse files Browse the repository at this point in the history
0.9.1
  • Loading branch information
zhujun98 authored Jul 15, 2020
2 parents 03117a2 + 6218b9c commit 9901ad3
Show file tree
Hide file tree
Showing 65 changed files with 2,562 additions and 3,281 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ EXtra-foam

![Overview](docs/images/extra_foam_0.9.0.jpg)

*EXtra-foam* (previously known as *[karaboFAI](https://in.xfel.eu/readthedocs/docs/karabofai/en/latest/)*) is a
framework that provides super fast on-line (real-time) and off-line data analysis and visualization for
experiments at European XFEL that using 2D detectors (e.g. AGIPD, DSSC, LPD, ePix100, FastCCD, JungFrau,
etc.), together with other 1D detectors (e.g. XGM, digitizer, etc.) and various control data.
*EXtra-foam* is a framework that provides real-time and off-line data analysis (**detector geometry**,
**pump-probe**, **azimuthal integration**, **ROI**, **statistics**, etc.) and visualization for experiments
that use **2D area detectors** (*AGIPD*, *LPD*, *DSSC*, *FastCCD*, *JungFrau*, *ePix100*, etc.) and
**1D detectors** (*Gotthard*, *XGM*, *digitizer*, etc.) at European XFEL.

[Documentation](https://extra-foam.readthedocs.io/en/latest/)
171 changes: 171 additions & 0 deletions benchmarks/azimuthal_integration.ipynb
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
}
7 changes: 5 additions & 2 deletions benchmarks/gui/benchmark_imageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
All rights reserved.
"""
import time
from collections import deque

import numpy as np

Expand All @@ -21,6 +22,8 @@

class BenchmarkImageViewSpeed:
def __init__(self):
self._dt = deque(maxlen=60)

self._timer = QTimer()
self._timer.timeout.connect(self.update)

Expand All @@ -40,9 +43,9 @@ def update(self):
self._count += 1

now = time.time()
dt = now - self._prev_t
self._dt.append(now - self._prev_t)
self._prev_t = now
fps = 1.0/dt
fps = len(self._dt) / sum(self._dt)

self._view.setTitle(f"{fps:.2f} fps")

Expand Down
21 changes: 13 additions & 8 deletions benchmarks/gui/benchmark_plotwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
import time
from enum import IntEnum
from collections import deque

import numpy as np

Expand All @@ -29,24 +30,28 @@ class PlotType(IntEnum):

class BenchmarkPlotItemSpeed:
def __init__(self, plot_type=PlotType.Line):
self._dt = deque(maxlen=60)

self._timer = QTimer()
self._timer.timeout.connect(self.update)
# self._timer.singleShot(1, self.update)

self._widget = PlotWidgetF()
self._widget.addLegend()

if plot_type == PlotType.Line:
self._graph = self._widget.plotCurve()
self._graph = self._widget.plotCurve(name='line')
n_pts = 5000
elif plot_type == PlotType.Bar:
self._graph = self._widget.plotBar()
self._graph = self._widget.plotBar(name='bar')
n_pts = 300
elif plot_type == PlotType.StatisticsBar:
self._graph = self._widget.plotStatisticsBar()
self._graph = self._widget.plotStatisticsBar(name='statistics bar')
self._graph.setBeam(1)
n_pts = 500
elif plot_type == PlotType.Scatter:
self._graph = self._widget.plotScatter()
n_pts = 3000
self._graph = self._widget.plotScatter(name='scatter')
n_pts = 5000
else:
raise ValueError(f"Unknown plot type: {plot_type}")

Expand Down Expand Up @@ -77,16 +82,16 @@ def update(self):
self._count += 1

now = time.time()
dt = now - self._prev_t
self._dt.append(now - self._prev_t)
self._prev_t = now
fps = 1.0 / dt
fps = len(self._dt) / sum(self._dt)

self._widget.setTitle(f"{fps:.2f} fps")

app.processEvents() # force complete redraw for every plot


if __name__ == '__main__':
bench = BenchmarkPlotItemSpeed(PlotType.Line)
bench = BenchmarkPlotItemSpeed(PlotType.Scatter)
bench.start()
app.exec_()
20 changes: 20 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
CHANGELOG
=========

0.9.1 (15 July 2020)
------------------------

- **Bug Fix**

- Fix transform type update in TransformView in ImageTool. #251

- **Improvement**

- PlotItem will not be shown in legend if its name is empty. #254
- Improve y2-axis plot implementation. #253
- Improve stack detector modules. #247
- Implement ScatterPlotItem to replace the pyqtgraph one. #238

- **New Feature**

- Implement curve fitting in correlation window. #255
- Implement azimuthal integration and concentric ring detection in C++. #252


0.9.0 (30 June 2020)
------------------------

Expand Down
Loading

0 comments on commit 9901ad3

Please sign in to comment.