Skip to content

Commit 386542c

Browse files
lagrularsoner
authored andcommitted
ENH: Extend peak finding capabilities in scipy.signal (scipy#8264)
* ENH: Add function to calculate peak prominence to scipy.signal This function allows to calculate the prominince of a peak in a signal. The prominence is a measure for how much a peak stands out from the base line of a signal. See scipy#8264. * ENH: Add function to calculate peak width to scipy.signal This function allows to calculate the width of a peak in a signal. The width is the horizontal distance between a peaks rising and falling slope at a chosen height. See scipy#8264 * ENH: Add new find_peaks function to scipy.signal This function allows to find a subset of all local maxima in a vector by specifying requirements e.g. peak height, distance, etc. It wraps and uses the two public functions - peak_prominences - peak_widths and the private functions - _unpack_filter_args - _filter_generic - _filter_by_peak_threshold - _filter_by_peak_distance See scipy#8264 * TST: Add tests for new functions in scipy.signal Adds basic tests (full coverage) for the functions: - scipy.signal.peak_promineces - scipy.signal.peak_widths - scipy.signal._peak_finding._unpack_filter_args - scipy.signal.find_peaks Also add notice to THANKS.txt and use better function order in signals toctree. See scipy#8264. * DOC: Shorter function references & fix example in peak_widths - The prefix `scipy.signal.` is not needed to create references to other functions within the module. The shorter version is more readable. - The example in `peak_widths` was broken for Python 2.7 because it relied on implicit float division with integers. - The example now uses the argument `rel_height` to be more explicit. See scipy#8264 * MAINT: Address suggested improvements in scipy#8264 - Replace kwargs in peak_widths with optional keyword arguments which improves introspection and resistance against typos. - Removed obsolete if-statement if number of peaks was 0. That way the content of `properties` gets populated properly. Extended unit tests to account for this. - Removed unnecessary indentation for prominence and with filtering. - Refactored "wheights" to "width_heights" which is more consistent with "peak_heights" and more descriptive. - More readable format for properties-key-list in docstring of find_peaks. - Explained usage of open interval `(None, None)` and made unit tests use this construct. - Replaced example in find_peaks's docstring with a more complex one that demonstrates simple and more advanced usage. * MAINT: Improve terminology in documentation and code - Don't use the term "filter" because in the context of this module it already has a meaning. Instead use "condition", "select" or other terms. - "filter options" are now named "conditions" which has a clearer meaning. - Remove unnecessary argument `peaks` in for function `_select_by_property`. - Use "in samples" where horizontal distance is required. - Added some cases to unit tests and refactored a few objects. * DOC: Add new functions for peak finding to release notes 1.1.0 * DOC: Describe behavior on flat extrema for argrelmax & argrelmin A reference to find_peaks which detects flat maxima was added as well where appropriate.
1 parent 102c334 commit 386542c

File tree

5 files changed

+1116
-15
lines changed

5 files changed

+1116
-15
lines changed

THANKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Felix Lenders for implementing trust-trlib method.
184184
Dezmond Goff for adding optional out parameter to pdist/cdist
185185
Nick R. Papior for allowing a wider choice of solvers
186186
Sean Quinn for the Moyal distribution
187+
Lars Grüter for contributions to peak finding in scipy.signal
187188

188189
Institutions
189190
------------

doc/release/1.1.0-notes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ can now accept an array. This array allows the user to specify the entire
4545
population.
4646

4747

48+
`scipy.signal` improvements
49+
---------------------------
50+
51+
Three new functions for peak finding in one-dimensional arrays were added.
52+
`scipy.signal.find_peaks` searches for peaks (local maxima) based on simple value
53+
comparison of neighbouring samples and returns those peaks whose properties match
54+
optionally specified conditions for their height, prominence, width, threshold
55+
and distance to each other. `scipy.signal.peak_prominences` and
56+
`scipy.signal.peak_width` can directly calculate the prominences or widths of
57+
known peaks.
58+
59+
4860
`scipy.sparse` improvements
4961
----------------------------
5062

scipy/signal/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,13 @@
278278
.. autosummary::
279279
:toctree: generated/
280280
281-
find_peaks_cwt -- Attempt to find the peaks in the given 1-D array
282-
argrelmin -- Calculate the relative minima of data
283-
argrelmax -- Calculate the relative maxima of data
284-
argrelextrema -- Calculate the relative extrema of data
281+
argrelmin -- Calculate the relative minima of data
282+
argrelmax -- Calculate the relative maxima of data
283+
argrelextrema -- Calculate the relative extrema of data
284+
find_peaks -- Find a subset of peaks inside a signal.
285+
find_peaks_cwt -- Find peaks in a 1-D array with wavelet transformation.
286+
peak_prominences -- Calculate the prominence of each peak in a signal.
287+
peak_widths -- Calculate the width of each peak in a signal.
285288
286289
Spectral Analysis
287290
=================

0 commit comments

Comments
 (0)