Skip to content

Commit

Permalink
Merge pull request #112 from will-moore/drop_color_key
Browse files Browse the repository at this point in the history
Drop color key
  • Loading branch information
joshmoore authored Jul 15, 2024
2 parents 51e940a + 60e39d0 commit 4574e13
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
20 changes: 18 additions & 2 deletions napari_ome_zarr/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions napari_ome_zarr/_tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4574e13

Please sign in to comment.