pymif.microscope_manager.zarr_manager

Classes

ZarrDataset

All the operations on a read-only sequence.

AttrDict

Dictionary with optional attribute access for valid Python names.

ZarrManager

A manager class for reading and handling OME-Zarr datasets.

Module Contents

class pymif.microscope_manager.zarr_manager.ZarrDataset[source]

Bases: collections.abc.Sequence

All the operations on a read-only sequence.

Concrete subclasses must override __new__ or __init__, __getitem__, and __len__.

data: List[dask.array.Array][source]
zarr_data: List[Any] | None[source]
metadata: Dict[str, Any][source]
name: str | None = None[source]
path: str | None = None[source]
__len__()[source]
__getitem__(item)[source]
__iter__() collections.abc.Iterator[dask.array.Array][source]
__repr__()[source]
class pymif.microscope_manager.zarr_manager.AttrDict[source]

Bases: dict

Dictionary with optional attribute access for valid Python names.

__getattr__(name)[source]
class pymif.microscope_manager.zarr_manager.ZarrManager(path, chunks: Tuple[int, Ellipsis] = None, mode: str = 'r', metadata: dict[str, Any] = None, ngff_version: str | None = None, zarr_format: int | None = None)[source]

Bases: pymif.microscope_manager.microscope_manager.MicroscopeManager

A manager class for reading and handling OME-Zarr datasets.

Supports both: - NGFF / OME-Zarr v0.4 -> metadata in root/group attrs directly - NGFF / OME-Zarr v0.5 -> metadata in attrs[“ome”]

path[source]
chunks = None[source]
mode = 'r'[source]
metadata = None[source]
ngff_version: str | None = None[source]
ngff_version_override = None[source]
zarr_format_override = None[source]
_get_image_meta(group: zarr.Group) dict[str, Any][source]

Return the image metadata dictionary for either NGFF v0.4 or v0.5.

v0.5 -> group.attrs[“ome”] v0.4 -> group.attrs

_get_multiscales(group: zarr.Group) list[dict[str, Any]][source]

Return the NGFF multiscales block for group regardless of version.

_get_omero(group: zarr.Group) dict[str, Any][source]

Return the OMERO-style channel metadata stored on group.

_extract_metadata(data_levels: List[dask.array.Array], datasets: list[dict[str, Any]], multiscales: dict[str, Any], omero: dict[str, Any], data_type: str = 'intensity') Dict[str, Any][source]

Translate NGFF metadata blocks into the normalized PyMIF schema.

The normalized schema is axis-aware: axes may be any unique combination of t, c, z, y and x. Spatial scales and units are stored in the same order as the spatial axes appear in axes.

_read_multiscale_group(group: zarr.Group) tuple[List[dask.array.Array], List[Any], Dict[str, Any]][source]

Load one multiscale image group as dask arrays plus normalized metadata.

read() Tuple[List[dask.array.Array], Dict[str, Any]][source]

Read the root image plus discover additional image groups and labels.

The root image is exposed through self.data and self.metadata. Additional multiscale subgroups are indexed in self.groups and label pyramids in self.labels.

_sync_raw_aliases() None[source]

Keep the old single-dataset API synchronized with the raw dataset.

This preserves:

d.data d.metadata d.zarr_data

as aliases to:

d.raw.data d.raw.metadata d.raw.zarr_data

_iter_datasets(include_raw: bool = True, include_groups: bool = True, include_labels: bool = True)[source]

Iterate over all datasets managed by ZarrManager.

This is ZarrManager-specific because only ZarrManager knows about raw/groups/labels.

_invalidate_zarr_data(dataset: ZarrDataset) None[source]

After lazy in-memory transformations, dataset.data no longer necessarily corresponds one-to-one to the original on-disk Zarr arrays.

_load_group(name)[source]
_load_labels()[source]
visualize_zarr(viewer: napari.Viewer | None = None) napari.Viewer | None[source]

Open the root image and all multiscale subgroups in napari.

create_empty_group(group_name: str, metadata: Dict[str, Any], is_label: bool = False, data_type: str | None = None)[source]

Create an empty image subgroup or label subgroup and update this manager.

metadata['axes'] may be any unique subset of tczyx. Use data_type='label' or is_label=True for label data.

write_image_region(data, t: int | slice = slice(None), c: int | slice = slice(None), z: int | slice = slice(None), y: int | slice = slice(None), x: int | slice = slice(None), level: int = 0, group: str | None = None, downscale_factor: int | collections.abc.Sequence[int] | None = None)[source]

Write an image patch into a root or subgroup pyramid and refresh lower levels.

write_label_region(data, t: int | slice = slice(None), z: int | slice = slice(None), y: int | slice = slice(None), x: int | slice = slice(None), level: int = 0, group: str = None, downscale_factor: int | collections.abc.Sequence[int] | None = None)[source]

Write a label patch into a label pyramid and regenerate coarser levels.

subset_dataset(T=None, C=None, Z=None, Y=None, X=None, include_groups: bool = True, include_labels: bool = True, rebuild_pyramid=False)[source]

Subset raw, groups, and labels.

Channel subsetting is skipped automatically for datasets without a channel axis, such as most label datasets.

build_pyramid(num_levels: int | None = 3, downscale_factor: int | collections.abc.Sequence[int] | None = 2, start_level: int = 0, include_groups: bool = True, include_labels: bool = True)[source]

Build/rebuild pyramids for raw, groups, and labels.

reorder_channels(new_order: List[int], include_groups: bool = True)[source]

Reorder channels in raw and non-label image groups.

Labels are skipped because they usually do not have a channel axis.

update_metadata(updates: Dict[str, Any], include_groups: bool = True, include_labels: bool = True)[source]

Update metadata for raw, groups, and labels.

Channel-specific metadata is skipped for datasets without a channel axis.

to_zarr(path: str | pathlib.Path, include_groups: bool = True, include_labels: bool = True, reread: bool = True, **kwargs)[source]

Write raw data, groups, and labels to a complete OME-Zarr store.

Raw data is written directly to the root group. Image groups are written as root-level subgroups. Labels are written under /labels.