ktk.cycles.time_normalize

Contents

ktk.cycles.time_normalize#

time_normalize(ts, event_name1, event_name2, *, n_points=100, span=None)[source]#

Time-normalize cycles in a TimeSeries.

This method time-normalizes the TimeSeries at each cycle defined by event_name1 and event_name2 on n_points. The time-normalized cycles are put end to end. For example, for a TimeSeries that contains three cycles, a time normalization with 100 points will give a TimeSeries of length 300. The TimeSeries’ events are also time-normalized, including event_name1 but with event_name2 renamed as “_”.

Parameters:
  • ts (TimeSeries) – The TimeSeries to analyze.

  • event_name1 (str) – The event name that corresponds to the beginning of a cycle.

  • event_name2 (str) – The event name that corresponds to the end of a cycle.

  • n_points (int) – Optional. The number of points of the output TimeSeries.

  • span (list[int] | None) – Optional. Specifies which normalized points to include in the output TimeSeries. See note below.

Returns:

A new TimeSeries where each cycle has been time-normalized.

Return type:

TimeSeries

Warning

The span argument is experimental and was introduced in version 0.4. The following behavior may change in the future. Don’t rely on it in long-term scripts for now. You can use it to define which normalized points to include in the output TimeSeries. For example, to normalize in percents and to include only data from 10 to 90% of each cycle, assign 100 to n_points and [10, 90] to span. The resulting TimeSeries will then be expressed in percents and wrap each 80 points. It is also possible to include pre-cycle or post-cycle data. For example, to normalize in percents and to include 20% pre-cycle and 15% post-cycle, assign 100 to n_points and [-20, 15] to span. The resulting TimeSeries will then wrap each 135 points with the cycles starting at 20, 155, etc. and ending at 119, 254, etc. For each cycle, events outside the 0-100% spans are ignored.