Quasars / orange-spectroscopy

Other
52 stars 59 forks source link

Problem with Savitzky-Golay filter. #55

Closed RPCausin closed 7 years ago

RPCausin commented 7 years ago

Hi,

When I use the Savitzky-Golay filter, I get an error (see at the end). I think that the problem is that the numbers at Window, Polynomial Order and Derivative Order are got as floats and not as integers.

I had this problem with the Savitzky-Golay before and was able to solve it by reinstalling and updating all the packages. However, since I upgraded Orange-infrared to the most recent version, I get the same error and I can't solve it by reinstalling Orange and all the packages as I did before.

What I can do is to change

return savgol_filter(data.X, window_length=self.window,
                             polyorder=self.polyorder,
                             deriv=self.deriv, mode="nearest")

at line 136 of preprocess.py by

return savgol_filter(data.X, window_length=int(self.window),
                             polyorder=int(self.polyorder),
                             deriv=int(self.deriv), mode="nearest")

in order to ensure that the parameters are integers.

Anyway, I don't know why this happens and I just want to let you know about this because I'm not sure if the problem is me or there is anything wrong.

I'm using openSUSE Leap 42.1. Here is the error:

Exception:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Module:
scipy.signal._savitzky_golay:137
Widget Name:
Preprocess Spectra
Widget Module:
orangecontrib.infrared.widgets.owpreproc:1393
Widget Scheme:
/tmp/ows-kdmn1_34.ows.xml
Version:
3.4.dev0+eb53e99
Environment:
Python 3.4.5 on Linux 4.1.38-50-default #1 SMP PREEMPT Sun Feb 19 14:35:48 UTC 2017 (6b4d8cb) x86_64
Installed Packages:
AnyQt==0.0.8, Bottleneck==1.2.0, Orange-Infrared==0.1.3, Orange3==3.4.dev0+eb53e99, Sphinx==1.5.3, beautifulsoup4==4.5.3, chardet==2.3.0, dill==0.2.6, docutils==0.13.1, joblib==0.11, keyring==10.3, keyrings.alt==2.0, numpy==1.12.0, numpydoc==0.6.0, opusFC==1.1.0, pip==9.0.1, pyqtgraph==0.10.0, recommonmark==0.4.0, scikit-learn==0.18.1, scipy==0.18.1, setuptools==34.3.1, wheel==0.24.0, xlrd==1.0.0
Machine ID:
194080954254757
Stack Trace:
Traceback (most recent call last):
  File "/home/rperea/orange3env/lib/python3.4/site-packages/orangecontrib/infrared/widgets/owpreproc.py", line 54, in _dataChanged
    self.parent().on_modelchanged()
  File "/home/rperea/orange3env/lib/python3.4/site-packages/orangecontrib/infrared/widgets/owpreproc.py", line 1393, in on_modelchanged
    self.show_preview()
  File "/home/rperea/orange3env/lib/python3.4/site-packages/orangecontrib/infrared/widgets/owpreproc.py", line 1287, in show_preview
    data = preproc(data)
  File "/home/rperea/orange3env/lib/python3.4/site-packages/orangecontrib/infrared/preprocess.py", line 157, in __call__
    return data.from_table(domain, data)
  File "/home/rperea/orange3/Orange/data/table.py", line 366, in from_table
    is_sparse=sp.issparse(source.X))
  File "/home/rperea/orange3/Orange/data/table.py", line 315, in get_columns
    shared_cache[id(col.compute_shared), id(source)] = col.compute_shared(source)
  File "/home/rperea/orange3env/lib/python3.4/site-packages/orangecontrib/infrared/preprocess.py", line 138, in __call__
    deriv=self.deriv, mode="nearest")
  File "/home/rperea/orange3env/lib/python3.4/site-packages/scipy/signal/_savitzky_golay.py", line 337, in savgol_filter
    coeffs = savgol_coeffs(window_length, polyorder, deriv=deriv, delta=delta)
  File "/home/rperea/orange3env/lib/python3.4/site-packages/scipy/signal/_savitzky_golay.py", line 137, in savgol_coeffs
    y[deriv] = factorial(deriv) / (delta ** deriv)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Local Variables:
{'A': array([[ 1.,  1.,  1.,  1.,  1.],
       [ 2.,  1.,  0., -1., -2.],
       [ 4.,  1.,  0.,  1.,  4.]]),
 'delta': 1.0,
 'deriv': 1.0,
 'halflen': 2,
 'order': array([[0],
       [1],
       [2]]),
 'polyorder': 2,
 'pos': 2,
 'rem': 1,
 'use': 'conv',
 'window_length': 5,
 'x': array([ 2.,  1.,  0., -1., -2.]),
 'y': array([ 0.,  0.,  0.])}
markotoplak commented 7 years ago

Thank you for this report. It was fixed in b148df3. The new release with this fix is coming today.