From 75a1e6fb50d21ce404553d7c31fa555c05a64094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20M=C3=A5nsson?= Date: Sun, 15 Mar 2020 22:37:07 +0100 Subject: [PATCH] Workaround for plotting data containing NaNs Data containing NaNs doesn't render properly with the current versions of PyQtGraph (0.11.0rc0) and PyQt (5.14.x). This commit adds a function to work around this which is used in the distance detector. Related issues: https://github.com/SainsburyWellcomeCentre/lasagna/issues/247 https://github.com/pyqtgraph/pyqtgraph/issues/1057 Fix taken from here: https://github.com/pyqtgraph/pyqtgraph/issues/1057#issuecomment-543190337 Change-Id: Ia57dadc66551c171bd52da6379d4e8524e8a82bd --- examples/processing/distance_detector.py | 3 ++- src/acconeer/exptool/__init__.py | 2 +- src/acconeer/exptool/utils.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/processing/distance_detector.py b/examples/processing/distance_detector.py index 07e3776c2..663bbdfdb 100644 --- a/examples/processing/distance_detector.py +++ b/examples/processing/distance_detector.py @@ -661,7 +661,8 @@ def setup(self, win): def update(self, data): self.sweep_curve.setData(100.0 * self.r, data["sweep"]) self.mean_sweep_curve.setData(100.0 * self.r, data["last_mean_sweep"]) - self.threshold_curve.setData(100.0 * self.r, data["threshold"]) + utils.pg_curve_set_data_with_nan( # Workaround for bug in PyQt5/PyQtGraph + self.threshold_curve, 100.0 * self.r, data["threshold"]) m = max(2 * np.nanmax(data["threshold"]), np.max(data["sweep"]), diff --git a/src/acconeer/exptool/__init__.py b/src/acconeer/exptool/__init__.py index 4b2cd76c0..c64443811 100644 --- a/src/acconeer/exptool/__init__.py +++ b/src/acconeer/exptool/__init__.py @@ -1,3 +1,3 @@ -__version__ = "3.2.19" +__version__ = "3.2.20" SDK_VERSION = "2.1.0" diff --git a/src/acconeer/exptool/utils.py b/src/acconeer/exptool/utils.py index 414584224..2172a5313 100644 --- a/src/acconeer/exptool/utils.py +++ b/src/acconeer/exptool/utils.py @@ -391,3 +391,16 @@ def hex_to_rgb_tuple(hex_color): def is_power_of_2(n): return (n & (n - 1) == 0) and n != 0 + + +def pg_curve_set_data_with_nan(curve, x, y): + # Workaround for PyQt5 related bug in PyQtGraph where curves don't render if they contain NaNs + # https://github.com/SainsburyWellcomeCentre/lasagna/issues/247 + # https://github.com/pyqtgraph/pyqtgraph/issues/1057 + # https://github.com/pyqtgraph/pyqtgraph/issues/1057#issuecomment-543190337 + + z = np.array(y) + finite = np.isfinite(z) + z[~finite] = 0 + connect = np.logical_and(finite, np.roll(finite, -1)) + return curve.setData(x, z, connect=connect)