ktk.TimeSeries.sort_events#

TimeSeries.sort_events(*, unique=False, in_place=False)[source]#

Sorts the TimeSeries’ events from the earliest to the latest.

Parameters
  • unique (bool) – Optional. True to make events unique so that no two events can have both the same name and the same time.

  • in_place (bool) – Optional. True to modify and return the original TimeSeries. False to return a modified copy of the TimeSeries while leaving the original TimeSeries intact. Default is False.

Returns

The TimeSeries with the sorted events.

Return type

TimeSeries

Example

>>> ts = ktk.TimeSeries(time=np.arange(100)/10)
>>> ts = ts.add_event(2, "two")
>>> ts = ts.add_event(1, "one")
>>> ts = ts.add_event(3, "three")
>>> ts = ts.add_event(3, "three")
>>> ts.events
[TimeSeriesEvent(time=2, name='two'),
 TimeSeriesEvent(time=1, name='one'),
 TimeSeriesEvent(time=3, name='three'),
 TimeSeriesEvent(time=3, name='three')]
>>> ts = ts.sort_events()
>>> ts.events
[TimeSeriesEvent(time=1, name='one'),
 TimeSeriesEvent(time=2, name='two'),
 TimeSeriesEvent(time=3, name='three'),
 TimeSeriesEvent(time=3, name='three')]
>>> ts = ts.sort_events(unique=True)
>>> ts.events
[TimeSeriesEvent(time=1, name='one'),
 TimeSeriesEvent(time=2, name='two'),
 TimeSeriesEvent(time=3, name='three')]