Merge pull request #436 from campagnola/fft-test
Add unit test covering plotdataitem fft
This commit is contained in:
commit
dd5a8bf9d1
@ -500,27 +500,10 @@ class PlotDataItem(GraphicsObject):
|
|||||||
if self.xData is None:
|
if self.xData is None:
|
||||||
return (None, 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:
|
if self.xDisp is None:
|
||||||
x = self.xData
|
x = self.xData
|
||||||
y = self.yData
|
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']:
|
if self.opts['fftMode']:
|
||||||
x,y = self._fourierTransform(x, y)
|
x,y = self._fourierTransform(x, y)
|
||||||
# Ignore the first bin for fft data if we have a logx scale
|
# Ignore the first bin for fft data if we have a logx scale
|
||||||
@ -531,14 +514,6 @@ class PlotDataItem(GraphicsObject):
|
|||||||
x = np.log10(x)
|
x = np.log10(x)
|
||||||
if self.opts['logMode'][1]:
|
if self.opts['logMode'][1]:
|
||||||
y = np.log10(y)
|
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']
|
ds = self.opts['downsample']
|
||||||
if not isinstance(ds, int):
|
if not isinstance(ds, int):
|
||||||
@ -591,8 +566,6 @@ class PlotDataItem(GraphicsObject):
|
|||||||
|
|
||||||
self.xDisp = x
|
self.xDisp = x
|
||||||
self.yDisp = y
|
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
|
return self.xDisp, self.yDisp
|
||||||
|
|
||||||
def dataBounds(self, ax, frac=1.0, orthoRange=None):
|
def dataBounds(self, ax, frac=1.0, orthoRange=None):
|
||||||
|
25
pyqtgraph/graphicsItems/tests/test_PlotDataItem.py
Normal file
25
pyqtgraph/graphicsItems/tests/test_PlotDataItem.py
Normal file
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user