diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py index 8259e94..295dc43 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,8 +17,10 @@ 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") + +# major and minor versions as int +napari_version = tuple(map(int, list(version("napari").split(".")[:2]))) def napari_get_reader(path: PathLike) -> Optional[ReaderFunction]: @@ -128,6 +131,12 @@ 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"]: + # 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 @@ -145,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) @@ -154,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: 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