Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for computing ego- and allocentric angles to RoIs #416

Merged
merged 42 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c01078c
Write distance_to, nearest_point_to, and vector_to methods of RoIs
willGraham01 Feb 11, 2025
ea32661
Tests for distance_to and nearest_point_to
willGraham01 Feb 11, 2025
78c9f06
Write tests for vector_to
willGraham01 Feb 11, 2025
f5e5d0f
Write angle from forward method
willGraham01 Feb 12, 2025
d96fc5f
Clarify some docstrings
willGraham01 Feb 12, 2025
e9be4bc
Rename methods to use the movement 'compute_' convention
willGraham01 Feb 12, 2025
d1010a2
Tidy up approach vector method and tests
willGraham01 Feb 13, 2025
fe3d3b1
Methods for ego- and allocentric angles
willGraham01 Feb 13, 2025
a23eae8
Tests for egocentric angles
willGraham01 Feb 13, 2025
7ae970d
Tests for allocentric calculation
willGraham01 Feb 13, 2025
2638804
CodeCov can't typecheck
willGraham01 Feb 17, 2025
d74866d
Refactor computation of approach vector from keypoint centroid
willGraham01 Feb 17, 2025
c412a6c
Use literal instead of repeat value
willGraham01 Feb 17, 2025
df84664
OK, now I've literal-ed the literal. Happy SonarQube?
willGraham01 Feb 17, 2025
77c3554
Fix rebase barfs
willGraham01 Feb 17, 2025
2672938
Write method for computing angle to segment support
willGraham01 Feb 17, 2025
13526e2
Give internal method a more descriptive name
willGraham01 Feb 18, 2025
3adc38a
Merge branch 'main' into wgraham-370-368-roi-vectors
willGraham01 Feb 18, 2025
de3f3b0
Avoid implicit float comparison
willGraham01 Feb 18, 2025
6d82bc1
Remove redundant error-catches that are checked in lower-level functions
willGraham01 Feb 18, 2025
64d1cf0
Implememnt minor suggestions for RoI class changes from review
willGraham01 Feb 21, 2025
57edda6
Move conftest to fixtures directory
willGraham01 Feb 21, 2025
4414924
Patch up test files
willGraham01 Feb 21, 2025
aca4c5f
Tidy up factory fixture
willGraham01 Feb 21, 2025
96f5e16
Remove the choice of approach vector direction
willGraham01 Feb 21, 2025
db57f2e
Approach vector is by default not normalised
willGraham01 Feb 21, 2025
de7768d
Standardise treatment of the boundary, and the boundary keyword argument
willGraham01 Feb 21, 2025
cc20ba3
Variable name review for code readability
willGraham01 Feb 21, 2025
591f2c5
Rework allocentric computation, following code recommendations
willGraham01 Feb 21, 2025
3cf6e8c
Rework egocentric vector computation
willGraham01 Feb 21, 2025
c8f88f8
Rework line support case
willGraham01 Feb 21, 2025
d824bbb
Refactor common boundary angle methodology
willGraham01 Feb 21, 2025
6f45187
Pass over the docstrings again
willGraham01 Feb 21, 2025
a26bcd5
Merge branch 'main' into wgraham-370-368-roi-vectors
willGraham01 Feb 21, 2025
27a74b1
Suggestions from code review number 1
willGraham01 Feb 25, 2025
cbf74d2
Code review comments 2
willGraham01 Feb 25, 2025
6a38ee9
Merge branch 'main' into wgraham-370-368-roi-vectors
willGraham01 Feb 25, 2025
1841322
Restrict normal to single-segment lines
willGraham01 Feb 25, 2025
ec67f68
Write test for multi-segment normals being forbidden
willGraham01 Feb 25, 2025
a412478
Generalise forward_vector to direction
willGraham01 Feb 25, 2025
ce4003e
Apply suggestions from code review
willGraham01 Feb 25, 2025
57bf48e
Apply suggestions from @sfmig code review
willGraham01 Feb 26, 2025
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
19 changes: 10 additions & 9 deletions movement/kinematics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Compute kinematic variables like velocity and acceleration."""

import itertools
from collections.abc import Hashable
from typing import Literal

import numpy as np
Expand Down Expand Up @@ -205,8 +206,8 @@ def compute_speed(data: xr.DataArray) -> xr.DataArray:

def compute_forward_vector(
data: xr.DataArray,
left_keypoint: str,
right_keypoint: str,
left_keypoint: Hashable,
right_keypoint: Hashable,
camera_view: Literal["top_down", "bottom_up"] = "top_down",
) -> xr.DataArray:
"""Compute a 2D forward vector given two left-right symmetric keypoints.
Expand All @@ -223,9 +224,9 @@ def compute_forward_vector(
The input data representing position. This must contain
the two symmetrical keypoints located on the left and
right sides of the body, respectively.
left_keypoint : str
left_keypoint : Hashable
Name of the left keypoint, e.g., "left_ear"
right_keypoint : str
right_keypoint : Hashable
Name of the right keypoint, e.g., "right_ear"
camera_view : Literal["top_down", "bottom_up"], optional
The camera viewing angle, used to determine the upwards
Expand Down Expand Up @@ -357,8 +358,8 @@ def compute_head_direction_vector(

def compute_forward_vector_angle(
data: xr.DataArray,
left_keypoint: str,
right_keypoint: str,
left_keypoint: Hashable,
right_keypoint: Hashable,
reference_vector: xr.DataArray | ArrayLike = (1, 0),
camera_view: Literal["top_down", "bottom_up"] = "top_down",
in_radians: bool = False,
Expand All @@ -371,7 +372,7 @@ def compute_forward_vector_angle(
Forward vector angle is the :func:`signed angle\
<movement.utils.vector.compute_signed_angle_2d>`
between the reference vector and the animal's :func:`forward vector\
<movement.kinematics.compute_forward_vector>`).
<movement.kinematics.compute_forward_vector>`.
The returned angles are in degrees, spanning the range :math:`(-180, 180]`,
unless ``in_radians`` is set to ``True``.

Expand All @@ -381,10 +382,10 @@ def compute_forward_vector_angle(
The input data representing position. This must contain
the two symmetrical keypoints located on the left and
right sides of the body, respectively.
left_keypoint : str
left_keypoint : Hashable
Name of the left keypoint, e.g., "left_ear", used to compute the
forward vector.
right_keypoint : str
right_keypoint : Hashable
Name of the right keypoint, e.g., "right_ear", used to compute the
forward vector.
reference_vector : xr.DataArray | ArrayLike, optional
Expand Down
Loading
Loading