Package: traja
Traja is a Python library for trajectory analysis. It extends the capability of
pandas DataFrame specific for animal trajectory analysis in 2D, and provides
convenient interfaces to other geometric analysis packages (eg, R and shapely).IntroductionThe traja Python package is a toolkit for the numerical characterization
and analysis of the trajectories of moving animals. Trajectory analysis
is applicable in fields as diverse as optimal foraging theory,
migration, and behavioral mimicry (e.g. for verifying similarities in
locomotion). A trajectory is simply a record of the path followed by a
moving animal. Traja operates on trajectories in the form of a series of
locations (as x, y coordinates) with times. Trajectories may be obtained
by any method which provides this information, including manual
tracking, radio telemetry, GPS tracking, and motion tracking from
videos.The goal of this package (and this document) is to aid biological
researchers, who may not have extensive experience with Python, to
analyze trajectories without being restricted by a limited knowledge of
Python or programming. However, a basic understanding of Python is
useful.If you use traja in your publications, please cite the repo@software{justin_shenk_2019_3237827,
  author       = {Justin Shenk and
                  the Traja development team},
  title        = {justinshenk/traja},
  month        = jun,
  year         = 2019,
  publisher    = {Zenodo},
  version      = {latest},
  doi          = {10.5281/zenodo.3237827},
  url          = {https://doi.org/10.5281/zenodo.3237827}
}Installation and setupTo install traja with conda, runconda install-cconda-forgetrajaor with pippip install traja.Import traja into your Python script or via the Python command-line withimport traja.Trajectories with trajaTraja stores trajectories in pandas DataFrames, allowing any pandas
functions to be used.Load trajectory with x, y and time coordinates:importtrajadf=traja.read_file('coords.csv')Once a DataFrame is loaded, use the.trajaaccessor to access the
visualization and analysis methods:df.traja.plot(title='Cage trajectory')Analyze TrajectoryThe following functions are available viatraja.trajectory.[method]FunctionDescriptioncalc_derivativesCalculate derivatives of x, y valuescalc_turn_anglesCalculate turn angles with regard to x-axistransitionsCalculate first-order Markov model for transitions between grid binsgenerateGenerate random walkresample_timeResample to consistent step_time intervalsrediscretize_pointsRediscretize points to given step lengthFor up-to-date documentation, seehttps://traja.readthedocs.io.Random walkGenerate random walks withdf=traja.generate(n=1000,step_length=2)df.traja.plot()Resample timetraja.trajectory.resample_timeallows resampling trajectories by astep_time.Flow Plottingdf=traja.generate()traja.plot_surface(df)traja.plot_quiver(df,bins=32)traja.plot_contour(df,filled=False,quiver=False,bins=32)traja.plot_contour(df,filled=False,quiver=False,bins=32)traja.plot_contour(df,bins=32,contourfplot_kws={'cmap':'coolwarm'})Acknowledgementstraja code implementation and analytical methods (particularlyrediscretize_points) are heavily inspired by Jim McLean’s R packagetrajr. Many thanks to Jim for his
feedback.