New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mode='wrap' in find_peaks(), as in argrelextrema() – signals with periodic boundary condition #13710
Comments
Hi, thanks for the suggestion. It seems like you would know how to do this. Would you be willing to do a PR? |
Yep, I guess, I can! |
Great, thanks! Don't hesitate to post on the dev mail list to enquire for help/advice about this. |
Hi there! I wonder how far you got with this. I'm on this page because I have a similar issue with find_peaks. In my case, the time series ends with a nice high peak but then drops down slightly just before the end. As a result, the right_base is just the end of the window, and the calculated prominence is very low. This is not at all desirable in my use case. I was thinking of adding a mode where we do not calculate prominence by reference to a value at the extreme end of the window unless, of course, both the left_base and right_base are at the end. I'm not super experienced with (a) Python and (b) contributing to large projects, but it seems like these issues should be handled together. I am happy to contribute, as it seems like it's within my competence! |
My current thoughts on this: This request might be solved by adapting the indexing logic on the Cython level. For The actual problem is not adapting the part that works similar to However I can understand why this would be a nice enhancement. If I can think of a solution without large drawbacks I will follow up. @bekemax, feel free to tag me if you come up with a solution. |
Hi, I would like to know if there has been any progress related to this enhancement. Thanks! |
Hey, Then I apply find_peaks as usual. Afterwards I shift the gained indice list of the extrema by the length of the second half splitted list I putted in front of the first half, to get the indices of the original array.
|
It's not 100% robust. It depends on your data and if you really want all local extrema. For my case I have particles in a box with periodic boundaries and consider the density distribution. For me it is better to take like 70% of max value. I changed to:
|
Is your feature request related to a problem? Please describe.
I'm working with signals that have "periodic boundary condition" – if a signal is given with
x
, anumpy.array
of shape(N,)
, then after its last,N-1
-st element,x[N-1]
, the "next" element should be againx[0]
. (So,x[N]
is kind of forced to be equal tox[0]
).It would be great if I could use the
find_peaks()
function fromscipy.signal
with all its features in this setting, but if done straightforwardly, here's what that gives:From the standard point of view, the
0
-th element ofy
is not a peak, since it has no "left" neighbour to be larger of. But from the "periodic boundary condition" point of view, it is larger than both the1
-st and the-1
-st element, so it is a peak.Describe the solution you'd like
It would be great to have an argument in
find_peaks()
similar to that ofmode='wrap'
of theargrelextrema()
function fromscipy.signal
.Describe alternatives you've considered
If I use
scipy.signal.argrelextrema()
withmode='wrap'
, I get the desired result:– it identifies the
0
-th element as a local maximum as well, since it is larger than both the1
-st and-1
-st elements.But
find_peaks()
has far more functionality thanargrelextrema()
– the former returns the properties of the peaks, has helpful arguments likedistance
– to find peaks that are not closer than a given distance, etc. Actually,distance
is probably the only thing to take care of if such amode='wrap'
feature is implemented forfind_peaks()
– since the distance is now circular, not only in the positive direction of the indices: inmode='clip'
the distance between the0
-th and theN-1
-st element isN-1
(for an array of shape(N,)
), while inmode='wrap'
it is just1
. This should be taken care of bynumpy.take(mode='wrap')
, as inargrelextrema()
.As a temporary workaround for my needs, I can, for example,
find_peaks()
, do annp.roll(signal, 1)
of the signal array,find_peaks()
again on a roll-ed array, thennp.roll(signal, -1)
it back, and then merge the two peaks sets that I've found. But implementingmode='wrap'
forfind_peaks()
could be quite helpful for others.Additional context (e.g. screenshots)
The text was updated successfully, but these errors were encountered: