ngff_zarr.to_ngff_zarr

Module Contents

Functions

_pop_metadata_optionals

_prep_for_to_zarr

_numpy_to_zarr_dtype

_write_with_tensorstore

Write array using tensorstore backend

_validate_ngff_parameters

Validate the parameters for the NGFF Zarr generation.

_prepare_metadata

Prepare and convert metadata to the proper version format.

_create_zarr_root

Create and configure the root Zarr group with proper attributes.

_configure_sharding

Configure sharding parameters if sharding is enabled.

_write_array_with_tensorstore

Write an array using the TensorStore backend.

_prepare_zarr_kwargs

Prepare zarr kwargs for dask.array.to_zarr.

_write_array_direct

Write an array directly using dask.array.to_zarr.

_handle_large_array_writing

Handle writing large arrays by splitting them into manageable pieces.

_compute_write_regions

Compute the regions for writing a large array in chunks.

_compute_plane_regions

Compute regions for a single z-slab, dividing into planes and strips if needed.

_prepare_next_scale

Prepare the next scale for processing if needed.

to_ngff_zarr

Write an image pixel array and metadata to a Zarr store with the OME-NGFF standard data model.

_to_ngff_zarr_impl

Internal implementation of to_ngff_zarr without .ozx handling.

Data

API

ngff_zarr.to_ngff_zarr.zarr_version

‘Version(…)’

ngff_zarr.to_ngff_zarr.IS_ZARR_V3_PLUS

None

ngff_zarr.to_ngff_zarr.DASK_SUPPORTS_SHARDING

None

ngff_zarr.to_ngff_zarr._pop_metadata_optionals(
metadata_dict,
enabled_rfcs: Optional[List[int]] = None,
)
ngff_zarr.to_ngff_zarr._prep_for_to_zarr(
store: ngff_zarr._zarr_types.StoreLike,
arr: dask.array.Array,
) dask.array.Array
ngff_zarr.to_ngff_zarr._numpy_to_zarr_dtype(dtype)
ngff_zarr.to_ngff_zarr._write_with_tensorstore(
store_path: str,
array,
region,
chunks,
zarr_format,
dimension_names=None,
internal_chunk_shape=None,
full_array_shape=None,
create_dataset=True,
compressor=None,
**kwargs,
) None

Write array using tensorstore backend

ngff_zarr.to_ngff_zarr._validate_ngff_parameters(
version: str,
chunks_per_shard: Optional[Union[int, Tuple[int, ...], Dict[str, int]]],
use_tensorstore: bool,
store: ngff_zarr._zarr_types.StoreLike,
) None

Validate the parameters for the NGFF Zarr generation.

ngff_zarr.to_ngff_zarr._prepare_metadata(
multiscales: ngff_zarr.multiscales.Multiscales,
version: str,
enabled_rfcs: Optional[List[int]] = None,
) Tuple[Union[ngff_zarr.v04.zarr_metadata.Metadata, ngff_zarr.v05.zarr_metadata.Metadata], Tuple[str, ...], Dict]

Prepare and convert metadata to the proper version format.

ngff_zarr.to_ngff_zarr._create_zarr_root(
store: ngff_zarr._zarr_types.StoreLike,
chunk_store: Optional[ngff_zarr._zarr_types.StoreLike],
version: str,
overwrite: bool,
metadata_dict: Dict,
) zarr.Group

Create and configure the root Zarr group with proper attributes.

ngff_zarr.to_ngff_zarr._configure_sharding(
arr: dask.array.Array,
chunks_per_shard: Optional[Union[int, Tuple[int, ...], Dict[str, int]]],
dims: Tuple[str, ...],
kwargs: Dict,
) Tuple[Dict, Optional[Tuple[int, ...]], dask.array.Array]

Configure sharding parameters if sharding is enabled.

ngff_zarr.to_ngff_zarr._write_array_with_tensorstore(
store_path: str,
path: str,
arr: dask.array.Array,
chunks: Union[Tuple[int, ...], List[int]],
shards: Optional[Tuple[int, ...]],
internal_chunk_shape: Optional[Tuple[int, ...]],
zarr_format: int,
dimension_names: Optional[Tuple[str, ...]],
region: Tuple[slice, ...],
full_array_shape: Optional[Tuple[int, ...]] = None,
create_dataset: bool = True,
**kwargs,
) None

Write an array using the TensorStore backend.

ngff_zarr.to_ngff_zarr._prepare_zarr_kwargs(to_zarr_kwargs: Dict)

Prepare zarr kwargs for dask.array.to_zarr.

This helper function ensures that correct kwargs are passed on based on which version of zarr and dask is being used. The different versions support different sets of arguments. The zarr_kwargs are adjusted in place and thus the original is overwritten. This is not a problem given that the arguments being adjusted are the same for the zarr store in use.

ngff_zarr.to_ngff_zarr._write_array_direct(
arr: dask.array.Array,
store: ngff_zarr._zarr_types.StoreLike,
path: str,
sharding_kwargs: Dict,
zarr_kwargs: Dict,
format_kwargs: Dict,
dimension_names_kwargs: Dict,
region: Optional[Tuple[slice, ...]] = None,
zarr_array=None,
**kwargs,
) None

Write an array directly using dask.array.to_zarr.

ngff_zarr.to_ngff_zarr._handle_large_array_writing(
image,
arr: dask.array.Array,
store: ngff_zarr._zarr_types.StoreLike,
path: str,
dims: Tuple[str, ...],
dim_factors: Dict[str, int],
chunks: Tuple[int, ...],
sharding_kwargs: Dict,
zarr_kwargs: Dict,
format_kwargs: Dict,
dimension_names_kwargs: Dict,
use_tensorstore: bool,
store_path: Optional[str],
zarr_format: int,
dimension_names: Tuple[str, ...],
internal_chunk_shape: Optional[Tuple[int, ...]],
shards: Optional[Tuple[int, ...]],
progress: Optional[Union[ngff_zarr.rich_dask_progress.NgffProgress, ngff_zarr.rich_dask_progress.NgffProgressCallback]],
index: int,
nscales: int,
**kwargs,
) None

Handle writing large arrays by splitting them into manageable pieces.

ngff_zarr.to_ngff_zarr._compute_write_regions(
image,
dims: Tuple[str, ...],
arr: dask.array.Array,
shape: Tuple[int, ...],
x_index: int,
y_index: int,
chunks: Tuple[int, ...],
shrink_factors: List[int],
) List[Tuple[slice, ...]]

Compute the regions for writing a large array in chunks.

ngff_zarr.to_ngff_zarr._compute_plane_regions(
image,
dims: Tuple[str, ...],
arr: dask.array.Array,
shape: Tuple[int, ...],
x_index: int,
y_index: int,
z_index: int,
chunks: Tuple[int, ...],
shrink_factors: List[int],
slab_index: int,
) List[Tuple[slice, ...]]

Compute regions for a single z-slab, dividing into planes and strips if needed.

ngff_zarr.to_ngff_zarr._prepare_next_scale(
image,
index: int,
nscales: int,
multiscales: ngff_zarr.multiscales.Multiscales,
store: ngff_zarr._zarr_types.StoreLike,
path: str,
progress: Optional[Union[ngff_zarr.rich_dask_progress.NgffProgress, ngff_zarr.rich_dask_progress.NgffProgressCallback]],
) Optional[object]

Prepare the next scale for processing if needed.

ngff_zarr.to_ngff_zarr.to_ngff_zarr(
store: ngff_zarr._zarr_types.StoreLike,
multiscales: ngff_zarr.multiscales.Multiscales,
version: str = '0.4',
overwrite: bool = True,
use_tensorstore: bool = False,
chunk_store: Optional[ngff_zarr._zarr_types.StoreLike] = None,
progress: Optional[Union[ngff_zarr.rich_dask_progress.NgffProgress, ngff_zarr.rich_dask_progress.NgffProgressCallback]] = None,
chunks_per_shard: Optional[Union[int, Tuple[int, ...], Dict[str, int]]] = None,
enabled_rfcs: Optional[List[int]] = None,
**kwargs,
) None

Write an image pixel array and metadata to a Zarr store with the OME-NGFF standard data model.

Parameters:
  • store (StoreLike) – Store or path to directory in file system. If the path ends with .ozx, writes an RFC-9 compliant zipped OME-Zarr file.

  • multiscales (Multiscales) – Multiscales OME-NGFF image pixel data and metadata. Can be generated with ngff_zarr.to_multiscales.

  • version (str, optional) – OME-Zarr specification version. For .ozx files, version 0.5 is required.

  • overwrite (bool, optional) – If True, delete any pre-existing data in store before creating groups.

  • use_tensorstore (bool, optional) – If True, write array using tensorstore backend.

  • chunk_store (StoreLike, optional) – Separate storage for chunks. If not provided, store will be used for storage of both chunks and metadata.

  • progress (RichDaskProgress) – Optional progress logger

  • chunks_per_shard (int, tuple, or dict, optional) – Number of chunks along each axis in a shard. If None, no sharding. For .ozx files, defaults to 2 if not specified. Requires OME-Zarr version >= 0.5.

  • enabled_rfcs (list of int, optional) – List of RFC numbers to enable. If RFC 4 is included, anatomical orientation metadata will be preserved in the output.

  • **kwargs – Passed to the zarr.create_array() or zarr.creation.create() function, e.g., compression options.

ngff_zarr.to_ngff_zarr._to_ngff_zarr_impl(
store: ngff_zarr._zarr_types.StoreLike,
multiscales: ngff_zarr.multiscales.Multiscales,
version: str = '0.4',
overwrite: bool = True,
use_tensorstore: bool = False,
chunk_store: Optional[ngff_zarr._zarr_types.StoreLike] = None,
progress: Optional[Union[ngff_zarr.rich_dask_progress.NgffProgress, ngff_zarr.rich_dask_progress.NgffProgressCallback]] = None,
chunks_per_shard: Optional[Union[int, Tuple[int, ...], Dict[str, int]]] = None,
enabled_rfcs: Optional[List[int]] = None,
**kwargs,
) None

Internal implementation of to_ngff_zarr without .ozx handling.