Skip to main content

trajectorytools

trajectorytools is a library with some utils to study and plot 2D trajectories.

Installation

From PyPI

pip install trajectorytools

From Source

To clone this repository:

git clone https://github.com/fjhheras/trajectorytools

To install requirements:

pip install -r requirements.txt

To install the package:

pip install .

or alternatively, locally with a symlink:

pip install -e .

If you see this error: “gcc: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory” you need the GNU C++ compiler. To install it in, for example, Ubuntu and derivatives:

sudo apt install g++

Example

import numpy as np
import matplotlib as mpl

import trajectorytools as tt
import trajectorytools.animation as ttanimation
import trajectorytools.socialcontext as ttsocial
from trajectorytools.constants import test_raw_trajectories_path

# Loading test trajectories as a numpy array of locations
test_trajectories = np.load(test_raw_trajectories_path, allow_pickle=True)

# We will process the numpy array, interpolate nans and smooth it.
# To do this, we will use the Trajectories API
smooth_params = {'sigma': 1}
traj = tt.Trajectories.from_positions(test_trajectories,
                                      smooth_params=smooth_params)

# We assume a circular arena and populate center and radius keys
center, radius = traj.estimate_center_and_radius_from_locations()

# We center trajectories around the estimated center
traj.origin_to(center)

# We will normalise the location by the radius:
traj.new_length_unit(radius)

# We will change the time units to seconds. The video was recorded at 32
# fps, so we do:
traj.new_time_unit(32, 'second')

# Now we can find the smoothed trajectories, velocities and accelerations
# in traj.s, traj.v and traj.a
# We can use, for instance, the positions in traj.s and find the border of
# the group:
in_border = ttsocial.in_alpha_border(traj.s, alpha=5)

# Animation showing the fish on the border
colornorm = mpl.colors.Normalize(vmin=0,
                                 vmax=3,
                                 clip=True)
mapper = mpl.cm.ScalarMappable(norm=colornorm, cmap=mpl.cm.RdBu)
color = mapper.to_rgba(in_border)

anim1 = ttanimation.scatter_vectors(traj.s, velocities=traj.v, k=0.3)
anim2 = ttanimation.scatter_ellipses_color(traj.s, traj.v, color)
anim = anim1 + anim2

anim.prepare()
anim.show()

In the directory examples, you can find some more example scripts. Scripts use some example trajectories, which can be found in data. All example trajectories were obtained using idtracker.ai on videos recorded in de Polavieja Lab (Champalimaud Research, Lisbon)

— NOTE

Note that, when using constructors like from_idtrackerai and from_positions, we need to calculate velocity and accelerations from positions. As a result, the traj object has 2 frames less than the original positions array. By default, the missing frames correspond to the first and last frames of the video. If you used the option “only_past”:True in smooth_params, the missing frames correspond to the first two frames of the video.

—

Project maintainers

Francisco J.H. Heras (2017-) Francisco Romero Ferrero (2017-) Dean Rance (2021-)

Contribute

We welcome contributions. The preferred way to report problems is by creating an issue. The best way to propose changes in the code is to create a pull request. Please, check our contribution guidelines and our code of conduct.

License

This project is licensed under the terms of the GNU General Public License v3.0 (See COPYING). This means that you may copy, distribute and modify the software as long as you track changes/dates in source files. However, any modifications to GPL-licensed code must also be made available under the GPL along with build & install instructions.

If you use this work in an academic context and you want to acknowledge us, please cite some of the relevant papers:

Romero-Ferrero, F., Bergomi, M. G., Hinz, R. C., Heras, F. J., & de Polavieja, G. G. (2019). idtracker.ai: tracking all individuals in small or large collectives of unmarked animals. Nature methods, 1

Heras, F. J., Romero-Ferrero, F., Hinz, R. C., & de Polavieja, G. G. (2019). Deep attention networks reveal the rules of collective motion in zebrafish. PLoS computational biology, 15(9), e1007354.

Metadata

Release files for trajectorytools-shaliulab 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trajectorytools-shaliulab 0.3.6
File Size Uploaded Provenance
trajectorytools-shaliulab-0.3.6.tar.gz 878.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for trajectorytools-shaliulab 0.3.6
File Interpreter ABI Platform
trajectorytools_shaliulab-0.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 1.8 MB

Release files / trajectorytools-shaliulab-0.3.6.tar.gz

Download URL trajectorytools-shaliulab-0.3.6.tar.gz
Size 878.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c77ecd47d55a778470efd6ee1b0e656913da9f4f0f13cb540609cb0e50116306
BLAKE2b-256 checksum
How to use checksums
dfbb05d63fd806cac29dcca0191a73c77186568daf0e05d1bd963b18333f61c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.4

Release files / trajectorytools_shaliulab-0.3.6-py3-none-any.whl

Download URL trajectorytools_shaliulab-0.3.6-py3-none-any.whl
Size 884.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7b65ccf7a585e86a1353530522ba74e2db16ece4796518b4b52b488d1716232
BLAKE2b-256 checksum
How to use checksums
ff46f01ffc94825de7d2b67f5c900fc6a22da7500c23f7eef1dc3ed3dd962a8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.4

Security for trajectorytools-shaliulab 0.3.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page