Skip to content

Feature: stitch mosaic readers when planning and writing OME-Zarr - #78

Merged
BrianWhitneyAI merged 8 commits into
mainfrom
feature/reader-kwargs-passthrough
Dec 2, 2026
Merged

BrianWhitneyAI merged 8 commits into
mainfrom
feature/reader-kwargs-passthrough

Conversation

@BrianWhitneyAI

@BrianWhitneyAI BrianWhitneyAI commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A mosaic reader (e.g. ImageXpress LIF, tiled CZI) reports a scene as M tiles that only BioImage resolves by stitching them into one image. The converter planned against reader.dims, so it saw the M dimension and either wrote a 6D store of unstitched tiles or failed on the unknown axis (KeyError: 'm' for a tiled CZI).

  • Detect mosaic readers (M in reader.dims.order) and take the planning axes from BioImage for those readers only: BioImage pads any other reader's axes out to a full TCZYX, which would add singleton axes the source does not have. Non-mosaic sources keep the existing reader fast path unchanged.
  • Shard workers read mosaic scenes with BioImage.get_image_dask_data(native_order, **region). This stays lazy, so a shard costs only the tiles and planes it overlaps (get_image_data has no sub-region read for a stitched mosaic and would materialize the whole scene per shard). Selecting by axis name also covers readers whose stitched axes BioImage pads out to TCZYX (e.g. a CMYX CZI stitches to CYX but is planned as TCZYX).

Resolves #91
Resolves #99

🤖 Generated with Claude Code

A mosaic reader (ImageXpress) reports a scene as M tiles that only BioImage
resolves, by stitching them into one image. The converter planned against
`reader.dims`, so it saw the M and wrote a 6D store of unstitched tiles.

Take the axes from BioImage for those readers only: BioImage pads any other
reader's axes out to a full TCZYX, which would add singleton axes the source
does not have. Shard workers slice `mosaic_xarray_dask_data` lazily rather than
going through `get_image_data`, which has no sub-region read for a stitched
mosaic and would materialize the whole scene per shard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BrianWhitneyAI
BrianWhitneyAI force-pushed the feature/reader-kwargs-passthrough branch from f456ae0 to ee2042d Compare August 19, 2026 23:09
@BrianWhitneyAI BrianWhitneyAI changed the title Stitch mosaic readers, and pass reader options to the pixel readers Stitch mosaic readers when planning and writing OME-Zarr Aug 19, 2026
Add tiled.lif from bioio-lif's test resources (git LFS, matching the
existing *.nd2 pattern): its reader reports MTCZYX (165 tiles of 512x512)
that BioImage stitches to 5622x7666, making it the only test dependency
whose reader exposes an M dim with default reader options. The new test
converts it across multiple shards and checks the store carries BioImage's
stitched shape and pixels exactly. Adds bioio-lif to the test extra.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
BrianWhitneyAI and others added 4 commits December 2, 2026 11:48
Resolve conflicts between mosaic stitching and channel_order. The
stitched-mosaic shard read now applies channel_order, and a test covers it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The mosaic shard read sliced the stitched array by position, which failed
when BioImage pads the reader's axes (e.g. a CMYX CZI stitches to CYX but is
planned as TCZYX). Select by axis name via get_image_dask_data instead, and
add CZI mosaic tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge the LIF and CZI mosaic tests into one parametrized test and drop the
mosaic channel_order test, which only exercised bioio's selection.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
bio.reader.get_image_data(native_order, **region_kwargs), dtype=out_dtype
)
if DimensionNames.MosaicTile in bio.reader.dims.order:
# A stitched mosaic has no sub-region read: BioImage.get_image_data

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to make this better in the future but thats a larger change across many repos

@BrianWhitneyAI
BrianWhitneyAI marked this pull request as ready for review December 2, 2026 20:04
shard_data = np.asarray(
bio.reader.get_image_data(native_order, **region_kwargs), dtype=out_dtype
)
if DimensionNames.MosaicTile in bio.reader.dims.order:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could reuse is_mosaic property

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.bioimage.set_scene(scene_index)
r = self.bioimage.reader
order = r.dims.order.upper()
dims = self._pixel_source().dims

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barring the comment below this - Is this the only purpose of pixel_source? If so, it seems less complex IMO to make a "native_dims" property

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._write_fallback(
writer, r, native_order, t_ax, level0_shape, channel_order
writer,
self._pixel_source(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pixel_source here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for It was for the fallback's get_image_dask_data read but we can get away with just self.bioimage

BrianWhitneyAI and others added 2 commits December 2, 2026 13:39
A fork inherits the parent's thread state and deadlocked the LIF mosaic test
on Linux (Python 3.11-3.13) when a zarr v2 fallback conversion ran earlier
in the same process.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e_dims

Address review: the worker no longer re-detects mosaics, _pixel_source is now a
_native_dims property, and the fallback write reads through BioImage. Shorten
the spawn comment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
pool = ProcessPoolExecutor(max_workers=self._n_workers)
# A single process pool spans *all* scenes. Spawn instead of fork, which
# can deadlock on thread state inherited from the parent.
pool = ProcessPoolExecutor(

@BrianWhitneyAI BrianWhitneyAI Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing our linux tests to stall so is technically unrelated but still needed for our tests to pass

@BrianWhitneyAI BrianWhitneyAI changed the title Stitch mosaic readers when planning and writing OME-Zarr Feature: stitch mosaic readers when planning and writing OME-Zarr Dec 2, 2026
@BrianWhitneyAI
BrianWhitneyAI merged commit e8bcfa9 into main Dec 2, 2026
19 checks passed
@BrianWhitneyAI
BrianWhitneyAI deleted the feature/reader-kwargs-passthrough branch December 2, 2026 22:08
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.

Feature Request: support CZI mosaic tile (M) axis in OME-Zarr conversion Feature Request: Stitch mosaic readers when planning and writing OME-Zarr

3 participants