ROBelgium / MSNoise

A Python Package for Monitoring Seismic Velocity Changes using Ambient Seismic Noise | http://www.msnoise.org
European Union Public License 1.1
172 stars 82 forks source link

Compatibility with latest SciPy - SciPy 1.9.0 removed scipy.signal.hanning #278

Closed kjdavidson closed 1 year ago

kjdavidson commented 1 year ago

Hello,

SciPy 1.9.0 deprecated scipy.signal.hanning - https://docs.scipy.org/doc/scipy/release.1.9.0.html?highlight=hann#expired-deprecations

This issue has also been mentioned over in ObsPy https://github.com/obspy/obspy/issues/3116

Running a fresh install of MSNoise 1.6.2 I get the following error when running msnoise test:

======================================================================
ERROR: test_024_mwcs (msnoise.test.tests.MSNoiseTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kdavidson/anaconda3/envs/test/lib/python3.8/site-packages/msnoise/test/tests.py", line 308, in test_024_mwcs
    main()
  File "/home/kdavidson/anaconda3/envs/test/lib/python3.8/site-packages/msnoise/s05compute_mwcs.py", line 163, in main
    output = mwcs(
  File "/home/kdavidson/anaconda3/envs/test/lib/python3.8/site-packages/msnoise/move2obspy.py", line 434, in mwcs
    dcur = np.sqrt(smooth(fcur2, window='hanning',
  File "/home/kdavidson/anaconda3/envs/test/lib/python3.8/site-packages/msnoise/move2obspy.py", line 304, in smooth
    w = scipy.signal.hanning(window_len).astype('complex')
AttributeError: module 'scipy.signal' has no attribute 'hanning'

----------------------------------------------------------------------

My environment:

Python:3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10) 
[GCC 10.3.0]
---------------+MODULES+-------------------
Required:
[X] setuptools: 65.4.0
[X] numpy: 1.23.3
[X] scipy: 1.9.1
[X] pandas: 1.5.0
[X] matplotlib: 3.6.0
[X] sqlalchemy: 1.4.41
[X] obspy: 1.2.2
[X] click: 8.1.3
[X] pymysql: 1.0.2
[X] flask: 2.2.2
[X] flask_admin: 1.6.0
[X] markdown: 3.4.1
[X] wtforms: 3.0.0
[X] folium: 0.12.1.post1
[X] jinja2: 3.1.2

It looks like the function has been moved into the scipy.signal.windows namespace. Changing the call to scipy.signal.hanning in the smooth() function on line 304 of move2obspy.py to scipy.signal.windows.hann appears to let the tests complete without error.

ThomasLecocq commented 1 year ago

thanks for this, indeed it's a breaking change in scipy, affecting a lot of packages. The next MSNoise release will take this into account.

ThomasLecocq commented 1 year ago

this is actually done in release 1.6.3, in master & in WIP MSNoise 2 - so should be safe to close now