Skip to content

Add Filter trajectories#796

Open
Edu92337 wants to merge 4 commits intoneuroinformatics-unit:mainfrom
Edu92337:filter_trajectories
Open

Add Filter trajectories#796
Edu92337 wants to merge 4 commits intoneuroinformatics-unit:mainfrom
Edu92337:filter_trajectories

Conversation

@Edu92337
Copy link
Contributor

@Edu92337 Edu92337 commented Feb 2, 2026

Description

What is this PR

  • Addition of a new feature

Why is this PR needed?

Tracking data often contains spurious short trajectories that are likely tracking errors. Currently, users need to manually write complex xarray selection code to filter these out. This PR adds a convenient utility function to streamline this common preprocessing task.

What does this PR do?

Adds filter_short_trajectories() function to movement.filtering module that:

  • Filters out individuals with fewer than a specified number of valid frames
  • Works at the Dataset level (filtering across all data variables)
  • Supports both poses and bounding boxes datasets
  • Includes optional print_report parameter to show which individuals were filtered
  • Follows existing filtering function patterns (consistent error handling with logger.error)

References

Closes #791

How has this PR been tested?

  • Added comprehensive unit tests in tests/test_unit/test_filtering.py covering:
    • Basic filtering for both poses and bboxes datasets
    • Edge cases (no individuals removed, all individuals removed, exact threshold)
    • Input validation (negative, zero, float, invalid types)
    • Missing individuals dimension
    • Attribute and coordinate preservation
    • Print report functionality
  • All existing tests pass
  • Tested manually with sample datasets to verify expected behavior

Is this a breaking change?

No. This is a new function with no changes to existing functionality.

Does this PR require an update to the documentation?

The function includes a comprehensive docstring with examples. The function will automatically appear in the API reference documentation when built. No additional documentation updates needed at this time, though a usage example could be added to the user guide in a future PR if desired.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (447492e) to head (7d5710f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #796   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           36        36           
  Lines         2205      2230   +25     
=========================================
+ Hits          2205      2230   +25     

☔ 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.

@sfmig sfmig force-pushed the filter_trajectories branch from e0b36d6 to 6c7d4c7 Compare February 4, 2026 11:41
@sfmig sfmig force-pushed the filter_trajectories branch from 6c7d4c7 to 7d5710f Compare February 13, 2026 20:11
@sonarqubecloud
Copy link

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.

Add utility to filter out short trajectories

1 participant