Skip to content

Conversation

@bergsalex
Copy link
Contributor

Normalized behavior names to bridge differences between annotation labels and prediction keys (e.g., rearing (unsupported) vs Rearing_unsupported).

Added helper functions to resolve behavior keys consistently and applied them when parsing JABS annotation JSON and prediction HDF5 files. Added unit tests covering normalization, resolution, annotation matching, and prediction lookup.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR normalizes behavior name handling to bridge differences between annotation labels (e.g., "rearing (unsupported)") and prediction keys (e.g., "Rearing_unsupported").

Changes:

  • Added normalize_behavior_name() and resolve_behavior_key() helper functions to standardize behavior name matching
  • Updated BoutTable.from_jabs_annotation_file() and Prediction.generate_bout_table() to use normalized behavior matching
  • Added comprehensive unit tests for normalization, resolution, and integration with existing methods

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/utils/test_behavior_normalization.py Adds unit tests covering normalization rules, resolution logic, and integration with annotation/prediction parsing
src/jabs_postprocess/utils/project_utils.py Implements normalization helpers and updates behavior matching logic in existing methods
pyproject.toml Bumps version from 0.5.3 to 0.5.4

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return normalized.lower()


def resolve_behavior_key(behavior: str, available_behaviors: List[str]) -> str | None:
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The function returns None when multiple matches are found (ambiguous case), but this is indistinguishable from the case where no matches are found. Consider returning a more informative result (e.g., raising an exception for ambiguous matches or returning a tuple indicating the error type) to help callers differentiate between these scenarios.

Copilot uses AI. Check for mistakes.
Comment on lines +1367 to +1368
behavior_key = resolve_behavior_key(settings.behavior, available_keys)
if behavior_key is None:
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

When behavior_key is None, the error message doesn't indicate whether the issue was ambiguous matching or no match found. Consider updating the error handling to provide a more specific message based on the resolution failure reason.

Copilot uses AI. Check for mistakes.
@gbeane
Copy link
Contributor

gbeane commented Jan 13, 2026

jabs-behavior-classifier has a function that normalizes behavior names before using them as filenames. I think it's called to_safe_name or something like that. I don't remember exactly what it does, but we should probably do the same thing here and there (and eventually when we merge the repos use the same code)

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