Skip to content

Commit 7819f1b

Browse files
ev-brj-bowhay
andauthored
DEP: deprecate scipy.signal wavelets (scipy#19340)
* DEP: deprecate scipy.signal wavelets * MAINT: signal: add deprecated wavelets to the deprecated list in doc/conf.py * TST: use pytest.deprecated_call instead of filtering warnings --------- Co-authored-by: Jake Bowhay <[email protected]>
1 parent d720703 commit 7819f1b

File tree

4 files changed

+220
-137
lines changed

4 files changed

+220
-137
lines changed

doc/source/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,20 @@
328328
'interp2d` is deprecated', # Deprecation of scipy.interpolate.interp2d
329329
'scipy.misc', # scipy.misc deprecated in v1.10.0; use scipy.datasets
330330
'kurtosistest only valid', # intentionally "bad" excample in docstring
331+
'scipy.signal.daub is deprecated',
332+
'scipy.signal.qmf is deprecated',
333+
'scipy.signal.cascade is deprecated',
334+
'scipy.signal.morlet is deprecated',
335+
'scipy.signal.morlet2 is deprecated',
336+
'scipy.signal.ricker is deprecated',
337+
'scipy.signal.cwt is deprecated',
331338
):
332339
warnings.filterwarnings(action='ignore', message='.*' + key + '.*')
333340
334341
import numpy as np
335342
np.random.seed(123)
336343
"""
344+
337345
plot_include_source = True
338346
plot_formats = [('png', 96)]
339347
plot_html_show_formats = False

scipy/signal/_peak_finding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import math
55
import numpy as np
66

7-
from scipy.signal._wavelets import cwt, ricker
7+
from scipy.signal._wavelets import _cwt, _ricker
88
from scipy.stats import scoreatpercentile
99

1010
from ._peak_finding_utils import (
@@ -1300,9 +1300,9 @@ def find_peaks_cwt(vector, widths, wavelet=None, max_distances=None,
13001300
if max_distances is None:
13011301
max_distances = widths / 4.0
13021302
if wavelet is None:
1303-
wavelet = ricker
1303+
wavelet = _ricker
13041304

1305-
cwt_dat = cwt(vector, wavelet, widths)
1305+
cwt_dat = _cwt(vector, wavelet, widths)
13061306
ridge_lines = _identify_ridge_lines(cwt_dat, max_distances, gap_thresh)
13071307
filtered = _filter_ridge_lines(cwt_dat, ridge_lines, min_length=min_length,
13081308
window_size=window_size, min_snr=min_snr,

scipy/signal/_wavelets.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import numpy as np
24
from scipy.linalg import eig
35
from scipy.special import comb
@@ -6,8 +8,18 @@
68
__all__ = ['daub', 'qmf', 'cascade', 'morlet', 'ricker', 'morlet2', 'cwt']
79

810

11+
_msg="""scipy.signal.%s is deprecated in SciPy 1.12 and will be removed
12+
in SciPy 1.14. We recommend using PyWavelets instead.
13+
"""
14+
15+
916
def daub(p):
1017
"""
18+
.. deprecated:: 1.12.0
19+
20+
scipy.signal.daub is deprecated in SciPy 1.12 and will be removed
21+
in SciPy 1.14. We recommend using PyWavelets instead.
22+
1123
The coefficients for the FIR low-pass filter producing Daubechies wavelets.
1224
1325
p>=1 gives the order of the zero at f=1/2.
@@ -24,6 +36,8 @@ def daub(p):
2436
Return
2537
2638
"""
39+
warnings.warn(_msg % 'daub', DeprecationWarning, stacklevel=2)
40+
2741
sqrt = np.sqrt
2842
if p < 1:
2943
raise ValueError("p must be at least 1.")
@@ -77,6 +91,12 @@ def daub(p):
7791

7892
def qmf(hk):
7993
"""
94+
.. deprecated:: 1.12.0
95+
96+
scipy.signal.qmf is deprecated in SciPy 1.12 and will be removed
97+
in SciPy 1.14. We recommend using PyWavelets instead.
98+
99+
80100
Return high-pass qmf filter from low-pass
81101
82102
Parameters
@@ -90,13 +110,21 @@ def qmf(hk):
90110
High-pass filter coefficients.
91111
92112
"""
113+
warnings.warn(_msg % 'qmf', DeprecationWarning, stacklevel=2)
114+
93115
N = len(hk) - 1
94116
asgn = [{0: 1, 1: -1}[k % 2] for k in range(N + 1)]
95117
return hk[::-1] * np.array(asgn)
96118

97119

98120
def cascade(hk, J=7):
99121
"""
122+
.. deprecated:: 1.12.0
123+
124+
scipy.signal.cascade is deprecated in SciPy 1.12 and will be removed
125+
in SciPy 1.14. We recommend using PyWavelets instead.
126+
127+
100128
Return (x, phi, psi) at dyadic points ``K/2**J`` from filter coefficients.
101129
102130
Parameters
@@ -127,6 +155,8 @@ def cascade(hk, J=7):
127155
end.
128156
129157
"""
158+
warnings.warn(_msg % 'cascade', DeprecationWarning, stacklevel=2)
159+
130160
N = len(hk) - 1
131161

132162
if (J > 30 - np.log2(N + 1)):
@@ -203,6 +233,11 @@ def cascade(hk, J=7):
203233

204234
def morlet(M, w=5.0, s=1.0, complete=True):
205235
"""
236+
.. deprecated:: 1.12.0
237+
238+
scipy.signal.morlet is deprecated in SciPy 1.12 and will be removed
239+
in SciPy 1.14. We recommend using PyWavelets instead.
240+
206241
Complex Morlet wavelet.
207242
208243
Parameters
@@ -267,6 +302,8 @@ def morlet(M, w=5.0, s=1.0, complete=True):
267302
>>> plt.show()
268303
269304
"""
305+
warnings.warn(_msg % 'morlet', DeprecationWarning, stacklevel=2)
306+
270307
x = np.linspace(-s * 2 * np.pi, s * 2 * np.pi, M)
271308
output = np.exp(1j * w * x)
272309

@@ -280,6 +317,12 @@ def morlet(M, w=5.0, s=1.0, complete=True):
280317

281318
def ricker(points, a):
282319
"""
320+
.. deprecated:: 1.12.0
321+
322+
scipy.signal.ricker is deprecated in SciPy 1.12 and will be removed
323+
in SciPy 1.14. We recommend using PyWavelets instead.
324+
325+
283326
Return a Ricker wavelet, also known as the "Mexican hat wavelet".
284327
285328
It models the function:
@@ -315,6 +358,11 @@ def ricker(points, a):
315358
>>> plt.show()
316359
317360
"""
361+
warnings.warn(_msg % 'ricker', DeprecationWarning, stacklevel=2)
362+
return _ricker(points, a)
363+
364+
365+
def _ricker(points, a):
318366
A = 2 / (np.sqrt(3 * a) * (np.pi**0.25))
319367
wsq = a**2
320368
vec = np.arange(0, points) - (points - 1.0) / 2
@@ -327,6 +375,12 @@ def ricker(points, a):
327375

328376
def morlet2(M, s, w=5):
329377
"""
378+
.. deprecated:: 1.12.0
379+
380+
scipy.signal.morlet2 is deprecated in SciPy 1.12 and will be removed
381+
in SciPy 1.14. We recommend using PyWavelets instead.
382+
383+
330384
Complex Morlet wavelet, designed to work with `cwt`.
331385
332386
Returns the complete version of morlet wavelet, normalised
@@ -397,6 +451,8 @@ def morlet2(M, s, w=5):
397451
>>> plt.show()
398452
399453
"""
454+
warnings.warn(_msg % 'morlet2', DeprecationWarning, stacklevel=2)
455+
400456
x = np.arange(0, M) - (M - 1.0) / 2
401457
x = x / s
402458
wavelet = np.exp(1j * w * x) * np.exp(-0.5 * x**2) * np.pi**(-0.25)
@@ -406,6 +462,12 @@ def morlet2(M, s, w=5):
406462

407463
def cwt(data, wavelet, widths, dtype=None, **kwargs):
408464
"""
465+
.. deprecated:: 1.12.0
466+
467+
scipy.signal.cwt is deprecated in SciPy 1.12 and will be removed
468+
in SciPy 1.14. We recommend using PyWavelets instead.
469+
470+
409471
Continuous wavelet transform.
410472
411473
Performs a continuous wavelet transform on `data`,
@@ -479,6 +541,11 @@ def cwt(data, wavelet, widths, dtype=None, **kwargs):
479541
... vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max())
480542
>>> plt.show()
481543
"""
544+
warnings.warn(_msg % 'cwt', DeprecationWarning, stacklevel=2)
545+
return _cwt(data, wavelet, widths, dtype, **kwargs)
546+
547+
548+
def _cwt(data, wavelet, widths, dtype=None, **kwargs):
482549
# Determine output type
483550
if dtype is None:
484551
if np.asarray(wavelet(1, widths[0], **kwargs)).dtype.char in 'FDG':

0 commit comments

Comments
 (0)