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

argrelextrema returns tuple of 2 empty arrays when no peaks found in 1D vector #2832

Closed
dmcminniwc opened this issue Sep 4, 2013 · 3 comments · Fixed by #2836
Closed

argrelextrema returns tuple of 2 empty arrays when no peaks found in 1D vector #2832

dmcminniwc opened this issue Sep 4, 2013 · 3 comments · Fixed by #2836
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal
Milestone

Comments

@dmcminniwc
Copy link

When using the scipy.signal.argrelextrema function to find the peaks in a 1D numpy vector and no peaks are found the return value is a tuple with two empty arrays.

The docs say it returns "Indices of the maxima, as an array of integers". I would expect with no peaks it would be a tuple with one empty array for each dimension of the input vector.

For example:

import numpy as np
import scipy.signal as sig
y = np.concatenate([np.arange(1, 0, -0.01), np.arange(0, 1, 0.01)]) 
peaks = sig.argrelextrema(0.5-np.abs(y - 0.5), np.greater)
print peaks # Prints '(array([ 50, 150]),)'
peaks = sig.argrelextrema(y, np.greater) # No peaks
print peaks # Prints '((array([]), dtype=float64),(array([]), dtype=float64),)'

I would have expected '((array([]), dtype=float64),)' for the second print statement.

In the source for scipy it returns "(np.array([]),) * 2" when no peaks are found but it should probably be "(np.array([]),) * data.ndim".

@dmcminniwc
Copy link
Author

I forgot to add that this was using scipy v 0.12.0 on Windows 7 x64 Professional, running on python 2.7.5.

@sebix
Copy link

sebix commented Sep 5, 2013

This issue has been discussed on the Scipy-User Mailinglist: http://mail.scipy.org/pipermail/scipy-user/2013-September/034905.html

@WarrenWeckesser
Copy link
Member

This is fixed by #2836

pv added a commit that referenced this issue Sep 9, 2013
BUG: signal: Some clean up in _peak_finding.py

    Fixed the description of the return value of argrelmin, argrelmax, argrelextrema and _boolrelextream.
    Fixed the example in the docstring of _boolrelextrema.
    Added examples to the docstrings of argrelmin, argrelmax and argrelextrema.
    Added more tests for argrelmin and argrelmax.
    Removed some commented-out code and unused imports from test_peak_finding.py along with an unused variable (num_peaks) in _gen_gaussians().
    Removed an argument ('order=2') from the signature of TestArgrel.test_higher_order() in test_peak_finding.py.
    Removed unnecessary special check in argrelextrema that incorrectly returned a length 2 tuple when there were no relative extrema, regardless of the dimension of the input. Fixes gh-2832.
    Several more minor tweaks.
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.

3 participants