Skip to content

refactor: Use sleap-io for analysis HDF5 and CSV exports#2649

Merged
gitttt-1234 merged 3 commits intodevelopfrom
refactor/use-sleap-io-for-analysis-export
Mar 11, 2026
Merged

refactor: Use sleap-io for analysis HDF5 and CSV exports#2649
gitttt-1234 merged 3 commits intodevelopfrom
refactor/use-sleap-io-for-analysis-export

Conversation

@gitttt-1234
Copy link
Copy Markdown
Collaborator

Summary

  • Replace SLEAP's internal write_tracking_h5.py with sleap-io's save_analysis_h5() and save_csv() functions
  • Consolidate analysis export logic into a single source of truth (sleap-io)
  • Maintain backwards compatibility with existing analysis file readers

Changes Made

  • sleap/io/format/sleap_analysis.py:

    • Use sio.load_analysis_h5() for reading (replaces 50+ lines of custom parsing)
    • Use sio.save_analysis_h5() for writing with preset="matlab" for SLEAP-compatible format
  • sleap/io/format/csv.py:

    • Use sio.save_csv() with format="sleap" instead of write_tracking_h5(..., csv=True)
  • sleap/io/convert.py:

    • Use sleap-io functions for both HDF5 and CSV analysis export in the CLI

Benefits

  1. Single source of truth: Analysis export logic lives in sleap-io, reducing code duplication
  2. Enhanced metadata: sleap-io adds dims attributes to datasets and file-level metadata (preset, format, sleap_io_version)
  3. Consistent format: Exports from SLEAP GUI and sleap-io CLI now produce identical files
  4. Better maintainability: Future enhancements (like Add option to analysis export that will export predictions for all frames (including those with no predictions) #1651 for full video length export) only need to be implemented in sleap-io

Backwards Compatibility

  • Output files use preset="matlab" which produces the same axis ordering as the original implementation
  • Extra HDF5 attributes are additive and won't break existing readers (MATLAB, Python, etc.)
  • sleap-io's reader handles both old and new format files

Related Issues

Testing

  • Manual testing of analysis HDF5 export from GUI
  • Manual testing of CSV export from GUI
  • Manual testing of sleap-convert --format analysis
  • Verify output files can be read by existing scripts

🤖 Generated with Claude Code

Replace SLEAP's internal write_tracking_h5.py with sleap-io's
save_analysis_h5() and save_csv() functions for exporting analysis files.

Benefits:
- Single source of truth for analysis export logic (sleap-io)
- Consistent format between SLEAP GUI and sleap-io CLI exports
- Additional metadata in output files (dimension labels, skeleton info)
- Backwards compatible with existing analysis file readers

Changes:
- sleap/io/format/sleap_analysis.py: Use sio.load_analysis_h5() and
  sio.save_analysis_h5() instead of custom implementation
- sleap/io/format/csv.py: Use sio.save_csv() instead of write_tracking_h5
- sleap/io/convert.py: Use sleap-io functions for analysis export

Related to #1651 (analysis export enhancements)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
github-actions bot pushed a commit that referenced this pull request Mar 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 11, 2026

Docs Preview

Preview has been removed.

sleap-io raises ValueError when a video has no labeled frames, but
the old SLEAP behavior was to silently skip such videos. Add try-except
to maintain backwards compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
github-actions bot pushed a commit that referenced this pull request Mar 11, 2026
sleap-io's save_csv doesn't raise ValueError when there are no labeled
frames - it writes an empty file. Check for labeled frames BEFORE calling
the export function to maintain old behavior of skipping empty videos.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
github-actions bot pushed a commit that referenced this pull request Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 70.96774% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.52%. Comparing base (960fd9f) to head (37df3f6).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
sleap/io/format/sleap_analysis.py 44.44% 5 Missing ⚠️
sleap/io/format/csv.py 66.66% 3 Missing ⚠️
sleap/io/convert.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2649      +/-   ##
===========================================
- Coverage    64.54%   64.52%   -0.03%     
===========================================
  Files           95       95              
  Lines        20223    20205      -18     
===========================================
- Hits         13053    13037      -16     
+ Misses        7170     7168       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gitttt-1234 gitttt-1234 merged commit 2200190 into develop Mar 11, 2026
12 checks passed
@gitttt-1234 gitttt-1234 deleted the refactor/use-sleap-io-for-analysis-export branch March 11, 2026 23:31
github-actions bot added a commit that referenced this pull request Mar 11, 2026
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