Skip to content

feat(backend): load STAC-format keypoint tracks#6

Merged
HugoFara merged 1 commit into
talmolab:mainfrom
HugoFara:feat-load-keypoints
Apr 22, 2026
Merged

feat(backend): load STAC-format keypoint tracks#6
HugoFara merged 1 commit into
talmolab:mainfrom
HugoFara:feat-load-keypoints

Conversation

@HugoFara

Copy link
Copy Markdown
Collaborator

Summary

Adds /api/load-keypoints and backend/keypoints_io so the UI can load already-resolved 3D keypoint tracks without going through monsees_retarget — the lab-private package that currently gates both /api/load-matfile and /api/load-acm. This unblocks end-to-end testing with real data for anyone who doesn't have monsees_retarget installed (CI, external contributors, new lab members).

Supported inputs

  • .h5 with a tracks dataset of shape (frames, [animals,] keypoints, 3) (SLEAP style) or a positions dataset of shape (frames, keypoints, 3).
  • .mat with a pred field of shape (frames, 3, keypoints) — matches stac-mjx/tests/data/test_rodent_mocap_1000_frames.mat.

Keypoint names come from a comma-separated kp_names query param if the count matches; otherwise the loader falls back to kp_0, kp_1, ....

Frontend
New Load KP button in the toolbar. Reuses the current acmKeypointNames from the store so names stay consistent when a config was loaded first.

Test plan

  • 9 unit tests in tests/test_keypoints_io.py with synthetic .h5 / .mat via tmp_path — covers both tracks layouts, the positions fallback, error paths, and name-count fallback
  • 2 "live" tests against stac-mjx/tests/data/test_rodent_mocap_1000_frames.mat (23 keypoints) and test_mouse_mocap_3600_frames.h5 (34 keypoints); skip gracefully when the stac-mjx checkout isn't alongside this repo
  • Integration via TestClient: uploading the rat fixture returns numFrames=1000, numKeypoints=23
  • pytest --ignore=tests/test_acm_processing.py → 17/17 pass
  • cd frontend && npm run build clean

Why two loaders?

Keeping the existing /api/load-matfile (which uses monsees_retarget to do forward kinematics on raw ACM joint angles) around because lab members with the package still need it for the Monsees data pipeline. /api/load-keypoints is the new supported path for anything already in keypoint form — which is what SLEAP, DeepLabCut, and stac-mjx's own test fixtures produce.

Adds /api/load-keypoints and backend/keypoints_io so the UI can load
already-resolved 3D keypoint tracks without going through
monsees_retarget (the lab-private dependency that gates /api/load-matfile
and /api/load-acm).

Supported inputs:
- .h5 with a `tracks` dataset (shape (frames, [animals,] keypoints, 3))
  or a `positions` dataset (shape (frames, keypoints, 3)).
- .mat with a `pred` field (shape (frames, 3, keypoints)), matching
  stac-mjx/tests/data/test_rodent_mocap_1000_frames.mat.

Keypoint names come from a comma-separated kp_names query param if the
count matches; otherwise the loader falls back to kp_0, kp_1, ...

Frontend: new "Load KP" button, reuses the current kpNames from the
store when sending the upload so names stay consistent across loads.

Tests:
- 9 unit tests with synthetic .h5 / .mat (tmp_path fixtures)
- 2 live tests against stac-mjx/tests/data fixtures that skip gracefully
  when the stac-mjx checkout isn't alongside this repo
@HugoFara HugoFara force-pushed the feat-load-keypoints branch from fda569d to b712e0c Compare April 22, 2026 21:36
@HugoFara

Copy link
Copy Markdown
Collaborator Author

Reviewed, merging.

@HugoFara HugoFara merged commit 2d6b3e7 into talmolab:main Apr 22, 2026
3 checks passed
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.

1 participant