timestamped collection¶
- class TimestampedInstanceCollection(*, data=None, cfg=None, validate_on_init=True)¶
Bases:
InstanceCollectionRepresents a collection of timestamped instances.
This class provides direct access to timestamps and adds functionality specific to timestamped data, such as sorting by timestamp and slicing based on time windows. It ensures that a timestamp key is defined in the configuration.
- Parameters:
- Raises:
ValueError – If the timestamp key is not defined in the trajectory keys during initialization.
- get_slice(start, stop)¶
Converts a time window to a slice object for accessing data within the window.
- Parameters:
- Return type:
- Returns:
The slice object for accessing data within the window.
- Raises:
ValueError – If the collection has zero length or is not sorted.
utils.OutOfInterval – If the start or stop time is outside the timestamp range.
- slice_window(start, stop)¶
Slices the collection based on a specified time window.
- sort(copy=True)¶
Sorts the collection by timestamp.
- Parameters:
copy (
bool, default:True) – Whether to return a copy of the sorted collection.- Return type:
Self- Returns:
The sorted collection.
- Raises:
ValueError – If
copy=Falseand the collection is a view or has existing views.