Skip to content

Sorting

module trajectopy.sorting

Trajectopy - Trajectory Evaluation in Python

Gereon Tombrink, 2025 tombrink@igg.uni-bonn.de


function sort_spatially

sort_spatially(
    xyz_unsorted: numpy.ndarray,
    settings: trajectopy.settings.SortingSettings = SortingSettings(discard_missing=True, voxel_size=0.05, movement_threshold=0.005, k_nearest=4)
)  Tuple[List[int], numpy.ndarray]

Reconstructs the spatial sorting of the given points

Spatially sorts the positions by constructing the minimum-spanning-tree of the positions. Finally, by performing up to 3 breadth-first-searches within the mst, the spatial sorting can be reconstructed

This functionality is only useful if the positions describe a closed loop without intersections.

This method can also take care of inserting missing points and assures that the direction of travel is kept during sorting.

Args:

  • xyz_unsorted (np.ndarray): unsorted positions
  • settings (SortingSettings, optional): sorting settings. Defaults to SortingSettings().

Returns:

  • list: Sort index
  • np.ndarray: Arc lengths along the path

function detect_direction

detect_direction(xyz: numpy.ndarray)  int

Detects the direction of travel using polar coordinates

This only works if the points describe a somewhat circular trajectory which circulates around the origin of the coordinate frame.

Args:

  • xyz (np.ndarray): input positions

Returns:

  • int: -1 / 1 indicating direction of travel

function complete_lap_dist

complete_lap_dist(xyz, dist_th: float = 0.5)  bool

Function to determine if lap is complete A lap is considered as complete, if the distance between the starting point and the end point is below a specified distance


class Sorting