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

3 participants

@dmcminniwc

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

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

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

@WarrenWeckesser

This is fixed by #2836

@WarrenWeckesser WarrenWeckesser added a commit that closed this issue Sep 9, 2013
@WarrenWeckesser WarrenWeckesser MAINT: 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 _boolrelextream.
* 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.
336b60f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment