Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: AttributeError: module 'scipy.signal' has no attribute 'cwt' (deprecated, use PyWavelets instead) #912

Open
3 tasks
tomvothecoder opened this issue Jan 14, 2025 · 1 comment
Assignees
Labels
bug Bug fix (will increment patch version)

Comments

@tomvothecoder
Copy link
Collaborator

tomvothecoder commented Jan 14, 2025

What happened?

Per https://docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.signal.cwt.html:

    .. deprecated:: 1.12.0

        scipy.signal.cwt is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

What did you expect to happen? Are there are possible answers you came across?

  • Add PyWavelets to dev.yml, ci.yml and pyproject.toml
  • Replace scipy.signal.cwt with PyWavelets
    • Tuple(np.ndarray, np.ndarray)
      The period and PSD arrays.
      """
      deg = 6
      period = np.arange(1, 55 + 1)
      freq = 1 / period
      widths = deg / (2 * np.pi * freq)
      cwtmatr = scipy.signal.cwt(data, scipy.signal.morlet2, widths=widths, w=deg)
      psd = np.mean(np.square(np.abs(cwtmatr)), axis=1)
      return (period, psd)
  • Update E3SM Unified notes that PyWavelets is a new dependency

Minimal Complete Verifiable Example (MVCE)

No response

Relevant log output

Traceback (most recent call last):
  File "/__w/e3sm_diags/e3sm_diags/e3sm_diags/parameter/core_parameter.py", line 340, in _run_diag
    single_result = module.run_diag(self)
  File "/__w/e3sm_diags/e3sm_diags/e3sm_diags/driver/qbo_driver.py", line 100, in run_diag
    test_dict["wave_period"], test_dict["wavelet"] = _calculate_wavelet(
  File "/__w/e3sm_diags/e3sm_diags/e3sm_diags/driver/qbo_driver.py", line 390, in _calculate_wavelet
    wave_period, wavelet = _get_psd_from_wavelet(detrended_data)
  File "/__w/e3sm_diags/e3sm_diags/e3sm_diags/driver/qbo_driver.py", line 418, in _get_psd_from_wavelet
    cwtmatr = scipy.signal.cwt(data, scipy.signal.morlet2, widths=widths, w=deg)
AttributeError: module 'scipy.signal' has no attribute 'cwt'. Did you mean: 'czt'?

Anything else we need to know?

Found in PR #907, where integration tests are breaking due to this issue.

Related SciPy docs:

Related PyWavelets docs:

Environment

Latest e3sm_diags on main
scipy=1.15.1

@tomvothecoder tomvothecoder added the bug Bug fix (will increment patch version) label Jan 14, 2025
@tomvothecoder tomvothecoder self-assigned this Jan 14, 2025
@xylar
Copy link
Contributor

xylar commented Jan 15, 2025

@tomvothecoder, @chengzhuzhang, @whannah1, I would prefer not to delay Unified testing for this. Could we consider constraining scipy<1.15 in e3sm_diags for the time being while you all work this out?

A second question: do you all have a strategy for detecting deprecation warnings like this (e.g. as outputs from your testing) so they can be addressed before they become a last-minute problem? I know tests spit out a lot of deprecation warnings and sometimes they're related to other tools (like xarray) but they can sometimes be a helpful indication that something like this is coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fix (will increment patch version)
Projects
None yet
Development

No branches or pull requests

2 participants