ktk.TimeSeries.get_index_before_event

ktk.TimeSeries.get_index_before_event#

TimeSeries.get_index_before_event(name, occurrence=0, inclusive=False)[source]#

Get the time index that is just before the specified event occurrence.

Parameters:
  • name (str) – Event name

  • occurrence (int) – Occurrence of the event. The default is 0.

  • inclusive (bool) – True to allow including one sample after the event if needed, to make sure that the event time is part of the returned TimeSeries’s time. False to make sure that the returned TimeSeries does not include the event time. Default is False.

Returns:

The index in the time attribute.

Return type:

int

Raises:

TimeSeriesRangeError – If the resulting index would be outside the TimeSeries range.

Example

>>> ts = ktk.TimeSeries(time=np.arange(10)/10)
>>> ts = ts.add_event(0.2, "event")
>>> ts = ts.add_event(0.36, "event")
>>> ts.time
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
>>> ts.get_index_before_event("event")
1
>>> ts.get_index_before_event("event", occurrence=1)
3
>>> ts.get_index_before_event("event", occurrence=0, inclusive=True)
2