From bbf9bc7856722b2ed0265d19e70e75448d7a730b Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Fri, 5 Jul 2024 12:44:13 -0400 Subject: [PATCH 1/4] drop color key and use colormap for labels --- napari_ome_zarr/_reader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py index 8259e94..1d24e34 100644 --- a/napari_ome_zarr/_reader.py +++ b/napari_ome_zarr/_reader.py @@ -17,7 +17,7 @@ LOGGER = logging.getLogger("napari_ome_zarr.reader") # NB: color for labels, colormap for images -METADATA_KEYS = ("name", "visible", "contrast_limits", "colormap", "color", "metadata") +METADATA_KEYS = ("name", "visible", "contrast_limits", "colormap", "metadata") def napari_get_reader(path: PathLike) -> Optional[ReaderFunction]: @@ -128,6 +128,8 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: for x in METADATA_KEYS: if x in node.metadata: metadata[x] = node.metadata[x] + elif x == "colormap" and node.metadata["color"]: + metadata[x] = node.metadata["color"] if channel_axis is not None: data = [ np.squeeze(level, axis=channel_axis) for level in node.data From 003b7beed8cc9d0147d60e12367c612fc5f7f7bc Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 11 Jul 2024 13:50:04 +0100 Subject: [PATCH 2/4] Check napari version to use color or colormap for labels --- napari_ome_zarr/_reader.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py index 1d24e34..17001c6 100644 --- a/napari_ome_zarr/_reader.py +++ b/napari_ome_zarr/_reader.py @@ -6,6 +6,7 @@ import logging import warnings +from importlib.metadata import version from typing import Any, Dict, Iterator, List, Optional import numpy as np @@ -16,9 +17,11 @@ LOGGER = logging.getLogger("napari_ome_zarr.reader") -# NB: color for labels, colormap for images METADATA_KEYS = ("name", "visible", "contrast_limits", "colormap", "metadata") +# major and minor versions as int +napari_version = tuple(map(int, list(version("napari").split(".")[:2]))) + def napari_get_reader(path: PathLike) -> Optional[ReaderFunction]: """Returns a reader for supported paths that include IDR ID. @@ -129,7 +132,11 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: if x in node.metadata: metadata[x] = node.metadata[x] elif x == "colormap" and node.metadata["color"]: - metadata[x] = node.metadata["color"] + # key changed 'color' -> 'colormap' in napari 0.5 + if napari_version >= (0, 5): + metadata["colormap"] = node.metadata["color"] + else: + metadata["color"] = node.metadata["color"] if channel_axis is not None: data = [ np.squeeze(level, axis=channel_axis) for level in node.data From f604ed89ae45badc41b4a09efea8c1e7999ed689 Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 11 Jul 2024 15:00:43 +0100 Subject: [PATCH 3/4] Fix name metadata from channel_names See https://github.com/ome/ome-zarr-py/commit/cae02c8198deb3a7575c33b04c6399d977293bb0 --- napari_ome_zarr/_reader.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py index 17001c6..295dc43 100644 --- a/napari_ome_zarr/_reader.py +++ b/napari_ome_zarr/_reader.py @@ -154,6 +154,9 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: for x in METADATA_KEYS: if x in node.metadata: metadata[x] = node.metadata[x] + # overwrite 'name' if we have 'channel_names' + if "channel_names" in node.metadata: + metadata["name"] = node.metadata["channel_names"] else: # single channel image, so metadata just needs # single items (not lists) @@ -163,6 +166,10 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: metadata[x] = node.metadata[x][0] except Exception: pass + # overwrite 'name' if we have 'channel_names' + if "channel_names" in node.metadata: + if len(node.metadata["channel_names"]) > 0: + metadata["name"] = node.metadata["channel_names"][0] properties = transform_properties(node.metadata.get("properties")) if properties is not None: From 60e39d0d44a633097e1d96e27a5028fd06f35776 Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 11 Jul 2024 15:16:45 +0100 Subject: [PATCH 4/4] Handle test failure of viewer.window.qt_viewer.on_draw(None) --- napari_ome_zarr/_tests/test_reader.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/napari_ome_zarr/_tests/test_reader.py b/napari_ome_zarr/_tests/test_reader.py index 4c2d957..145e904 100644 --- a/napari_ome_zarr/_tests/test_reader.py +++ b/napari_ome_zarr/_tests/test_reader.py @@ -106,8 +106,13 @@ def test_viewer(self, make_napari_viewer): # Set canvas size to target amount viewer.window.qt_viewer.view.canvas.size = (800, 600) - viewer.window.qt_viewer.on_draw(None) - - # Check that current level is first large enough to fill the canvas with - # a greater than one pixel depth - assert layer.data_level == 2 + # FutureWarning: Public access to Window.qt_viewer is deprecated + # and will be removed in v0.6.0 + try: + viewer.window.qt_viewer.on_draw(None) + + # Check that current level is first large enough to fill the canvas with + # a greater than one pixel depth + assert layer.data_level == 2 + except AttributeError: + pass