ngff_zarr.to_multiscalesΒΆ

Module ContentsΒΆ

FunctionsΒΆ

_ngff_image_scale_factors

_find_optimal_chunk_size

Target the requested chunk size, clamped to the axis length.

_large_image_serialization

_cache_2d_strips

Cache large 2D images in strips along the larger spatial dimension.

_cache_1d_segments

Cache large 1D images in segments along x.

to_multiscales

Generate multiple resolution scales for the OME-NGFF standard data model.

APIΒΆ

ngff_zarr.to_multiscales._ngff_image_scale_factors(ngff_image, min_length, out_chunks)ΒΆ
ngff_zarr.to_multiscales._find_optimal_chunk_size(first_chunk, dim_size)ΒΆ

Target the requested chunk size, clamped to the axis length.

Zarr v3 permits a partial final chunk, so the cache chunk size need not divide the dimension evenly (region slabs are chunk-aligned and the final slab is truncated to the axis, so a partial final chunk is safe). Do not snap to an axis divisor: for dimensions with large prime factors the nearest divisor collapses to a tiny chunk (e.g. 320095 = 5 * 64019 -> 5).

ngff_zarr.to_multiscales._large_image_serialization(
image: ngff_zarr.ngff_image.NgffImage,
progress: ngff_zarr.rich_dask_progress.NgffProgress | ngff_zarr.rich_dask_progress.NgffProgressCallback | None,
)ΒΆ
ngff_zarr.to_multiscales._cache_2d_strips(data, dims, rechunks, cache_store, base_path, progress)ΒΆ

Cache large 2D images in strips along the larger spatial dimension.

This avoids constructing a massive dask rechunk graph for the full image by processing manageable strips and writing them incrementally to disk.

ngff_zarr.to_multiscales._cache_1d_segments(data, dims, rechunks, cache_store, base_path, progress)ΒΆ

Cache large 1D images in segments along x.

Handles the edge case of 1D data (only x dimension, possibly with c/t).

ngff_zarr.to_multiscales.to_multiscales(
data: ngff_zarr.ngff_image.NgffImage | numpy.typing.ArrayLike | collections.abc.MutableMapping | str | zarr.core.Array,
scale_factors: int | collections.abc.Sequence[dict[str, int] | int] = 128,
method: ngff_zarr.methods.Methods | None = None,
chunks: int | tuple[int, ...] | tuple[tuple[int, ...], ...] | collections.abc.Mapping[Any, None | int | tuple[int, ...]] | None = None,
progress: ngff_zarr.rich_dask_progress.NgffProgress | ngff_zarr.rich_dask_progress.NgffProgressCallback | None = None,
cache: bool | None = None,
orientation: str | collections.abc.Mapping[str, ngff_zarr.rfc4.AnatomicalOrientation] | None = None,
) ngff_zarr.multiscales.NgffMultiscalesΒΆ

Generate multiple resolution scales for the OME-NGFF standard data model.

Parameters:
  • data (NgffImage, ArrayLike, ZarrArray, MutableMapping, str) – Multi-dimensional array that provides the image pixel values, or image pixel values + image metadata when an NgffImage.

  • scale_factors (int of minimum length, int per scale or dict of spatial dimension int's per scale) – If a single integer, scale factors in spatial dimensions will be increased by a factor of two until this minimum length is reached. If a list, integer scale factors to apply uniformly across all spatial dimensions or along individual spatial dimensions. Examples: 64 or [2, 4] or [{β€˜x’: 2, β€˜y’: 4 }, {β€˜x’: 5, β€˜y’: 10}] Scaling is constrained by size of chunks - we do not scale below the chunk size.

  • method (Methods, optional) – Specify the anti-aliasing method used to downsample the image. Default is ITKWASM_GAUSSIAN. See the Methods enum for all available options.

  • chunks (Dask array chunking specification, optional) – Specify the chunking used in each output scale. The default is 128 for 3D images and 256 for 2D images.

  • cache (bool, optional) – Cache intermediate results to disk to limit memory consumption. If None, the default, determine based on ngff_zarr.config.memory_target.

  • progress (NgffProgress, NgffProgressCallback) – Optional progress logger

  • orientation (str or mapping of str to AnatomicalOrientation, optional) – Anatomical orientation (RFC 4) for the spatial axes. Either a preset coordinate-system name ("LPS" or "RAS", case-insensitive) or a mapping of axis name to :class:AnatomicalOrientation. When provided, it takes precedence over any axes_orientations on the input image. Anatomical orientation is written to the output automatically whenever it is present; no separate opt-in is required.

Returns:

NgffImage for each resolution and NGFF multiscales metadata. Axes are normalized to the OME-Zarr specification order – time, then channel, then space (t, c, z, y, x) – with a lazy transpose when the input image orders them differently.

Rtype :

NgffMultiscales