From 3b60dc74b60f5aaf5adecb0d821147ffab41fba8 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 1 Jul 2015 17:10:54 +0100
Subject: [PATCH] Added a bunch of edge-cases for bad plot data

---
 fsl/fslview/views/histogrampanel.py |  6 ++++++
 fsl/fslview/views/plotpanel.py      | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/fsl/fslview/views/histogrampanel.py b/fsl/fslview/views/histogrampanel.py
index 3168107f7..b4b700144 100644
--- a/fsl/fslview/views/histogrampanel.py
+++ b/fsl/fslview/views/histogrampanel.py
@@ -215,6 +215,12 @@ class HistogramSeries(plotpanel.DataSeries):
         log.debug('Calculating histogram for '
                   'overlay {}'.format(self.overlay.name))
 
+        if self.dataRange.xhi - self.dataRange.xlo < 0.00000001:
+            self.xdata = np.array([])
+            self.ydata = np.array([])
+            self.nvals = 0
+            return
+
         if self.ignoreZeros:
             if self.includeOutliers: data = self.nonZeroData
             else:                    data = self.clippedNonZeroData
diff --git a/fsl/fslview/views/plotpanel.py b/fsl/fslview/views/plotpanel.py
index a4b5ee46e..f7da6140e 100644
--- a/fsl/fslview/views/plotpanel.py
+++ b/fsl/fslview/views/plotpanel.py
@@ -196,6 +196,13 @@ class PlotPanel(viewpanel.ViewPanel):
 
         (xmin, xmax), (ymin, ymax) = self.__calcLimits(xlims, ylims)
 
+        if xmax - xmin < 0.0000000001 or \
+           ymax - ymin < 0.0000000001:
+            axis.clear()
+            canvas.draw()
+            self.Refresh()
+            return
+
         # x/y axis labels
         xlabel = self.xlabel 
         ylabel = self.ylabel
@@ -269,6 +276,9 @@ class PlotPanel(viewpanel.ViewPanel):
 
         xdata, ydata = ds.getData()
 
+        if len(xdata) != len(ydata) or len(xdata) == 0:
+            return (0, 0), (0, 0)
+
         # Note to self: If the smoothed data is
         # filled with NaNs, it is possibly due
         # to duplicate values in the x data, which
@@ -290,6 +300,9 @@ class PlotPanel(viewpanel.ViewPanel):
         xdata[nans] = np.nan
         ydata[nans] = np.nan
 
+        if np.all(np.isnan(xdata) | np.isnan(ydata)):
+            return (0, 0), (0, 0)
+
         kwargs = plotArgs
         kwargs['lw']    = kwargs.get('lw',    ds.lineWidth)
         kwargs['alpha'] = kwargs.get('alpha', ds.alpha)
-- 
GitLab