Skip to content

feat: Redesign orientation API with perpendicular vector and vector-from-to#853

Open
mujju-212 wants to merge 2 commits intoneuroinformatics-unit:mainfrom
mujju-212:feat/616-orientation-api-redesign
Open

feat: Redesign orientation API with perpendicular vector and vector-from-to#853
mujju-212 wants to merge 2 commits intoneuroinformatics-unit:mainfrom
mujju-212:feat/616-orientation-api-redesign

Conversation

@mujju-212
Copy link

Summary

Closes #616

This PR redesigns the orientation API as discussed in the issue and community call, adding composable vector computation and angle functions.

Changes

New Functions

Function Purpose
compute_perpendicular_vector(data, left_keypoint, right_keypoint, camera_view) Renamed from compute_forward_vector — same cross-product logic, clearer name reflecting that it produces a vector perpendicular to the left–right axis
compute_vector_from_to(data, from_keypoint, to_keypoint) New — computes a direction vector between any two keypoints via subtraction (e.g., neck → nose for head direction)
compute_vector_angle(vector, reference_vector, in_degrees) New — computes the signed angle of any pre-computed vector DataArray against a reference direction. Supports both static tuples and time-varying DataArray references

Deprecated Functions

Function Replacement Backward Compatible?
compute_forward_vector compute_perpendicular_vector ✅ Yes — wrapper emits DeprecationWarning
compute_forward_vector_angle compute_perpendicular_vector + compute_vector_angle ✅ Yes — wrapper emits DeprecationWarning

Design Decisions

  • Follows the API design from Adding the option for front-back instead of left-right points for forward vector calculation. #616 comments (sfmig / niksirbi's decomposition into separate vector + angle steps)
  • Composable: compute any vector first, then optionally get its angle — no tight coupling
  • Backward compatible: existing code using compute_forward_vector / compute_forward_vector_angle continues to work with deprecation warnings
  • Immutable: no input data is modified (per project conventions)

Example Usage

from movement.kinematics import compute_vector_from_to, compute_vector_angle

# Head direction from neck to nose
head_dir = compute_vector_from_to(ds.position, "neck", "nose")
head_angle = compute_vector_angle(head_dir, in_degrees=True)

# Perpendicular vector (replaces compute_forward_vector)
from movement.kinematics import compute_perpendicular_vector
perp = compute_perpendicular_vector(ds.position, "left_ear", "right_ear")

Tests

  • Rewrote test_orientation.py with 26 tests covering all new and deprecated functions
  • Organized into clear test classes: TestVectorFromTo, TestVectorAngle, TestForwardVectorAngle
  • All 138 kinematics + ROI tests pass (backward compatibility confirmed)
  • Deprecation warnings correctly emitted in downstream test_roi/test_angles.py

Files Changed

File Description
movement/kinematics/orientation.py Core implementation — 3 new functions + 2 deprecated wrappers
movement/kinematics/__init__.py Updated exports
tests/test_unit/test_kinematics/test_orientation.py Full test rewrite

…rom-to (neuroinformatics-unit#616)

- Add compute_perpendicular_vector() - renamed from compute_forward_vector
  with clearer semantics (cross-product of left-right with up axis)
- Add compute_vector_from_to() - new function for direction vectors
  between any two keypoints (e.g. neck-to-nose)
- Add compute_vector_angle() - new function to compute signed angles
  of pre-computed vectors against a reference direction
- Deprecate compute_forward_vector() and compute_forward_vector_angle()
  with backward-compatible wrappers that emit DeprecationWarning
- Update kinematics __init__.py exports
- Rewrite orientation test suite with full coverage (26 tests)

Closes neuroinformatics-unit#616
@mujju-212 mujju-212 force-pushed the feat/616-orientation-api-redesign branch from a3a626d to 2958fd3 Compare March 11, 2026 18:20
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding the option for front-back instead of left-right points for forward vector calculation.

1 participant