Skip to content

fix(writers): let continued and extended runs grow the OME-Zarr time axis - #26

Open
hinderling wants to merge 2 commits into
pertzlab:mainfrom
hinderling:fix/omezarr-continue
Open

fix(writers): let continued and extended runs grow the OME-Zarr time axis#26
hinderling wants to merge 2 commits into
pertzlab:mainfrom
hinderling:fix/omezarr-continue

Conversation

@hinderling

@hinderling hinderling commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Problem

A single-position OME-Zarr run cannot be continued or extended. The ome-writers stream was created with a fixed time count taken from the first run's events, so every frame appended by continue_experiment or extend_experiment failed inside the writer with

IndexError: Cannot append frame: would exceed total of N frames. Check your AcquisitionSettings.dimensions. If you need to write an unbounded number of frames, set the count of your first dimension to None.

and was only logged as a background error, so the run reported success while the continued frames were missing from the store. This has been the case since the OME-Zarr writers were added (2026-04-02); continue_experiment predates them.

Fix

  • OmeZarrWriter: single-position runs now build the raw array directly with zarr-python, the same path multi-position runs already use. The ome-writers stream is gone from the base class. Rationale: a bounded stream cannot grow, and an unbounded one (ome-writers ≤ 0.3.2) grows by exactly one timepoint per frame, rewriting 0/zarr.json on every write — the slow, crash-fragile pattern on SMB shares the direct path was built to avoid. The direct path pre-sizes to n_timepoints, grows once per appended batch, and trims to the written length on close.
  • On-disk layout is unchanged: root array 0, axes (t, c, y, x), same multiscales/omero metadata. The array now also carries dimension_names, as the stream did.
  • Controller: continue_experiment and extend_experiment call the writer's set_n_timepoints, so the time axis is resized once per batch instead of per frame. set_n_timepoints takes the label lock, matching _maybe_resize_leading.
  • Tests: TestContinueExperimentOmeZarr covers continue and extend end to end on a single position; TestOmeZarrContinuePastDeclared (writer level, 1 and 2 positions) continues past the declared length and asserts the array metadata is not rewritten by the appended frames.

Not in this PR

  • OmeZarrWriterPlate still streams raw frames through a bounded ome-writers stream and cannot be continued or extended (same IndexError). Left untouched on purpose; the set_n_timepoints docstring says so. Whether to fix it, move plate layout to an export/viewer step, or retire it is a separate decision.

Notes

The examples PR #27 (feat/examples) has a demo that continues a run and depends on this; merge this one first. Writer and continue tests pass locally (Motile-parametrized cases deselected; the venv still has motile 0.4, the code needs ≥1.0). A real single-FOV run on the scope is the confirmation that matters.

…axis

The single-position ome-writers stream was created with a fixed time
count taken from the first run, so every frame appended by
continue_experiment or extend_experiment failed with "Cannot append
frame: would exceed total of N frames" and was only logged as a
background error. The stream now declares an unbounded time axis
(ome-writers grows it with amortised resizes and closes at the exact
written length), and the controller calls the writer's existing but
uncalled set_n_timepoints on continue/extend so the multi-position
path pre-sizes once. Regression test continues a single-position
OME-Zarr run and checks the store.

Claude-Session: https://claude.ai/code/session_01CSrNm4WLiNzDkiCi75vZfy
…can grow

Route the single-position OmeZarrWriter through the same direct zarr-python
path as multi-position runs instead of an ome-writers stream. The stream
could not be continued: a bounded time axis refuses appends past the
declared count, and an unbounded one (ome-writers <= 0.3.2) grows by one
timepoint per frame, rewriting the array's zarr.json on every write, which
is the slow, crash-fragile pattern on SMB shares the direct path was built
to avoid. The direct path pre-sizes to n_timepoints, grows once per
continued/extended batch via set_n_timepoints, and trims to the written
length on close. On-disk layout is unchanged ((t, c, y, x) at root "0");
the array now also carries dimension_names as the stream did.

set_n_timepoints takes the label lock, matching _maybe_resize_leading.
OmeZarrWriterPlate is untouched and still cannot be continued.

Tests: writer-level continue past the declared length for one and two
positions, asserting no per-frame metadata rewrite; extend_experiment
variant of the single-position integration test.
@hinderling
hinderling marked this pull request as ready for review September 9, 2026 13:50
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.

1 participant