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

Adding support for more .nwb training data to SLEAP #101

Closed

Conversation

keyaloding
Copy link

@keyaloding keyaloding commented Jun 28, 2024

Description

Right now, data from NWB (Neurodata without Borders) is partially supported in sleap-io. The PoseEstimation and PoseEstimationSeries data structures are supported, but the TrainingFrame, TrainingFrames, PoseTraining, and SourceVideos structures are not. These data structures correspond to data structures in SLEAP as shown in rly/ndx-pose#24. I will add support for these data types in sleap-io by allowing the user to save and load them.

My plan is to update the save_nwb and load_nwb functions in io/main.py to allow support for classes besides Labels. I will also update the read_nwb function in io/nwb.py so that it can read NWB data structures and return the corresponding SLEAP structures. So far, I have written a function convert_nwb that uses NWB objects to initialize corresponding SLEAP objects with the same attributes. https://github.com/keyaloding/io_fork/blob/70a34ede294d3c783d1758c55c1dd9752e29f1e7/sleap_io/io/nwb.py#L37-L72. I will write new tests that confirm that the attributes of the SLEAP data structures that are initialized have the same attributes as the NWB data structures used to create them.

I will also update the documentation to include information about how to use NWB data in SLEAP.

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?

#100, #86, rly/ndx-pose#29

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!

❤️

Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 testing code 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 testing code 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 testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 29, 2024

Codecov Report

Attention: Patch coverage is 15.38462% with 11 lines in your changes missing coverage. Please review.

Project coverage is 95.42%. Comparing base (5a30110) to head (2bd6d91).

Files Patch % Lines
sleap_io/io/nwb.py 15.38% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
- Coverage   96.04%   95.42%   -0.62%     
==========================================
  Files          17       17              
  Lines        2022     2034      +12     
==========================================
- Hits         1942     1941       -1     
- Misses         80       93      +13     

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

sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
tests/io/test_nwb.py Outdated Show resolved Hide resolved
tests/io/test_nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Show resolved Hide resolved
@@ -47,7 +47,7 @@ def save_slp(
return slp.write_labels(filename, labels, embed=embed)


def load_nwb(filename: str) -> Labels:
def load_nwb(filename: str, format: str) -> Labels:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: since we only have two "formats", it might be easier to just make this a boolean. For example:

def load_nwb(filename: str, as_training: bool | None = None):
    if as_training is None:
        as_training = ...  # try to auto-detect based on whether there are tracks or user-labeled instances

    if as_training:
        return nwb.read_nwb_training(filename)
    else:
        return nwb.read_nwb(filename)

And maybe we want to rename nwb.read_nwb to nwb.read_nwb_predictions for clarity?

Copy link
Contributor

Choose a reason for hiding this comment

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

PS: We probably want to keep nwb.read_nwb and anything else that existed before as an alias for backwards compatibility.

sleap_io/io/main.py Outdated Show resolved Hide resolved
sleap_io/io/main.py Outdated Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely cannot commit a 16 MB test file!! Shoot for 1-2 MB max by reducing the contents of the file to the minimal subset that still allows for testing the functionality. If not possible, then maybe will need to generate the testing artifacts dynamically (e.g., converting from the base SLP file and saving to a temp dir).

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this getting changed? It's not a part of this PR's scope but is used in a lot of the rest of the package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this new? Why can't we use one of the other SLP files in https://github.com/talmolab/sleap-io/tree/main/tests/data/slp?

sleap_io/io/nwb.py Show resolved Hide resolved
sleap_io/io/nwb.py Outdated Show resolved Hide resolved
@keyaloding keyaloding closed this Jul 12, 2024
@keyaloding keyaloding deleted the kloding/add_nwb_training_structures branch July 12, 2024 16:18
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.

3 participants