Ulm-IQO / qudi-core

A framework for modular measurement applications.
GNU General Public License v3.0
38 stars 21 forks source link

[Hotfix] Util/maths broken for scipy > 1.12.0 #91

Closed timoML closed 7 months ago

timoML commented 7 months ago

Using the windows functions from scipy.signal has been deprecated since 1.8.0 scipy 1.1.0. Changing our imports to the new location will require to change in setup.py the requirements

'scipy>=1.7.1' to 'scipy>=1.8.0'

which should probably get some testing.

timoML commented 7 months ago

I looked through the scipy changelogs too quickly... Apparently, scipy.signal is deprecated even since scipy 1.1.0. This would mean that we could change the imports without touching setup.py.

@takuya-ulm Can you check that the changes proposed here work with 'scipy==1.7.1'?

takuya-ulm commented 7 months ago

I checked the source and found that we do not have to change the requirement.

Indeed, the windows functions have been moved to signal.windows for a long time. But, the code has been working because similar functions are created under signal at init file of signal.

deprecated_windows = ('boxcar', 'triang', 'parzen', 'bohman', 'blackman',
                      'nuttall', 'blackmanharris', 'flattop', 'bartlett',
                      'barthann', 'hamming', 'kaiser', 'gaussian',
                      'general_gaussian', 'chebwin', 'cosine',
                      'hann', 'exponential', 'tukey')

# backward compatibility imports for actually deprecated windows not
# in the above list
from .windows import hanning

def deco(name):
    f = getattr(windows, name)
    # Add deprecation to docstring

    def wrapped(*args, **kwargs):
        return f(*args, **kwargs)

    wrapped.__name__ = name
    wrapped.__module__ = 'scipy.signal'
    if hasattr(f, '__qualname__'):
        wrapped.__qualname__ = f.__qualname__

    if f.__doc__:
        lines = f.__doc__.splitlines()
        for li, line in enumerate(lines):
            if line.strip() == 'Parameters':
                break
        else:
            raise RuntimeError('dev error: badly formatted doc')
        spacing = ' ' * line.find('P')
        lines.insert(li, ('{0}.. warning:: scipy.signal.{1} is deprecated,\n'
                          '{0}             use scipy.signal.windows.{1} '
                          'instead.\n'.format(spacing, name)))
        wrapped.__doc__ = '\n'.join(lines)

    return wrapped

for name in deprecated_windows:
    locals()[name] = deco(name)

In the recent version, they are removed in the init file. That's the reason why the code at math.py is not working anymore.

The changes at math.py are enough for this problem.

timoML commented 7 months ago

Thanks for checking. Can you approve?