Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using FFT on data with one point #3018

Open
Python-simulation opened this issue May 2, 2024 · 1 comment
Open

Error when using FFT on data with one point #3018

Python-simulation opened this issue May 2, 2024 · 1 comment

Comments

@Python-simulation
Copy link

Python-simulation commented May 2, 2024

Activating the FFT transform on data with one point raises the following error:

File ~\anaconda3\lib\site-packages\pyqtgraph\graphicsItems\PlotDataItem.py:1190 in _fourierTransform
uniform = not np.any(np.abs(dx-dx[0]) > (abs(dx[0]) / 1000.))
IndexError: index 0 is out of bounds for axis 0 with size 0

This occurs because dx = np.diff(x) is empty when x is of size 1.

A possible solution is to add the following condition if len(x) == 1: return np.array([0]), abs(y) in the beginning of _fourierTransform in PlotDataItem.py.

  • PyQtGraph version: tested on 0.13.3 but will also raise same error in 0.13.7 has the relevant code has not changed.
@j9ac9k
Copy link
Member

j9ac9k commented May 2, 2024

We probably shouldn't be raising an exception, but I'm struggling to think of what the ideal behavior should be.

>>> np.fft.rfft(np.array([1]))
array([1.+0.j])
>>> np.fft.rfft(np.array([5]))
array([5.+0.j])

I do think the solution you've proposed is probably the best tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants