pyyeti.cyclecount.findap

pyyeti.cyclecount.findap(y, tol=1e-06, nan_check=True)[source]

Find alternating local maximum and minimum points in a vector.

Parameters:
  • y (ndarray) – y-axis data vector

  • tol (scalar; optional) – Tolerance value for detecting unique values; see pyyeti.locate.find_unique()

  • nan_check (bool; optional) – Whether to check for NaNs. Set to False for a performance gain if you know there are no NaNs.

Returns:

pv (ndarray) – Boolean vector for the alternating peaks in y.

Notes

y is flattened to one dimension before operations.

When y has a series of equal points, the first of the series is considered the peak. The first value in y is always considered a peak. The last point is a peak if and only if it is not equal to the point before it.

This routine is typically used to prepare a signal for cycle counting.

NaNs are not considered to be peaks and treated as if they are not present when nan_check is True (the default).

Examples

>>> from pyyeti import cyclecount
>>> import numpy as np
>>> cyclecount.findap(np.array([1]))
array([ True], dtype=bool)
>>> cyclecount.findap(np.array([1, 1, 1, 1]))
array([ True, False, False, False], dtype=bool)
>>> tf = cyclecount.findap(np.array([1, 2, 3, 4, 4, -2, -2, 0]))
>>> np.nonzero(tf)[0]
array([0, 3, 5, 7]...)
>>> tf = cyclecount.findap(np.array([1, 2, 3, 4, 4, -2, -2, -2]))
>>> np.nonzero(tf)[0]
array([0, 3, 5]...)
>>> tf = cyclecount.findap(np.array([1, 2, 3, 4, -2]))
>>> np.nonzero(tf)[0]
array([0, 3, 4]...)
>>> cyclecount.findap(np.array([np.nan, 1, 2, np.nan]))
array([False,  True,  True, False], dtype=bool)