From f632b02985b87e1fb8e78e14c82e5c5597c2dee5 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 5 Feb 2017 23:13:00 -0800 Subject: [PATCH] Add unit test covering plotdataitem fft --- pyqtgraph/graphicsItems/PlotDataItem.py | 27 ------------------- .../graphicsItems/tests/test_PlotDataItem.py | 25 +++++++++++++++++ 2 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 pyqtgraph/graphicsItems/tests/test_PlotDataItem.py diff --git a/pyqtgraph/graphicsItems/PlotDataItem.py b/pyqtgraph/graphicsItems/PlotDataItem.py index a26c1c72..d7ea5100 100644 --- a/pyqtgraph/graphicsItems/PlotDataItem.py +++ b/pyqtgraph/graphicsItems/PlotDataItem.py @@ -500,27 +500,10 @@ class PlotDataItem(GraphicsObject): if self.xData is None: return (None, None) - #if self.xClean is None: - #nanMask = np.isnan(self.xData) | np.isnan(self.yData) | np.isinf(self.xData) | np.isinf(self.yData) - #if nanMask.any(): - #self.dataMask = ~nanMask - #self.xClean = self.xData[self.dataMask] - #self.yClean = self.yData[self.dataMask] - #else: - #self.dataMask = None - #self.xClean = self.xData - #self.yClean = self.yData - if self.xDisp is None: x = self.xData y = self.yData - - #ds = self.opts['downsample'] - #if isinstance(ds, int) and ds > 1: - #x = x[::ds] - ##y = resample(y[:len(x)*ds], len(x)) ## scipy.signal.resample causes nasty ringing - #y = y[::ds] if self.opts['fftMode']: x,y = self._fourierTransform(x, y) # Ignore the first bin for fft data if we have a logx scale @@ -531,14 +514,6 @@ class PlotDataItem(GraphicsObject): x = np.log10(x) if self.opts['logMode'][1]: y = np.log10(y) - #if any(self.opts['logMode']): ## re-check for NANs after log - #nanMask = np.isinf(x) | np.isinf(y) | np.isnan(x) | np.isnan(y) - #if any(nanMask): - #self.dataMask = ~nanMask - #x = x[self.dataMask] - #y = y[self.dataMask] - #else: - #self.dataMask = None ds = self.opts['downsample'] if not isinstance(ds, int): @@ -591,8 +566,6 @@ class PlotDataItem(GraphicsObject): self.xDisp = x self.yDisp = y - #print self.yDisp.shape, self.yDisp.min(), self.yDisp.max() - #print self.xDisp.shape, self.xDisp.min(), self.xDisp.max() return self.xDisp, self.yDisp def dataBounds(self, ax, frac=1.0, orthoRange=None): diff --git a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py new file mode 100644 index 00000000..dc13bb7a --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py @@ -0,0 +1,25 @@ +import numpy as np +import pyqtgraph as pg + +pg.mkQApp() + + +def test_fft(): + f = 20. + x = np.linspace(0, 1, 1000) + y = np.sin(2 * np.pi * f * x) + pd = pg.PlotDataItem(x, y) + pd.setFftMode(True) + x, y = pd.getData() + assert abs(x[np.argmax(y)] - f) < 0.03 + + x = np.linspace(0, 1, 1001) + y = np.sin(2 * np.pi * f * x) + pd.setData(x, y) + x, y = pd.getData() + assert abs(x[np.argmax(y)]- f) < 0.03 + + pd.setLogMode(True, False) + x, y = pd.getData() + assert abs(x[np.argmax(y)] - np.log10(f)) < 0.01 + \ No newline at end of file