Trajectory
class Trajectory
Class representing a trajectory, i.e. position and orientation of a plattform over time
- Position-Computations are always done in a local frame
- Time stamps are always in UTC time
- Rotations are always defined in a East-North-Up frame
Attributes:
pos
(PointSet): Position of the trajectoryrot
(RotationSet): Orientation of the trajectorytstamps
(np.ndarray): Time stamps of the trajectoryname
(str): Name of the trajectoryarc_lengths
(np.ndarray): Arc lengths of the trajectoryspeed_3d
(np.ndarray): 3D speed of the trajectorysorting
(Sorting): Sorting of the trajectory
Methods:
__init__
: Initialize trajectory__str__
: Returns string describing trajectory__repr__
: Returns string representation of trajectory__len__
: Return number of poses__eq__
: Check if two trajectories are equalinit_arc_lengths
: Initialize arc lengthscopy
: Deep copy of itselffrom_file
: Create trajectory from filesort_switching_index
: Returns the index that switches the sorting of the trajectorysorting_index
: Returns the index that sorts the trajectoryfunction_of
: Returns the function of the trajectoryfunction_of_unit
: Returns the unit of the function of the trajectoryfunction_of_label
: Returns the label of the function of the trajectoryxyz
: Returns the xyz coordinates of the trajectoryquat
: Returns the quaternion of the trajectoryrpy
: Returns the roll, pitch, yaw of the trajectoryto_dataframe
: Returns a pandas dataframe containing tstamps, xyz, quat and speed_3d of the trajectoryto_file
: Writes trajectory to ascii filefrom_numpy
: Initialize trajectory using numpy arraysse3
: Returns SE3 pose listse3.setter
: Sets position and rotation from se3 listdata_rate
: Returns data ratetotal_length
: Return the total trajectory arc_lengthspeed_3d
: Returns computed speeds or custom speedsspeed_3d.setter
: Sets custom speedsspeed
: Returns trajectory speeds calculated using consecutive point distancescrop
: Crops trajectory to timespan defined by t_start and t_endinterpolate
: Interpolates a trajectory to specified timestamps_interpolate_rotations
: Function for rotation interpolation of a trajectory_interpolate_positions
: Function for position interpolation of a trajectorymatch_timestamps
: Truncates trajectory to only those poses where the timestamps exactly match "tstamps"intersect
: Intersects trajectory with a given timestamp vectorapply_index
: Applies index to the trajectoryapply_transformation
: Applies transformation to trajectory
method Trajectory.__init__
__init__(
pos: pointset.pointset.PointSet,
rot: Optional[trajectopy.core.rotationset.RotationSet] = None,
tstamps: Optional[numpy.ndarray] = None,
name: str = '',
arc_lengths: Optional[numpy.ndarray] = None,
speed_3d: Optional[numpy.ndarray] = None,
sorting: trajectopy.core.sorting.Sorting = <Sorting.TIME: 'time'>
) → None
property Trajectory.data_rate
Returns data rate
property Trajectory.function_of
Returns the function of the trajectory
property Trajectory.function_of_label
Returns the label of the function of the trajectory
property Trajectory.function_of_unit
Returns the unit of the function of the trajectory
property Trajectory.has_orientation
Returns True if orientation is available
property Trajectory.quat
Returns the quaternion of the trajectory
In contrast to the rot.as_quat() attribute, this method reflects the current sorting of the trajectory.
property Trajectory.rpy
Returns the roll, pitch, yaw of the trajectory
In contrast to the rot.as_euler(seq="xyz") attribute, this method reflects the current sorting of the trajectory.
property Trajectory.se3
Returns SE3 pose list
property Trajectory.sort_switching_index
Returns the index that switches the sorting of the trajectory
property Trajectory.sorting_index
Returns the index that sorts the trajectory
property Trajectory.speed
Returns trajectory speeds calculated using consecutive point distances
property Trajectory.speed_3d
Returns computed speeds or custom speeds
property Trajectory.total_length
Return the total trajectory arc_length.
property Trajectory.xyz
Returns the xyz coordinates of the trajectory
In contrast to the pos.xyz attribute, this method reflects the current sorting of the trajectory.
method Trajectory.adopt_first_orientation
Transform trajectory so that the first orientation is identical in both
Args:
trajectory
(Trajectory): Target Trajectoryinplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Transformed trajectory
method Trajectory.adopt_first_pose
Transform trajectory so that the first pose is identical in both
Args:
trajectory
(Trajectory): Target Trajectoryinplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Transformed trajectory
method Trajectory.adopt_first_position
Transform trajectory so that the first position is identical in both
Args:
trajectory
(Trajectory): Target Trajectoryinplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Transformed trajectory
method Trajectory.apply_alignment
apply_alignment(
alignment_result: trajectopy.core.alignment.result.AlignmentResult,
inplace: bool = True
) → Trajectory
Transforms trajectory using alignment parameters.
After computing the alignment parameters needed to align two trajectories, they can be applied to arbitrary trajectories.
Args:
alignment_result (AlignmentResult)
- inplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Aligned trajectory
method Trajectory.apply_index
Applies index to the trajectory
This will be done either in-place or using a new instance of a trajectory. The index can be used to filter and / or sort the components of the trajectory.
Those components are: - timestamps (tstamps) - positions (xyz) - rotations (rot) - arc lengths (arc_lengths) - sorting index (_sort_index)
Args:
index
(Union[list, np.ndarray]): index that should be appliedinplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Trajectory with index applied.
method Trajectory.apply_transformation
Applies transformation to trajectory
Args:
transformation
(np.ndarray): 4x4 Transformation matrixinplace
(bool, optional): Perform in-place. Defaults to True.
Returns:
Trajectory
: Transformed trajectory
method Trajectory.approximate
approximate(
approximation_settings: trajectopy.core.settings.approximation.ApproximationSettings = ApproximationSettings(fe_int_size=0.15, fe_min_obs=25, rot_approx_win_size=0.15),
inplace: bool = True
) → Trajectory
Approximates the trajectory using piecewise cubic polynomial.
Args:
approximation_settings
(ApproximationSettings): Approximation settings.
Returns:
Trajectory
: Approximated trajectory.
method Trajectory.copy
Deep copy of itself
method Trajectory.crop
Crops trajectory to timespan defined by t_start and t_end
Args:
t_start
(float): Start timestamp of desired time spant_end
(float): End timestamp of desired time spaninverse
(bool, optional): If true, 'crop' turns into 'cut', i.e. everthing outside of t_start and t_end will be removed. Defaults to False.inplace
(bool, optional): Perform crop in-place. Defaults to True.
Returns:
Trajectory
: Cropped trajectory
classmethod Trajectory.from_file
Create trajectory from file
The file must be a csv file containing columns for at least the timestamp, x, y and z coordinates of the trajectory. Those fields must be named "t", "px", "py" and "pz" in the header using the #fields tag. However, by default a trajectory with "t,px,py,pz,qx,qy,qz,qw" fields is assumed. Additional fields include the arc length, specified by "l", and the speed, specified by "vx", "vy" and "vz". The delimiter can be specified using the #delimiter tag. The default delimiter is a comma.
Args:
filename
(str): path to fileio_stream
(bool, optional): If true, the file is read from a stream.
Returns:
Trajectory
: trajectory object
classmethod Trajectory.from_numpy
from_numpy(
xyz: numpy.ndarray,
quat: numpy.ndarray,
tstamps: numpy.ndarray,
epsg: int = 0
) → Trajectory
Initialize trajectory using numpy arrays
method Trajectory.init_arc_lengths
method Trajectory.interpolate
Interpolates a trajectory to specified timestamps
This method removes timestamps from tstamps if they lie outside of the timestamp range of the trajectory (self). Since providing values for those timestamps would require an extrapolation and not an interpolation, this behaviour is consistent with the definition of this method.
Args:
tstamps
(list): Interpolation timestampsinplace
(bool, optional): Perform in-place interpolation. Defaults to True.
Returns:
Trajectory
: Interpolated trajectory
method Trajectory.intersect
Intersects trajectory with a given timestamp vector
After intersection, the trajectory covers the same timespan as 'tstamps'. Further, gaps larger than 'max_gap_size' are removed. If two consecutive timespans in tstamps have a difference of more than 'max_gap_size' seconds, they are considered as the limits of a gap. All timestamps of the trajectory that lie within this gap will be removed.
Args:
tstamps
(np.ndarray): Intersection timespansmax_gap_size
(float, optional): Maximum allowed gap between timespans. If Defaults to 0.5.inplace
(bool, optional): Perform intersection in-place. Defaults to True.
Raises:
ValueError
: If timespans do not overlap.
Returns:
Trajectory
: Intersected trajectory
method Trajectory.match_timestamps
Truncates trajectory to only those poses where the timestamps exactly match "tstamps"
Args:
tstamps
(np.ndarray): Input timestampsinplace
(bool, optional): Perform matching in-place. Defaults to True.
Returns:
Trajectory
: Trajectory with matched timestamps
method Trajectory.sort_spatially
sort_spatially(
sorting_settings: trajectopy.core.settings.sorting.SortingSettings = SortingSettings(discard_missing=True, voxel_size=0.05, movement_threshold=0.005, k_nearest=4),
inplace: bool = True
) → Trajectory
Sorts the trajectory spatially.
Args:
sorting_settings
(SortingSettings): Sorting settings.inplace
(bool, optional): Whether to sort the trajectory in-place. Defaults to True.
Returns:
Trajectory
: Sorted trajectory.
method Trajectory.to_dataframe
Returns a pandas dataframe containing tstamps, xyz, quat and speed_3d of the trajectory.
The dataframe is sorted by the current sorting attribute (time or arc_length).
Args:
sort_by
(str, optional): Column to sort by. This overrides the current sort_by attribute.
Returns:
pd.DataFrame
: Trajectory as dataframe
method Trajectory.to_file
Writes trajectory to ascii file
The first line will always be the epsg information. After that, the trajectory data is written.
Args:
filename
(str): Output filename