Skip to content
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

No output of scipy.signal.argrelextrema() #3749

Closed
suuuehgi opened this issue Jun 20, 2014 · 4 comments · Fixed by #8264
Closed

No output of scipy.signal.argrelextrema() #3749

suuuehgi opened this issue Jun 20, 2014 · 4 comments · Fixed by #8264
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal

Comments

@suuuehgi
Copy link

Hey,

I hope that I did not made major flaws but I can not find a mistake. The output of argrelextrema() is always an empty numpy array.

import numpy as np
from scipy.signal import argrelextrema

dat = np.genfromtxt("numbers.dat")
print argrelextrema(dat[:], np.greater, order=6)

(array([], dtype=int64),)

numbers.dat contains a list of 50 testvalues containing a maximum. I also tested several values for the order parameter

78.75
81.0                                                                                                                                
83.25
85.5
87.75
89.25
91.5
93.0
94.5
96.75
98.25
99.75
101.25
102.0
103.5
104.25
105.75
106.5
107.25
108.0
108.75
108.75
109.5
109.5
109.5
109.5
109.5
109.5
109.5
108.75
108.75
108.0
107.25
106.5
105.75
105.0
104.25
102.75
102.0
100.5
99.0
97.5
96.0
94.5
93.0
90.75
89.25
87.0
84.75
82.5

Thanks for any comments!
Stephan

@WarrenWeckesser
Copy link
Member

argrelextrema with np.greater doesn't consider repeated values to be relative maxima; it requires a strict inequality to be satisfied on both sides of the point:

In [11]: argrelextrema(np.array([1,2,2,0]), np.greater)
Out[11]: (array([], dtype=int64),)

A possible work-around for argrelextrema is to use np.greater_equal as the comparator.

In [26]: argrelextrema(np.array([1,2,2,0]), np.greater_equal)
Out[26]: (array([1, 2]),)

Here's what your example gives:

In [27]: dat = np.genfromtxt("numbers.dat")

In [28]: indx = argrelextrema(dat, np.greater_equal, order=6)

In [29]: indx
Out[29]: (array([22, 23, 24, 25, 26, 27, 28]),)

In [30]: dat[indx[0]]
Out[30]: array([ 109.5,  109.5,  109.5,  109.5,  109.5,  109.5,  109.5])

@pletnes
Copy link

pletnes commented Jun 30, 2016

I second this being a bug; two identical values in a row would intuitively result in one (if not two) peaks. The workaround works ok, but does give duplicates, of course. Which is worse - missing a peak or getting a duplicate - might depend on the application, but for me, missing the peak is definitely bad.

@rgommers rgommers added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Jun 30, 2016
@rgommers
Copy link
Member

agreed, a duplicate is better than nothing. maybe even better is then checking for duplicates and removing one according to some simple rule (like keep the one that has the highest value next to it)

@lagru
Copy link
Contributor

lagru commented Mar 1, 2018

This is quite old but I think there is an alternative solution now.

In #8350 the cython function _argmaxima1d was introduced which can detect "flat" peaks in 1D arrays. It approximates the center of flat peaks. However, currently this function is "private" but should get exposed with find_peaks in #8264.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants