From ed5a36b38aceff1f468330d50c8263b822d8a8ec Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Sun, 28 Jun 2015 13:37:50 +0100 Subject: [PATCH] Moved demean/usePixdim logic from PlotPanel to TSPanel where it belongs --- fsl/fslview/views/plotpanel.py | 20 ++++++++------------ fsl/fslview/views/timeseriespanel.py | 26 ++++++++++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/fsl/fslview/views/plotpanel.py b/fsl/fslview/views/plotpanel.py index e49041b1d..b535261ed 100644 --- a/fsl/fslview/views/plotpanel.py +++ b/fsl/fslview/views/plotpanel.py @@ -42,6 +42,7 @@ class DataSeries(props.HasProperties): ('-.', 'Dash-dot line'), (':', 'Dotted line')])) + def __init__(self, overlay): self.overlay = overlay @@ -257,20 +258,15 @@ class PlotPanel(viewpanel.ViewPanel): if ds.alpha == 0: return (0, 0), (0, 0) - ydata = np.array(ds.getData(), dtype=np.float32) - npoints = len(ydata) - - if self.demean: - ydata = ydata - ydata.mean() + xdata, ydata = ds.getData() if self.smooth: - tck = interp.splrep(np.arange(npoints), ydata) - ydata = interp.splev(np.linspace(0, npoints - 1, 5 * npoints), tck) - - xdata = np.linspace(0, npoints - 1, len(ydata), dtype=np.float32) - - if self.usePixdim: - xdata *= ds.overlay.pixdim[3] + tck = interp.splrep(xdata, ydata) + xdata = np.linspace(xdata[0], + xdata[-1], + len(xdata) * 5, + dtype=np.float32) + ydata = interp.splev(xdata, tck) if self.xLogScale: xdata = np.log10(xdata) if self.yLogScale: ydata = np.log10(ydata) diff --git a/fsl/fslview/views/timeseriespanel.py b/fsl/fslview/views/timeseriespanel.py index 6094bd463..d4a0b7259 100644 --- a/fsl/fslview/views/timeseriespanel.py +++ b/fsl/fslview/views/timeseriespanel.py @@ -30,23 +30,33 @@ log = logging.getLogger(__name__) class TimeSeries(plotpanel.DataSeries): - def __init__(self, overlay, coords): + def __init__(self, tsPanel, overlay, coords): plotpanel.DataSeries.__init__(self, overlay) - - self.coords = map(int, coords) - self.data = overlay.data[coords[0], coords[1], coords[2], :] + + self.tsPanel = tsPanel + self.coords = map(int, coords) + self.data = overlay.data[coords[0], coords[1], coords[2], :] def getData(self): - return self.data + ydata = np.array( self.data, dtype=np.float32) + xdata = np.arange(len(ydata), dtype=np.float32) + + if self.tsPanel.usePixdim: + xdata *= self.overlay.pixdim[3] + + if self.tsPanel.demean: + ydata = ydata - ydata.mean() + + return xdata, ydata class TimeSeriesPanel(plotpanel.PlotPanel): """A panel with a :mod:`matplotlib` canvas embedded within. The volume data for each of the overlay objects in the - :class:`.OverlayList`, at the current :attr:`.DisplayContext.location` is - plotted on the canvas. + :class:`.OverlayList`, at the current :attr:`.DisplayContext.location` + is plotted on the canvas. """ @@ -136,7 +146,7 @@ class TimeSeriesPanel(plotpanel.PlotPanel): vox[2] >= overlay.shape[2]: return - ts = TimeSeries(overlay, vox) + ts = TimeSeries(self, overlay, vox) ts.colour = [0.2, 0.2, 0.2] ts.lineWidth = 1 ts.lineStyle = ':' -- GitLab