ktk.TimeSeries.get_index_before_time#

TimeSeries.get_index_before_time(time, *, inclusive=False)[source]#

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

Parameters
  • time (float) – Time to look for in the TimeSeries’ time vector.

  • inclusive (bool) – Optional. True to include the given time in the comparison.

Returns

The index in the time vector.

Return type

int

Raises

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

Example

>>> ts = ktk.TimeSeries(time=np.array([0, 0.5, 1, 1.5, 2]))
>>> ts.get_index_before_time(0.9)
1
>>> ts.get_index_before_time(1)
1
>>> ts.get_index_before_time(1.1)
2
>>> ts.get_index_before_time(1.1, inclusive=True)
2