hippalectryon-0 / xr-scipy

scipy for xarray eco-system
http://xr-scipy.readthedocs.io
61 stars 9 forks source link

FIX: scipy api change #16

Closed filipito closed 1 year ago

filipito commented 2 years ago

I was using xr-scipy recently and I got the following error:

/home/filipito/.local/lib/python3.8/site-packages/xarray_dsp/filters.py:379: AccessorRegistrationWarning: registration of accessor <class 'xarray_dsp.filters.FilterAccessor'> under name 'filt' for type <class 'xarray.core.dataarray.DataArray'> is overriding a preexisting attribute with the same name.
  class FilterAccessor(object):
Traceback (most recent call last):
  File "/home/filipito/skola/diplomka/data/processing_main.py", line 105, in <module>
    analyze(39796)
  File "/home/filipito/skola/diplomka/data/processing_main.py", line 82, in analyze
    spectrogram = dsp.spectrogram(sel_plasma, nperseg=512, dim='time')
  File "/home/filipito/anaconda3/envs/tjii_data/lib/python3.8/site-packages/xrscipy/signal/spectral.py", line 322, in spectrogram
    Pxx = crossspectrogram(darray, darray, fs, seglen, overlap_ratio, window,
  File "/home/filipito/anaconda3/envs/tjii_data/lib/python3.8/site-packages/xrscipy/signal/spectral.py", line 150, in crossspectrogram
    f, t, Pxy = scipy.signal.spectral._spectral_helper(d_val,
  File "/home/filipito/.local/lib/python3.8/site-packages/scipy/signal/spectral.py", line 24, in __getattr__
    raise AttributeError(
AttributeError: scipy.signal.spectral is deprecated and has no attribute _spectral_helper. Try looking in scipy.signal instead. 

It seems to be introduced with scipy version 1.8.0 where the scipy.signal.spectral.py became deprecated but the _spectral_helper was moved to scipy.signal._spectral_py.py (effectively it was just a rename of spectral.py to _spectral_py.py). I have found two ways to fix this error, I do not know which one of them is preferable so I have not created a pull request.

  1. change the setup to require scipy version <= 1.7.3
  2. or change line 149 in the referenced file to this: f, t, Pxy = scipy.signal._spectral_py._spectral_helper(d_val,

https://github.com/fujiisoup/xr-scipy/blob/ee7e8fb438c3c2e0bdd73885f39df862d1b9f114/xrscipy/signal/spectral.py#L149-L154

hippalectryon-0 commented 1 year ago

Fixed in dev0