From 01e4e6763e01e0658ea38e26c6d33e27cb2b2a44 Mon Sep 17 00:00:00 2001 From: Python-simulation <46069237+Python-simulation@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:59:07 +0200 Subject: [PATCH] fixe fft from pyqtgraph wrap _fourierTransform to fixe pyqtgraph/issues/3018 before patch pyqtgraph/pull/3070 --- autolab/core/gui/GUI_utilities.py | 17 +++++++++++++++++ autolab/core/gui/scanning/figure.py | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/autolab/core/gui/GUI_utilities.py b/autolab/core/gui/GUI_utilities.py index 86946de6..4b2360a1 100644 --- a/autolab/core/gui/GUI_utilities.py +++ b/autolab/core/gui/GUI_utilities.py @@ -15,8 +15,24 @@ from ..config import get_GUI_config + +# Fixes pyqtgraph/issues/3018 for pg<=0.13.7 (before pyqtgraph/pull/3070) +from pyqtgraph.graphicsItems.PlotDataItem import PlotDataItem + +if hasattr(PlotDataItem, '_fourierTransform'): + + _fourierTransform_bugged = PlotDataItem._fourierTransform + + def _fourierTransform_fixed(self, x, y): + if len(x) == 1: return np.array([0]), abs(y) + return _fourierTransform_bugged(self, x, y) + + PlotDataItem._fourierTransform = _fourierTransform_fixed + + ONCE = False + def get_font_size() -> int: GUI_config = get_GUI_config() if GUI_config['font_size'] != 'default': @@ -189,6 +205,7 @@ def update_img(self, x, y, z): self.img = img self.ax.addItem(self.img) + def pyqtgraph_fig_ax() -> Tuple[MyGraphicsLayoutWidget, pg.PlotItem]: """ Return a formated fig and ax pyqtgraph for a basic plot """ fig = MyGraphicsLayoutWidget() diff --git a/autolab/core/gui/scanning/figure.py b/autolab/core/gui/scanning/figure.py index aab6d0cf..86e9a626 100644 --- a/autolab/core/gui/scanning/figure.py +++ b/autolab/core/gui/scanning/figure.py @@ -632,7 +632,6 @@ def reloadData(self): alpha = (true_nbtraces - (len(data) - 1 - i)) / true_nbtraces # Plot - # OPTIMIZE: known issue but from pyqtgraph, error if use FFT on one point # careful, now that can filter data, need .values to avoid pyqtgraph bug curve = self.ax.plot(x.values, y.values, symbol='x', symbolPen=color, symbolSize=10,