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

Fix IndexError for hdf5 file import for single instance analysis files #1695

Merged
merged 4 commits into from
Mar 17, 2024

Conversation

shrivaths16
Copy link
Contributor

@shrivaths16 shrivaths16 commented Feb 21, 2024

Description

While performing inference for single instances, there seems to be no track names generated. This is causing IndexError while trying to load a HDF5 file since, the number of tracks is 1 and the track_names is empty. So we add a condition to check this and create a single track accordingly.

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

  • New Features
    • Enhanced data import by importing FileHandle for improved functionality.
    • Introduced new fixtures small_robot_3_frame_hdf5, single_fly_hdf5, and single_fly_mp4_vid for testing.
    • Included constants TEST_SMALL_ROBOT3_FRAME_H5, TEST_SINGLE_FLY_H5, and TEST_SINGLE_FLY for test scenarios.
    • Added a new test function test_sleap_analysis_read to read Sleap analysis files using SleapAnalysisAdaptor.

Copy link

coderabbitai bot commented Feb 21, 2024

Walkthrough

A new test function was added to test_formats.py to test reading Sleap analysis files using SleapAnalysisAdaptor. This addition enhances the testing suite's coverage for reading Sleap analysis files.

Changes

File Path Change Summary
tests/fixtures/videos.py Added import for FileHandle.
Added constants and fixtures for single fly data.
tests/io/test_formats.py Added test function test_sleap_analysis_read.

🐇📝🧪
Tests and fixtures, a rabbit's delight,
New functions added, shining bright.
Code and data, hand in hand,
Ensuring Sleap files are grand.
🌟🐾🔍

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5fa1079 and dc1457f.
Files selected for processing (1)
  • sleap/io/format/sleap_analysis.py (1 hunks)
Additional comments: 1
sleap/io/format/sleap_analysis.py (1)
  • 81-81: The added condition to check if "track_names" exists and is not empty before proceeding is a good approach to handle the scenario where track names are missing in single instance analysis files. This fix should prevent the IndexError that was occurring due to an empty track_names list. However, it's important to ensure that the default track names generated in the else block (f"track_{i}") are suitable and consistent with the rest of the application's naming conventions.

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.38%. Comparing base (60a441f) to head (4d48a65).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1695   +/-   ##
========================================
  Coverage    73.38%   73.38%           
========================================
  Files          134      134           
  Lines        24064    24064           
========================================
+ Hits         17659    17660    +1     
+ Misses        6405     6404    -1     

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

@shrivaths16 shrivaths16 linked an issue Mar 11, 2024 that may be closed by this pull request
4 tasks
@shrivaths16 shrivaths16 changed the title Fix hdf5 import for single instance analysis files Fix IndexError for hdf5 file import for single instance analysis files Mar 11, 2024
Copy link
Collaborator

@talmo talmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dc1457f and 5c655b2.
Files ignored due to path filters (1)
  • tests/data/videos/single_fly.mp4 is excluded by: !**/*.mp4
Files selected for processing (2)
  • tests/fixtures/videos.py (2 hunks)
  • tests/io/test_formats.py (1 hunks)
Additional comments: 7
tests/fixtures/videos.py (5)
  • 4-4: Import of FileHandle added.

This import is necessary for handling file operations with the newly added fixture single_fly_hdf5.

  • 11-11: Added constant TEST_SINGLE_FLY_H5.

This constant provides a clear and reusable reference to the path of the single fly HDF5 file used in tests.

  • 14-16: Added fixture single_fly_hdf5.

This fixture correctly utilizes the FileHandle class to manage the single fly HDF5 file, facilitating its use in tests.

  • 52-52: Added constant TEST_SINGLE_FLY.

This constant serves a similar purpose as TEST_SINGLE_FLY_H5, providing a clear reference to the single fly MP4 video file.

  • 55-57: Added fixture single_fly_mp4_vid.

This fixture is well-implemented for loading the single fly MP4 video file using the Video.from_media method, aligning with the existing pattern for video fixtures.

tests/io/test_formats.py (2)
  • 22-22: Import of SleapAnalysisAdaptor added.

This import is necessary for the new test function test_sleap_analysis_read to validate reading Sleap analysis files.

  • 25-34: Added test function test_sleap_analysis_read.

This test function is well-structured and effectively validates the reading of single instance hdf5 analysis files, ensuring that the expected number of videos, tracks, and skeletons are loaded correctly.

Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test. For the fixture, I think it's a bit big. Maybe we can use one of the videos we already have (proposing small_robot.mp4) and also making a really small analysis file from that.

tests/io/test_formats.py Outdated Show resolved Hide resolved
tests/data/videos/single_fly.mp4 Outdated Show resolved Hide resolved
tests/data/hdf5_format_v1/single_fly.h5 Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5c655b2 and f0fd539.
Files selected for processing (2)
  • tests/fixtures/videos.py (2 hunks)
  • tests/io/test_formats.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tests/fixtures/videos.py
  • tests/io/test_formats.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f0fd539 and 4d48a65.
Files selected for processing (1)
  • tests/fixtures/videos.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/fixtures/videos.py

@talmo talmo merged commit 8ab323e into develop Mar 17, 2024
9 checks passed
@talmo talmo deleted the shrivaths/hdf5-import-error-fix branch March 17, 2024 02:49
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.

IndexError during import SLEAP Analysis H5 file
3 participants