Skip to content

Commit

Permalink
Workaround for plotting data containing NaNs
Browse files Browse the repository at this point in the history
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:
SainsburyWellcomeCentre/lasagna#247
pyqtgraph/pyqtgraph#1057

Fix taken from here:
pyqtgraph/pyqtgraph#1057 (comment)

Change-Id: Ia57dadc66551c171bd52da6379d4e8524e8a82bd
  • Loading branch information
erikmansson committed Mar 16, 2020
1 parent 71b8d17 commit 75a1e6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/processing/distance_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down
2 changes: 1 addition & 1 deletion src/acconeer/exptool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "3.2.19"
__version__ = "3.2.20"

SDK_VERSION = "2.1.0"
13 changes: 13 additions & 0 deletions src/acconeer/exptool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 75a1e6f

Please sign in to comment.