Skip to content

Conversation

@bergsalex
Copy link
Contributor

@bergsalex bergsalex commented Aug 24, 2025

Add Bout Statistics Feature

This PR adds bout statistics functionality to JABS-postprocess, enabling users to calculate and include aggregate bout-level metrics in behavior tables. This includes bout counts, duration statistics, and timing information.

Changes Made

  • New Method: BoutTable.add_bout_statistics() in src/jabs_postprocess/utils/project_utils.py

    • Calculates aggregate statistics per animal per behavior
    • Adds 5 new columns to bout tables with bout-level metrics
    • Handles edge cases (empty data, single bouts, mixed behavior states)
  • CLI Integration

    • Added --add-statistics flag to generate-tables command
    • New add-bout-statistics for post-processing existing tables
  • Testing

    • Tests for the new BoutTable.add_bout_statistics() method.
    • Tests for CLI commands to ensure correct functionality and output.

New Statistics Added

All commands add these columns to bout tables:

  • total_bout_count: Number of behavior bouts per animal
  • avg_bout_duration: Average bout duration per animal
  • bout_duration_std: Standard deviation of bout durations
  • bout_duration_var: Variance of bout durations
  • latency_to_first_bout: Frame number of first behavior bout

Usage Examples

During table generation:

jabs-postprocess generate-tables \
  --project-folder ./data --behavior grooming --add-statistics

Post-processing existing tables:

jabs-postprocess add-bout-statistics \
  --input-tables grooming_bouts.csv fighting_bouts.csv

Backward Compatibility

This feature is fully backward compatible:

  • No changes to existing APIs or file formats
  • New columns are optional and only added when explicitly requested
  • All existing functionality remains unchanged

@bergsalex bergsalex marked this pull request as ready for review August 25, 2025 12:47
@bergsalex bergsalex merged commit 2b3faf1 into master Aug 26, 2025
3 checks passed
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.

4 participants