Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions movement/kinematics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
"compute_forward_vector_angle",
"compute_kinetic_energy",
]
from .trajectory_metrics import trajectory_length, trajectory_variance
9 changes: 9 additions & 0 deletions movement/kinematics/trajectory_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import numpy as np


def trajectory_length(traj):
return np.sum(np.linalg.norm(np.diff(traj, axis=0), axis=1))


def trajectory_variance(traj):
return np.var(traj, axis=0).sum()
8 changes: 8 additions & 0 deletions tests/test_trajectory_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np

from movement.kinematics.trajectory_metrics import trajectory_length


def test_trajectory_length():
traj = np.array([[0, 0], [3, 4]])
assert trajectory_length(traj) == 5.0

Check warning on line 8 in tests/test_trajectory_metrics.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not perform equality checks with floating point values.

See more on https://sonarcloud.io/project/issues?id=neuroinformatics-unit_movement&issues=AZ1DanzRrB9c6w2G4FaJ&open=AZ1DanzRrB9c6w2G4FaJ&pullRequest=943