Skip to content

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

@tomvothecoder

Description

@tomvothecoder

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

Metadata

Metadata

Assignees

Labels

bugBug fix (will increment patch version)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions