Repository navigation
Make zarr time axis dense - #291
Merged
Merged
Conversation
Load VIA tracks files with `use_frame_numbers_from_file=True` so `time` holds the clip's real frame numbers, then reindex onto the clip's full frame range (from the metadata csv) so the axis is dense: a frame with no tracked boxes is a NaN row rather than an absent label. `escape_state` is now sized by the clip rather than by however many rows survived, so its onset lands on the right frame. Adds `_validate_frames_in_clip_range`, because `reindex` silently drops out-of-range labels: a file tracked on the full video, or paired with the wrong metadata row, would otherwise yield a mostly-NaN dataset with no error. Also guards the escape frame, which previously could slice nothing and leave `escape_state` all zeros. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The existing fixtures are the bug's best witness (a 101-frame clip whose VIA tracks file holds boxes for 7 frames, with the escape at clip frame 51), so they are kept as they are and only asserted against harder. Adds coverage for a contiguous tracks file, and for both new guards. The factory grows an optional `frame_indices` argument so the guard tests can write frames outside the clip's range; its default is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
States that `time` is the clip's 0-based frame index and spans the whole clip, gives the slice recipe for a single clip's frame range, says why `dropna(dim="time", how="all")` is not that recipe, and warns that stores built before this change mean something else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
sfmig
commented
Sep 16, 2026
Comment on lines
+31
to
+33
| By default the file holds boxes for a sparse set of frames of a | ||
| 101-frame clip, which is the case the dense `time` axis is about. | ||
| Pass `frame_indices` to write boxes for a different set of frames. |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| By default the file holds boxes for a sparse set of frames of a | |
| 101-frame clip, which is the case the dense `time` axis is about. | |
| Pass `frame_indices` to write boxes for a different set of frames. | |
| By default the file holds boxes for a sparse set of frames within a | |
| 101-frame clip. Pass `frame_indices` to write boxes for a different | |
| set of frames. |
Co-authored-by: sfmig <33267254+sfmig@users.noreply.github.com> Signed-off-by: sfmig <33267254+sfmig@users.noreply.github.com>
for more information, see https://pre-commit.ci
The batched review suggestions were applied through the GitHub UI, so they never went through pre-commit locally and reintroduced long docstring, comment and f-string lines. E501 has no autofix, so pre-commit.ci could not clean them up either. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
sfmig
marked this pull request as ready for review
September 17, 2026 14:22
This reverts commit 9a57dd1.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #291 +/- ##
==========================================
+ Coverage 50.53% 50.89% +0.35%
==========================================
Files 26 26
Lines 1670 1682 +12
==========================================
+ Hits 844 856 +12
Misses 826 826 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5 of 7 tasks
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
What is this PR?
Why is this PR needed?
Currently, the zarr store that collects the crab tracks across the full set of videos has a sparse time axis. This means that for a given clip, the time dimension has coordinates only for the frames with data. This is because the VIA tracks file only records detections, and therefore only logs frames with data.
When concatenating the data across clips of the same video, the time dimension becomes less sparse (as it will become the union of all 'coordinates' per clip), but there is no guarantee that it will be dense for any video.
Importantly, because the data per clip was loaded with
use_frame_numbers_from_file=False, the frame numbers are mapped to ordinal numbers 0,1,2,... If there are frames with no detections in the clip, this can be confusing and lead to error (e.g. this would make the current definition of theescape_statearray wrong).What does this PR do?
It makes the time axis on the zarr dataset dense. Specificallu:
use_frame_numbers_from_file=True, to retain the frame numbers from the VIA tracks file (which for the crabs case, are 0-based clip indices)use_frame_numbers_from_file=Falsewould give the same result in this case.It also updates the script to generate output videos, so that the ds loaded from an input VIA tracks file has a dense axis that matches the frame in the video (it includes a check like the above to avoid silently dropping data out of range).
References
How has this PR been tested?
Past and added tests pass locally and in CI
Does this PR require an update to the documentation?
It includes an update to the guide to generate a zarr dataset from tracks (
guides/CreateZarrDatasetForTracks.md)Checklist: