trajectory¶
- class Trajectory(*, data=None, cfg=None, timestep=None, validate_on_init=True)¶
Bases:
TimestampedInstanceCollectionRepresents a trajectory, a collection of timestamped instances from a single animal.
This class adds functionality specific to trajectories, such as interpolation and sampling at specific timestamps. It also manages a
timestepattribute.- Parameters:
data (
Mapping[str,ndarray] |None, default:None) – A dictionary containing the trajectory data.cfg (
Config|None, default:None) – The configuration object.timestep (
int|float|None, default:None) – The timestep of the trajectory.validate_on_init (
bool, default:True) – Whether to validate the data during initialization.
- get_interpolated_length(timestep=None)¶
Calculates the interpolated length of the trajectory based on a given timestep.
- Parameters:
timestep (
int|float|None, default:None) – The time step to use for interpolation; defaults to the trajectory’s timestep if not provided.- Return type:
- Returns:
The interpolated length of the trajectory.
- Raises:
ValueError – If the timestep does not result in an integer trajectory length.
- init_other(*, data, copy_config=False, validate_on_init=False)¶
Initializes a new trajectory, optionally copying the configuration.
- Parameters:
- Return type:
Self- Returns:
A new trajectory instance.
- interpolate(timestep=None, *, copy=True)¶
Linearly interpolates the trajectory to a new timestep, effectively resampling the trajectory at a different rate.
See also
Trajectory.sample().
- property is_complete: bool¶
Checks if the trajectory is complete based on its length, timestamps, and timestep.
- sample(timestamps, *, keep_dtype=False, copy=True)¶
Samples the trajectory at the given timestamps, linearly interpolating values where necessary.
- Parameters:
- Return type:
Self- Returns:
The sampled trajectory.
- Raises:
AssertionError – If the trajectory is not sorted or if it contains more than one unique identity.
- slice_window(start, stop, *, copy=True, interpolate=True, interpolation_timestep=None)¶
Slices a time window of the trajectory, optionally interpolating to a fixed timestep.
- Parameters:
- Return type:
Self- Returns:
The sliced trajectory.
- Raises:
ValueError – If
interpolate=Trueandcopy=False.
- property timestep: int | float¶
Returns or sets the timestep of the trajectory.
If the timestep is not set, it is inferred as the greatest common denominator of the time steps between consecutive timestamps.
- validate_data(data, *, allow_duplicated_timestamps=False, allow_missing_keys=False, try_broadcasting=True, require_array_like=False)¶
Validates the input data against the specified requirements.
See
validate_data()for more details.- Parameters:
data (
Mapping[str,ndarray|int|float|str|integer|floating]) – The data to validate.allow_duplicated_timestamps (
bool, default:False) – Ignored, exists for consistency withInstanceCollection.allow_missing_keys (
bool, default:False) – Whether to allow missing keys.try_broadcasting (
bool, default:True) – Whether to try broadcasting.require_array_like (
bool, default:False) – Whether to require array-like data.
- Return type:
- Returns:
If the data passed validation.