laszukdawid / PyEMD

Python implementation of Empirical Mode Decompoisition (EMD) method
https://pyemd.readthedocs.io/
Apache License 2.0
867 stars 224 forks source link

EMD_good_corr.py error #2

Closed donaldtone closed 7 years ago

donaldtone commented 7 years ago

python 3.5.2, windows 10

C:\ProgramData\Anaconda3\python.exe "D:/AI/workspace/ML study/1-Basic/PyEMD-master/PyEMD/EMD_good_corr.py" Input S.dtype: float32 DEBUG:main:IMF -- 0 Traceback (most recent call last): File "D:/AI/workspace/ML study/1-Basic/PyEMD-master/PyEMD/EMD_good_corr.py", line 1018, in IMF, EXT, ITER, imfNo = emd.emd(S, timeLine, maxImf) File "D:/AI/workspace/ML study/1-Basic/PyEMD-master/PyEMD/EMD_good_corr.py", line 885, in emd maxEnv, minEnv, eMax, eMin = self.extractMaxMinSpline(timeLine, imf) File "D:/AI/workspace/ML study/1-Basic/PyEMD-master/PyEMD/EMD_good_corr.py", line 113, in extractMaxMinSpline maxTSpline, maxSpline = self.splinePoints(T, maxExtrema, self.splineKind) File "D:/AI/workspace/ML study/1-Basic/PyEMD-master/PyEMD/EMD_good_corr.py", line 311, in splinePoints return t, interp1d(extrema[0], extrema[1], kind=kind)(t).astype(self.DTYPE) File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\interpolate\interpolate.py", line 496, in init check_finite=False) File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\interpolate_bsplines.py", line 702, in make_interp_spline _bspl._colloc(x, t, k, ab, offset=nleft) File "scipy/interpolate/_bspl.pyx", line 225, in scipy.interpolate._bspl._colloc (scipy\interpolate_bspl.c:4300) ValueError: Buffer dtype mismatch, expected 'double' but got 'float'

Process finished with exit code 1

laszukdawid commented 7 years ago

Thanks @donaldtone for pointing this out :) In all honesty, this was not intended to be used for now, but since you brought it up I might soon take a look at making it up-to-date. (Same as with _matlab.py.)

laszukdawid commented 7 years ago

It seems that the error is due to SciPy interpolation interp1d method not supporting float32 type, only float64 (double). Changing type to double, i.e. (line 987) TYPE = 64, fixes the issue. Before I commit the solution I'd like to make sure that the rest works fine as well. SciPy issue: scipy/scipy#7273

laszukdawid commented 7 years ago

Again, thanks @donaldtone for pointing this out. It motivated me to go through this much quicker than I initially thought. With merge #3 it the default settings should not result in this issue. In short, for now I'm not supporting interpolation in single floats (numpy.float32), because NumPy does not. I'll try to submit patch to NumPy later to handle this, but for now it should be fine.

I've also cleaned those files (EMD_good_cor.py and EMD_matlab.py) a little, so they should be more readable. Hopefully next step is documentation :)

laszukdawid commented 7 years ago

Thanks again @donaldtone for pointing this issue. It motivated me to quickly go through EMD_good_cor.py and EMD_matlab.py files cleaning them and updating. They're now merged into master branch, so the issue that you noted is fixed. Long story short, currently float32 (single float) is not supported on cubic splines. Scipy, through Numpy, by default does some conversion which in my understanding should be illegal, but it makes sense in broad scheme.