ktk.cycles.detect_cycles#

detect_cycles(ts, data_key, *, event_names=('phase1', 'phase2'), thresholds=(0.0, 1.0), directions=('rising', 'falling'), min_durations=(0.0, 0.0), max_durations=(inf, inf), min_peak_heights=(- inf, - inf), max_peak_heights=(inf, inf))[source]#

Detect cycles in a TimeSeries based on a dual threshold approach.

This function detects biphasic cycles and identifies the transitions as new events in the output TimeSeries. These new events are named:

  • event_names[0]: corresponds to the start of phase 1

  • event_names[1]: corresponds to the start of phase 2

  • “_”: corresponds to the end of the cycle.

Parameters
  • ts (TimeSeries) – TimeSeries to analyze.

  • data_key (str) – Name of the data key to analyze in the TimeSeries. This data must be unidimensional.

  • event_names (tuple[str, str]) – Optional. Event names to add in the output TimeSeries. Default is (“phase1”, “phase2”).

  • thresholds (tuple[float, float]) – Optional. Values to cross to register phase changes. Default is [0., 1.].

  • directions (tuple[str, str]) – Optional. Directions to cross thresholds to register phase changes. Either (“rising”, “falling”) or (“falling”, “rising”). Default is (“rising”, “falling”).

  • min_durations (tuple[float, float]) – Optional. Minimal phase durations in seconds. Default is (0.0, 0.0).

  • max_durations (tuple[float, float]) – Optional. Maximal phase durations in seconds. Default is (np.Inf, np.Inf)

  • min_peak_heights (tuple[float, float]) – Optional. Minimal peak values to be reached in both phases. Default is (-np.Inf, -np.Inf).

  • max_peak_heights (tuple[float, float]) – Optional. Maximal peak values to be reached in both phases. Default is (np.Inf, np.Inf).

Returns

A copy of ts with the events added.

Return type

TimeSeries