Add LEAP .mat format reader#224
Merged
Merged
Conversation
This adds support for reading LEAP (LEAP Estimates Animal Pose) MATLAB files. LEAP is a deep learning framework for animal pose estimation that exports tracking data in .mat format. Key changes: - Add new `sleap_io/io/leap.py` module with `read_labels()` function - Parse skeleton structure from LEAP data (nodes and edges) - Convert LEAP position data to SLEAP instances - Handle MATLAB 1-based to Python 0-based indexing conversion - Add `load_leap()` wrapper in main.py with .mat file detection - Export load_leap from package __init__.py - Add pymatreader as optional dependency in [mat] group - Add comprehensive tests and fixture for LEAP format - Support custom skeleton override when loading The implementation is read-only (no writer) as LEAP files are typically generated by the LEAP software itself. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
==========================================
+ Coverage 93.14% 93.19% +0.04%
==========================================
Files 24 25 +1
Lines 5119 5199 +80
Branches 1378 1403 +25
==========================================
+ Hits 4768 4845 +77
Misses 156 156
- Partials 195 198 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Test alternative position field names (pose, posedata) - Test single frame (2D array) position data - Test various skeleton parsing edge cases (numpy arrays, non-string names) - Test video path inference when boxPath is missing - Improve coverage from 76.9% to 94.0% 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Change default video extension inference to .mp4 (more common than .avi) - Remove redundant .mp4 fallback logic - Add test case for 1D numpy edge arrays that need reshaping to 2D - This covers line 103 for complete branch coverage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Split combined import statement into separate lines per ruff style guide. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add load_leap to formats.md API reference - Include LEAP in supported formats list in index.md - Add .mat (LEAP) to format detection tip in examples.md - Document mat optional dependency for LEAP support 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
JABS format uses .h5 files, not .jabs. Corrected the documentation to accurately reflect this. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for reading LEAP (LEAP Estimates Animal Pose) MATLAB
.matfiles. LEAP is a deep learning framework for animal pose estimation that exports tracking data in MATLAB format. This implementation provides a read-only interface to import LEAP tracking data into the SLEAP ecosystem.Key Changes
Core Implementation
sleap_io/io/leap.pywithread_labels()function for parsing LEAP.matfilesload_leap()wrapper function and automatic.matfile format detection inload_file()sleap_io/__init__.pyto exposeload_leapfunctionpymatreaderas an optional dependency in the[mat]extra groupData Parsing Features
nodesorjointsfields, builds edge connectionspositions,pose,posedata).matfile path whenboxPathfield is missingExample Usage
Installation
To use the LEAP reader, install sleap-io with the mat extra:
API Changes
New Public Functions
sleap_io.load_leap(filename: str, skeleton: Optional[Skeleton] = None) -> Labelssleap_io.io.leap.read_labels(labels_path: str, skeleton: Optional[Skeleton] = None) -> LabelsUpdated Functions
load_file()now automatically detects.matfiles and routes them to the LEAP loaderTesting
Comprehensive test coverage (94.0%) with 11 test cases covering:
Design Decisions
Read-only Implementation: LEAP files are typically generated by the LEAP software itself, so writing support was not implemented. Users should export from LEAP and import into SLEAP.
Video Path Inference: When
boxPathis missing from the.matfile, we infer the video path by replacing the.matextension with.mp4(most common video format).Flexible Field Names: LEAP exports may use different field names (
positions,pose,posedata) depending on the version. The reader tries multiple alternatives.Array Shape Handling: LEAP may store positions as either (nodes, 2, frames) or (frames, nodes, 2). The reader automatically detects and transposes as needed.
Optional Dependency:
pymatreaderis only required when using LEAP functionality, keeping the base installation lightweight.File Format Notes
LEAP
.matfiles typically contain:skeleton: Dictionary withnodes/joints(node names) andedges(connections)positions/pose/posedata: Array of shape (nodes, 2, frames) or (frames, nodes, 2)boxPath: Optional path to the associated video fileFuture Considerations
🤖 Generated with Claude Code