Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop color key #112

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
joshmoore marked this conversation as resolved.
Show resolved Hide resolved
Loading