question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

find_peaks_cwt has undocumented behavior when window_size is None and wavelet is ricker

See original GitHub issue

From the documentation for find_peaks_cwt (window_size):

Size of window to use to calculate noise floor. Default is cwt.shape[1] / 20.

However, when window_size is None and wavelet = ricker (default for find_peaks_cwt) this will also trigger special case handing in scipy.signal.wavelets.cwt:

 if wavelet == ricker and window_size is None:
     ceil = np.ceil(N)
     if ceil != N:
         N = int(N)

which affects the output with my supplied input: input.txt. So, in the end the result from find_peaks_cwt differs between when window_size is None and cwt.shape[1] / 20.

Reproducing code example:

>>> import json
>>> import numpy as np
>>> from scipy import signal
>>> vector = np.array(json.load(open('input.txt')))  # Attached file
>>> widths = np.linspace(1, 265)
>>> signal.find_peaks_cwt(vector, widths)
array([  22,  436,  868, 1299, 1732, 2164, 2596, 3028, 3459, 3892, 4324, 4756, 5189, 5620, 6052, 6484, 6916, 7349, 7780, 8212, 8625])
# window_size gets computed in _filter_ridge_lines to 433
>>> window_size = int(np.ceil(len(vector) / 20))
# Now, I supply this computed window_size:
>>> signal.find_peaks_cwt(vector, widths, window_size=window_size)
array([  23,  436,  868, 1300, 1732, 2164, 2596, 3028, 3460, 3892, 4325, 4757, 5189, 5621, 6053, 6485, 6917, 7349, 7781, 8213, 8626])

Scipy/Numpy/Python version information:

1.5.2 1.17.5 sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ilayncommented, Aug 19, 2020

Today I am exceptionally stupid. Happened a few times with other PRs too. Sorry for that. I’ll fill the bathtub with coffee.

1reaction
tylerjereddycommented, Aug 20, 2020

For the 1.6.0 release, I believe we may be dropping that NumPy version range, so just deleting the shim might be ok.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.signal.find_peaks_cwt — SciPy v1.9.3 Manual
Find peaks in a 1-D array with wavelet transformation. The general approach is to smooth vector by convolving it with wavelet(width) for each...
Read more >
FindPeaksCWT — Peak finding with continuous wavelet ...
Should be normalized to unit area. Default: None (ricker wavelet). max_distances, (ndarray, optional) At each row, a ridge line is only connected if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found