IO (sphero_vem.io)#
Zarr and TIFF I/O with OME-NGFF metadata tracking.
Module containing input/output functions
- sphero_vem.io.write_image(fname, image, compressed=False, **kwargs)[source]#
Save a NumPy array as a TIFF file, optionally with zlib compression.
- Parameters:
fname (Path) – Destination file path.
image (numpy.ndarray) – Image array to save.
compressed (bool, optional) – If True, apply zlib compression (level 6) with tiling. Extra keyword arguments are ignored when compression is enabled. Default is False.
**kwargs – Additional keyword arguments forwarded to
tifffile.imwritewhen compressed is False.
- Return type:
- sphero_vem.io.stack_to_zarr(stack_dir, root_path, spacing, chunk_size=(1, 1024, 1024), verbose=True)[source]#
Convert a tiff stack to a ZYX zarr archive.
The stack will be saved under root/images/spacing_dir
- Parameters:
stack_path (Path) – Path to the tiff stack. This should be a directory with single tif slices that will be concatened along the Z axis.
dest_path (Path) – Path the root of the destination zarr store.
spacing (tuple[int, int, int] | None) – ZYX spacing of the dataset in nanometers. If None, attempt to read the spacing from metadata (Currently not implemented).
chunk_size (tuple[int, int, int] | None) – ZYX chunk size of the zarr array. If None, use (1, H, W).
verbose (bool) – Enable verbose output.
stack_dir (Path)
root_path (Path)
- Raises:
NotImplementedError – When passing None to spacing.
- Return type:
- sphero_vem.io.write_zarr(root, array, dst_path, src_zarr=None, spacing=None, dtype=None, shape=None, processing=None, inputs=None, zarr_chunks=None)[source]#
Write a numpy or dask array to zarr with metadata.
- Parameters:
root (zarr.Group | Path | str) – Root zarr group, or path to one.
array (np.ndarray | da.Array) – Array to save. Axis order should be (CZ)YX.
dst_path (str) – Path under root where to save the array.
src_zarr (zarr.Array | None) – Source zarr array. Used to read spacing, chunks, previous processing, and inputs if not explicitly provided. Default is None.
spacing (tuple[int | float, ...] | None) – Spacing of the array. If None, reads from src_zarr. Default is None.
dtype (Any | None) – dtype to cast to when saving. If None, uses array dtype. Default is None.
shape (tuple[int, ...] | None) – Zarr array shape. If None, uses array shape. Default is None.
processing (ProcessingStep | list[ProcessingStep] | list[dict] | dict | None) – Processing steps to append to src_zarr processing history. Default is None.
inputs (list[str] | None) – Paths to input arrays. If None, uses src_zarr path. Default is None.
zarr_chunks (tuple[int, ...] | None) – Chunk shape. If None, reads from src_zarr. Default is None.
- Raises:
ValueError – If zarr_chunks is None and src_zarr is None.
ValueError – If spacing is None and src_zarr is None or has no spacing attribute.
TypeError – If array is neither a numpy nor a dask array.
- Return type: