Fix BDV N5 setup over-allocation#1207
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts BDV N5/HDF5 writer behavior to prevent creating an extra (unwritten) “position worth” of setup groups at the end of a completed acquisition by changing when dynamic setup expansion occurs in BigDataViewerDataSource.write().
Changes:
- Move dynamic setup expansion to occur immediately before a write that targets a new position.
- Remove the post-write expansion logic that ran after incrementing
_current_frame.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8de0d03 to
711f95e
Compare
711f95e to
597fd18
Compare
Move dynamic BDV N5 setup expansion ahead of the frame write so the writer only creates setup groups for positions that are actually receiving image data. The previous post-write check recomputed indices after _current_frame advanced; at the end of a complete acquisition that pointed at the next position and serialized an empty position worth of setup metadata. Use an append-friendly setup id mapping, position * channel_count + channel, for both HDF5/N5 dataset names and BDV XML metadata. This keeps existing setup ids stable when dynamic acquisitions grow from one position to more positions; otherwise c * positions + p changes when positions grows and can overwrite an existing channel/position setup. Keep the metadata position count in sync when dynamic growth occurs so the XML describes the extra positions that were actually written. Make the BDV data source tests deterministic by using explicit z/time dimensions, deterministic image and stage data, and deterministic stop-early behavior instead of random shape choices. Update the BDV metadata test expectation to the append-friendly setup ordering. Validation: - Verified fresh 2026-05-21 PR data in /Users/Dean/Desktop/pr1207/20260521_lung_mv3_488nm_562nm for both per-stack cell_001 and per-Z cell_002 acquisitions: each run has 4 N5 setups, 240 chunk files, 12 MIP files, and 12 XML view registrations. - Confirmed logs for both 2026-05-21 acquisitions received all 240 expected frames and wrote the final C=1, Z=19, T=2, P=1 frame. - Added a regression test for dynamic growth from one to two positions with two channels; it verifies setup data, N5 chunk creation, XML ViewSetup ids, and XML ViewRegistration setup ids. - Ran: uv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/data_sources/test_bdv_data_source.py::test_bdv_getitem -vv - Result: 24 passed in 36.89s. - Ran: uv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/data_sources/test_bdv_data_source.py - Result: 122 passed, 196 warnings in 130.29s. - Ran: uv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/metadata_sources/test_bdv_metadata.py::test_bdv_xml_dict -vv - Result: 2 passed in 2.56s. - Ran: uv run --python 3.9 --extra dev ruff check test/model/data_sources/test_bdv_data_source.py test/model/metadata_sources/test_bdv_metadata.py - Result: All checks passed.
597fd18 to
7eeeda5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1207 +/- ##
===========================================
+ Coverage 63.65% 64.41% +0.75%
===========================================
Files 189 190 +1
Lines 26029 26279 +250
===========================================
+ Hits 16569 16927 +358
+ Misses 9460 9352 -108
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
annie-xd-wang
approved these changes
May 27, 2026
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.
Motivation
setupgroups at the end of a complete acquisition because setup expansion was performed after advancing the frame index.c * positions + pchanges existing setup IDs whenpositionsgrows, which can overwrite an existing channel/position setup.Description
BigDataViewerDataSource.write()to happen before the write, and only when the current frame actually targets a new position (if pos >= self.positions: ...).position * channel_count + channel, for HDF5/N5 dataset names and BDV XML metadata.metadata.positionssynchronized when dynamic growth occurs so the XML includes positions that were actually written.Evidence from 2026-05-21 acquisitions
/Users/Dean/Desktop/pr1207/20260521_lung_mv3_488nm_562nm.cell_001(per_stack) has 4 N5 setups, 240 chunk files, 12 MIP files, and 12 XML view registrations.cell_002(per_z) has 4 N5 setups, 240 chunk files, 12 MIP files, and 12 XML view registrations.C=1, Z=19, T=2, P=1.Testing
uv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/data_sources/test_bdv_data_source.py::test_bdv_getitem -vvuv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/data_sources/test_bdv_data_source.pyuv run --python 3.9 --extra dev python -m pytest -p no:cov -o addopts= test/model/metadata_sources/test_bdv_metadata.py::test_bdv_xml_dict -vvuv run --python 3.9 --extra dev ruff check test/model/data_sources/test_bdv_data_source.py test/model/metadata_sources/test_bdv_metadata.pyCodex Task