detect_peaks

ketos.utils.detect_peaks(df, distance=1, multiplicity=1, prominence=1.0, height=None, threshold=None)[source]

Detect peaks in time-series data.

The time-series data is provided in the form of a Pandas DataFrame object, where each column contains a different time series.

This is essentially a wrapper around a SciPy’s find_peaks method:

Args:
df: Pandas DataFrame

Data frame containing the input data.

distance: int

Minimum distance between adjacent peaks

multiplicity: int

Number of time series in which peaks must appear to be counted.

prominence: float

Required prominence of the peaks. The prominence of a peak measures how much a peak stands out from the surrounding baseline of the signal and is defined as the vertical distance between the peak and its lowest contour line. See also https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_prominences.html#scipy.signal.peak_prominences

height: float

Required absolute height of the peaks.

threshold: float

Required threshold of peaks (the vertical distance to its neighbouring samples).

Returns:
y: Pandas DataFrame

Data frame containing the detected peaks

Example:
>>> from ketos.utils import detect_peaks
>>> import pandas as pd
>>>
>>> # create a two time series, where only the first contains a peak
>>> d = {'series1' : pd.Series([1.0, 2.3, 22.0, 2.2, 1.5]), 'series2': pd.Series([1.0, 2.3, 1.8, 2.2, 1.5])}
>>> df = pd.DataFrame(d)
>>> 
>>> # detect peaks with multiplicity 1 and prominence of at least 2.0
>>> peaks = detect_peaks(df=df, multiplicity=1, prominence=2.0)
>>> print(peaks)
[0 0 1 0 0]
>>> 
>>> # try again, but this time require multiplicity 2
>>> peaks = detect_peaks(df=df, multiplicity=2, prominence=2.0)
>>> print(peaks)
[0 0 0 0 0]