cokelaer / spectrum

Spectral Analysis in Python
http://pyspectrum.readthedocs.io
BSD 3-Clause "New" or "Revised" License
339 stars 90 forks source link

scipy fftn produces warning that numpy fftn does not #51

Closed anielsen001 closed 4 years ago

anielsen001 commented 6 years ago

When working on addressing the deprecation warning announced in #49 , I found that the scipy.fftpack.fftn produces a different warning:

import numpy as np
from scipy.fftpack import fftn
a = np.random.random([16,16])
fftn(a, [32,32])      

/home/apn/proj/spectrum/lib/python3.6/site-packages/scipy-1.1.0-py3.6-linux-x86_64.egg/scipy/fftpack/basic.py:160: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use arr[tuple(seq)] instead of arr[seq]. In the future this will be interpreted as an array index, arr[np.array(seq)], which will result either in an error or a different result. z[index] = x

If you use the numpy version of fftn, this warning goes away, and the answers are the same:

np.allclose(np.fft.fftn(a,[32,32]) , fftn(a, [32,32]))

is True

I'm not sure if there's a reason to choose one of the fftn over another, but the warning appears to come from scipy and could be removed by switching to the numpy version.

I'm suing scipy 1.1.0, numpy 1.15.2 and python 3.6.5

cokelaer commented 5 years ago

Thanks for reporting this warning. For book-keeping, not seen with python 3.5.5, scipy 1.0 and numpy 1.14.1 does not show this warning. Interesting to see that fft version from numpy is without warning. I'm keeping this issue open for now.

anielsen001 commented 5 years ago

It turns out that scipy and numpy use different code to implement their ffts. There's some explanation here that his helpful. https://stackoverflow.com/questions/6363154/what-is-the-difference-between-numpy-fft-and-scipy-fftpack

I have not thought too much about which is better in this case.

cokelaer commented 4 years ago

no more warnings with current version of python (3.7.3) and latest scipy/numpy version. closing for now