zarrsmith.utils.visualize

Functions

_parse_color(color) → tuple[float, float, float]

Convert an OME int, hex string or color name to an RGB float tuple for napari.

_axis_scale(metadata, axes, level, *, drop_channel) → tuple[float, ...]

units_for_axes(metadata, requested)

Per-axis units for napari layers covering the axes requested, or None.

_axis_units(metadata, axes, *, drop_channel)

Units of the axes shown by an image/label layer (channel axis optionally removed).

_set_axis_labels(viewer, axes, *, drop_channel) → None

visualize(data_levels, metadata[, start_level, ...]) → napari.Viewer | None

Visualize an axis-aware multiscale dataset with napari.

channel_names(metadata, n) → list[str]

Names of the n channels of a dataset (ch_0, ch_1, ... when not in its metadata).

layer_geometry(metadata, axes[, level]) → Dict[str, Any]

scale (and units, when known) of a napari layer showing level of a dataset.

add_layers(viewer, data_levels, metadata, *[, level, name]) → list

Add a dataset to viewer and return its layers: one labels layer for label data, else one

Module Contents

zarrsmith.utils.visualize._parse_color(color: int | str) → tuple[float, float, float][source]

Convert an OME int, hex string or color name to an RGB float tuple for napari.

zarrsmith.utils.visualize._axis_scale(metadata: Dict[str, Any], axes: tuple[str, ...], level: int, *, drop_channel: bool) → tuple[float, ...][source]
zarrsmith.utils.visualize.units_for_axes(metadata: Dict[str, Any], requested: Iterable[str])[source]

Per-axis units for napari layers covering the axes requested, or None.

Layers added without units default to pixel. napari then disables units for rendering (“Inconsistent units across layers”) as soon as it also holds layers with physical units. Every layer that ZarrSmith adds, image or helper (ROI, Z range…), therefore takes its units from here so they all agree with each other and with a converted zarr opened by napari-ome-zarr.

None is returned (so the caller omits units) when napari has no layer units or a unit cannot be parsed.

zarrsmith.utils.visualize._axis_units(metadata: Dict[str, Any], axes: tuple[str, ...], *, drop_channel: bool)[source]

Units of the axes shown by an image/label layer (channel axis optionally removed).

zarrsmith.utils.visualize._set_axis_labels(viewer, axes: tuple[str, ...], *, drop_channel: bool) → None[source]
zarrsmith.utils.visualize.visualize(data_levels: List[dask.array.Array], metadata: Dict[str, Any], start_level: int = 0, stop_level: int = -1, in_memory: bool = False, viewer: napari.Viewer | None = None) → napari.Viewer | None[source]

Visualize an axis-aware multiscale dataset with napari.

Datasets without a t axis are passed to napari without an artificial time dimension, so napari will not expose an active T slider. Datasets without a c axis are displayed as a single image/label layer rather than channel layers.

zarrsmith.utils.visualize.channel_names(metadata: Dict[str, Any], n: int) → list[str][source]

Names of the n channels of a dataset (ch_0, ch_1, … when not in its metadata).

zarrsmith.utils.visualize.layer_geometry(metadata: Dict[str, Any], axes, level: int = 0, *, drop_channel: bool) → Dict[str, Any][source]

scale (and units, when known) of a napari layer showing level of a dataset.

zarrsmith.utils.visualize.add_layers(viewer, data_levels: List[Any], metadata: Dict[str, Any], *, level: int = 0, name: str | None = None, **kwargs) → list[source]

Add a dataset to viewer and return its layers: one labels layer for label data, else one image layer per channel (named "<name>: <channel>" when name is given).

data_levels are the levels shown (level: the first one’s index in the dataset). The colours are the channel colours of the metadata (gray without them); kwargs go to napari and replace any of these settings (e.g. contrast_limits, blending, colormap).