plateau

exovetter.utils.plateau(array, threshold)[source]

Find plateaus in an array, i.e continuous regions that exceed threshold.

Given an array of numbers, return a 2d array such that out[:,0] marks the indices where the array crosses threshold from below, and out[:,1] marks the next time the array crosses that same threshold from below.

Parameters:
arrayarray_like

Numpy 1D array

thresholdfloat or array_like

If threshold is a single number, any point above that value is above threshold. If it’s an array, it must have the same length as the first argument, and an array[i] > threshold[i] to be included as a plateau

Returns:
locarray_like

Numpy 2d array with 2 columns.

Notes

To find the length of the plateaus, use out[:,1] - out[:,0]

To find the length of the largest plateau, use np.max(out[:,1] - out[:,0])

The algorithm fails if a value is exactly equal to the threshold. To guard against this, we add a very small amount to threshold to ensure floating point arithmetic prevents two numbers being exactly equal.