From ca8b6070e35dc4cb3a7217142461093b2506f31f Mon Sep 17 00:00:00 2001 From: OverLordGoldDragon <16495490+OverLordGoldDragon@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:56:37 +0400 Subject: [PATCH 1/6] Allow user to set `precision`, increase default to 12 --- pywt/_cwt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index 8158caca..7bbb1598 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -24,7 +24,7 @@ def next_fast_len(n): return 2**ceil(np.log2(n)) -def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): +def cwt(data, scales, wavelet, sampling_period=1., method='conv', precision=12, axis=-1): """ cwt(data, scales, wavelet) @@ -57,6 +57,11 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): The ``fft`` method is ``O(N * log2(N))`` with ``N = len(scale) + len(data) - 1``. It is well suited for large size signals but slightly slower than ``conv`` on small ones. + precision: int, optional + Length of wavelet (2 ** precision) used to compute the CWT. Greater + will increase resolution, especially for lower and higher scales, + but compute a bit slower. Too low will distort coefficients + and their norms, with a zipper-like effect; recommended >= 12. axis: int, optional Axis over which to compute the CWT. If not given, the last axis is used. @@ -116,7 +121,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): dt_out = dt_cplx if wavelet.complex_cwt else dt out = np.empty((np.size(scales),) + data.shape, dtype=dt_out) - precision = 10 + int_psi, x = integrate_wavelet(wavelet, precision=precision) int_psi = np.conj(int_psi) if wavelet.complex_cwt else int_psi From a518fbc0fd602783ae61f1300c1f3bcc069d4bda Mon Sep 17 00:00:00 2001 From: OverLordGoldDragon <16495490+OverLordGoldDragon@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:17:29 +0400 Subject: [PATCH 2/6] Edit docstring Higher `precision` doesn't help with lower scales --- pywt/_cwt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index 7bbb1598..f73b499f 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -59,9 +59,9 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', precision=12, signals but slightly slower than ``conv`` on small ones. precision: int, optional Length of wavelet (2 ** precision) used to compute the CWT. Greater - will increase resolution, especially for lower and higher scales, - but compute a bit slower. Too low will distort coefficients - and their norms, with a zipper-like effect; recommended >= 12. + will increase resolution, especially for higher scales, but will + compute a bit slower. Too low will distort coefficients and their + norms, with a zipper-like effect; recommended >= 12. axis: int, optional Axis over which to compute the CWT. If not given, the last axis is used. From 016da31807bd17560cef44226e4560ea6bde0a33 Mon Sep 17 00:00:00 2001 From: OverLordGoldDragon <16495490+OverLordGoldDragon@users.noreply.github.com> Date: Mon, 5 Oct 2020 18:38:16 +0400 Subject: [PATCH 3/6] Newline to meet line length limit --- pywt/_cwt.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index f73b499f..793eb46f 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -24,7 +24,8 @@ def next_fast_len(n): return 2**ceil(np.log2(n)) -def cwt(data, scales, wavelet, sampling_period=1., method='conv', precision=12, axis=-1): +def cwt(data, scales, wavelet, sampling_period=1., method='conv', + precision=12, axis=-1): """ cwt(data, scales, wavelet) From dc9a6852d329f12216666012684fddc1d2857f35 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 3 Aug 2025 19:43:49 +0200 Subject: [PATCH 4/6] MAINT: address review comments, fix `cwt` argument order --- pywt/_cwt.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index 793eb46f..c77b8ccc 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -24,8 +24,8 @@ def next_fast_len(n): return 2**ceil(np.log2(n)) -def cwt(data, scales, wavelet, sampling_period=1., method='conv', - precision=12, axis=-1): +def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1, + *, precision=12): """ cwt(data, scales, wavelet) @@ -58,14 +58,15 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', The ``fft`` method is ``O(N * log2(N))`` with ``N = len(scale) + len(data) - 1``. It is well suited for large size signals but slightly slower than ``conv`` on small ones. - precision: int, optional - Length of wavelet (2 ** precision) used to compute the CWT. Greater - will increase resolution, especially for higher scales, but will - compute a bit slower. Too low will distort coefficients and their - norms, with a zipper-like effect; recommended >= 12. axis: int, optional Axis over which to compute the CWT. If not given, the last axis is used. + precision: int, optional + Length of wavelet (``2 ** precision``) used to compute the CWT. Greater + will increase resolution, especially for higher scales, but will + compute a bit slower. Too low will distort coefficients and their + norms, with a zipper-like effect. The default is 12, it's recommended + to use >=12. Returns ------- From 19f056096810730a101af592386b7c66440eada8 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 3 Aug 2025 19:46:13 +0200 Subject: [PATCH 5/6] DOC: remove incorrect `cwt` signature from its docstring --- pywt/_cwt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index c77b8ccc..91cde0f6 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -27,8 +27,6 @@ def next_fast_len(n): def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1, *, precision=12): """ - cwt(data, scales, wavelet) - One dimensional Continuous Wavelet Transform. Parameters From 50c5693e549722328dc3ac45230e14ac5fe84e3e Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 3 Aug 2025 20:36:58 +0200 Subject: [PATCH 6/6] TST: fix test failure for `cwt` matlab comparison --- pywt/tests/test_matlab_compatibility_cwt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywt/tests/test_matlab_compatibility_cwt.py b/pywt/tests/test_matlab_compatibility_cwt.py index 21d37c0a..7819c50f 100644 --- a/pywt/tests/test_matlab_compatibility_cwt.py +++ b/pywt/tests/test_matlab_compatibility_cwt.py @@ -149,7 +149,7 @@ def _load_matlab_result_psi(wavelet): def _check_accuracy(data, w, scales, coefs, wavelet, epsilon): # PyWavelets result - coefs_pywt, freq = pywt.cwt(data, scales, w) + coefs_pywt, freq = pywt.cwt(data, scales, w, precision=10) # coefs from Matlab are from R2012a which is missing the complex conjugate # as shown in Eq. 2 of Torrence and Compo. We take the complex conjugate of