From: SciPy-Dev <scipy-dev-bounces+ali.cetin=outlook.com@python.org> on behalf of Ralf Gommers <ralf.gommers@gmail.com>
Sent: Saturday, October 20, 2018 00:14
To: SciPy Developers List
Subject: Re: [SciPy-Dev] Finding signal upcrossings and declustered peaks
 


On Fri, Oct 19, 2018 at 7:28 PM Ali Cetin <ali.cetin@outlook.com> wrote:

Are these covered by the recent find_peaks functions or brand new ones?
As far as I can see, the current find_peaks don't cover it. Also, finding crossings (up and down) is not "peak finding", but necessary to find declustered peaks. 

On Thu, Oct 18, 2018, 22:53 Ali Cetin <ali.cetin@outlook.com> wrote:



From: SciPy-Dev <scipy-dev-bounces+ali.cetin=outlook.com@python.org> on behalf of Ralf Gommers <ralf.gommers@gmail.com>
Sent: Thursday, October 18, 2018 21:59
To: SciPy Developers List
Subject: Re: [SciPy-Dev] Finding signal upcrossings and declustered peaks
 


On Thu, Oct 18, 2018 at 10:41 AM Ali Cetin <ali.cetin@outlook.com> wrote:
Hi,

this is my first attempt to write to this mailing list, so if I'm doing something wrong please bear with me.

Hi Ali, no worries you got it all right. welcome:)

I've been working with extreme value analysis during my PhD and also in my current job. What we often do is to find signal upcrossings (such as mean and zero upcrossings) and find declustered peaks. That is, find the largest peak between two upcrossings, or the two largest peaks between two upcrossings etc...

I'm proposing to add two new functions to the scipy.signal submodule:
   - find_upcross; takes in signal and returns index of upcrossings wrt user defined upcrossing level
   - find_peaks_dc; takes in signal and returns index of peaks (n largest)

(find_peaks_dc is not necessarly easily incorporated into find_peaks, so it may be cleaner to have a separate function).

Any thought on this?

Do you have any references for the algorithms?
Well, the "algorithms" are rather straight forward and heuristic.

   - find_upcross is often referred to as zero-crossing (https://en.wikipedia.org/wiki/Zero_crossing) (a special case). It is essentially detecting sign changes. Upcrossing count and rates are important statistics in time series (extreme value) analysis. Side note: Zero-crossing rate is by def the ratio between the second and zeroth moment of the power spectrum of the signal.

   - find_peaks_dc finds all peaks above an upcrossing level (or threshold) between two consecutive upcrossings, i.e. batches of peaks. Then the n-largest peaks are selected from each batch. Declustering is a technique often used to break down statistical dependency between peaks when performing extreme value analysis, and thus be able to use simpler distributions to describe them. As n-> inf find_peaks_dc -> find_peaks 😊 (Albeit in many practical situations, inf < 5). (Note that find_peaks_dc depends on find_upcross).

The code are just a few lines and mostly numpy array operations.

It sounds like you have implementations ready, could you link to them? (put in a git branch or a gist for example).

If it's just a few lines of code and not based on a publication, then I'm not sure we'd want to add these. We are interested in further peak finding improvements, however it should be clear for any new functions that they're an improvement over what we currently have. Otherwise I'm afraid we keep adding separate functions that all do a small subset of the spectrum of what users are interested in. E.g., from your description it's not clear how to treat zero crossings in the presence of noise.

Cheers,
Ralf
I think I misunderstood what you ment by reference; peak declustering methods dont necessarily have a reference paper, as the methods are rather self-explanatory. However, scientific papers and textbooks that use these methods are plenty! (Peaks declustering is indeed a very common technique in extreme value analysis. Just google "peak over threshold declustering") These are some of them:
   - Coles, An Introduction to Statistical Modeling of Extreme Values, (https://www.springer.com/us/book/9781852334598)
   - Davison, A. C., & Smith, R. L. (1990). Models for exceedances over high thresholds. Journal of the Royal Statistical Society. Series B (Methodological), 393-442.
   - Ferro, C. A. T. and Segers, J. (2003) Inference for clusters of extreme values. Journal of the Royal Statistical Society B, 65, 545--556.

I also note that peak declustering methods are available in R. (https://www.rdocumentation.org/packages/extRemes/versions/1.65/topics/decluster.runs)

Yes, I have written a "small" package that can find up-crossings and one particular method for peaks declustering (https://github.com/4Subsea/evapy). However, the functions in this package are rather limited in scope, limited to 1D arrays (performance optimized), and depends heavily on NumPy and SciPy. I was thinking about expanding the functionality anyway, and thought that I might do that by contributing to SciPy.

I propose to take an agile approach on this:
  • I'm almost done re-writing base signal up/down-crossing module. I can make a pull-request to scipy in the coming days. (It will add similar functionality as argrelmax, argrelmin -> argupcross, argdowncross etc.) If you don't like it, we can stop it there.
  • next step may be to add peaks declustering methods (whether by extending the current find_peaks or a new function dedicated for peaks declustering methods.)
Cheers,
Ali


Ali


_______________________________________________
SciPy-Dev mailing list
SciPy-Dev@python.org
https://mail.python.org/mailman/listinfo/scipy-dev
_______________________________________________
SciPy-Dev mailing list
SciPy-Dev@python.org
https://mail.python.org/mailman/listinfo/scipy-dev