feat: add compute_inactivity_bouts() for detecting inactivity periods#884
Open
mujju-212 wants to merge 3 commits into
Open
feat: add compute_inactivity_bouts() for detecting inactivity periods#884mujju-212 wants to merge 3 commits into
mujju-212 wants to merge 3 commits into
Conversation
- Add strict=False to zip() call in _label_bouts (B905) - Wrap long lines in test_inactivity_bouts.py to stay within 79 chars (E501) - Shorten two docstrings that exceeded the line limit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Closes #760.
Adds
compute_inactivity_bouts()tomovement.kinematics, implementing the inactivity detection feature requested in #760 (reframed by @niksirbi from "freezing detection" to the more general "inactivity" concept).API
Returns an
xr.DataArraynamed"inactivity_bout_id"with the sametime(and any extra individual/keypoint) dimensions as the input but without thespacedimension. Each frame is labelled with an integer:0= active,1, 2, 3, …= consecutive inactive bouts ordered by onset time.Implementation details
compute_speed()— uses the existing kinematics pipeline (velocity → norm) rather than reimplementing differentiation.speed_threshold: frames wherespeed < speed_thresholdare candidates for inactivity.min_bout_duration: contiguous inactive stretches shorter than this (in the units of thetimecoordinate) are discarded. Defaults to0.0(keep all bouts including single-frame ones).spacedimension are always treated as active, never as inactive. This prevents the central-differences artefact wherenumpy.gradientcan computespeed ≈ 0at a NaN frame by using its non-NaN neighbours.xr.apply_ufuncwithvectorize=Truelabels each individual/keypoint track independently, so bout IDs restart from 1 for each track.Changes
movement/kinematics/kinematics.pycompute_inactivity_bouts()+import numpy as npmovement/kinematics/__init__.pycompute_inactivity_boutstests/test_unit/test_kinematics/test_inactivity_bouts.pyTests (20 new)
TestComputeInactivityBoutsBasicTestMinBoutDurationTestNaNHandlingTestMultipleIndividualsTestInvalidInputsType of change
Checklist
compute_speed,validate_dims_coords,logger.error)