Note
Go to the end to download the full example code.
Comparing
traja allows comparing trajectories using various methods.
import traja
df = traja.generate(seed=0)
df.traja.plot()

<matplotlib.collections.PathCollection object at 0x795026e92ef0>
Fast Dynamic Time Warping of Trajectories
Fast dynamic time warping can be performed using fastdtw.
Source article: link.
import numpy as np
rotated = traja.rotate(df, angle=np.pi / 10)
rotated.traja.plot()

<matplotlib.collections.PathCollection object at 0x7950269fdb10>
Compare trajectories hierarchically
Hierarchical agglomerative clustering allows comparing trajectories as actograms and finding nearest neighbors. This is useful for comparing circadian rhythms, for example.
# Generate random trajectories
trjs = [traja.generate(seed=i) for i in range(20)]
# Calculate displacement
displacements = [trj.traja.calc_displacement() for trj in trjs]
traja.plot_clustermap(displacements)

/home/docs/checkouts/readthedocs.org/user_builds/traja/envs/latest/lib/python3.10/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
warnings.warn(msg)
<seaborn.matrix.ClusterGrid object at 0x795026e707c0>
Compare trajectories point-wise
Distance between the two trajectories is 27254.161638114736
Total running time of the script: (0 minutes 0.951 seconds)