Skip to content

Commit

Permalink
keep the old way for napari <0.4.19
Browse files Browse the repository at this point in the history
  • Loading branch information
psobolewskiPhD committed Feb 5, 2025
1 parent 4f10b8b commit 68a3468
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/napari_omero/plugins/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dask.delayed import delayed
from napari.types import LayerData
from napari.utils.colormaps import ensure_colormap

Check warning on line 6 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L6

Added line #L6 was not covered by tests
from vispy.color import Colormap

from napari_omero.utils import PIXEL_TYPES, lookup_obj, parse_omero_url, timer
from napari_omero.widgets import QGateWay
Expand Down Expand Up @@ -78,16 +79,24 @@ def get_omero_metadata(image: ImageWrapper) -> dict:
colors = []
for ch in channels:
# use current rendering settings from OMERO
color = ch.getColor().getHtml()
# work around a napari bug https://github.com/napari/napari/issues/7504
if color == "000000":
color = ch.getColor()

Check warning on line 82 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L82

Added line #L82 was not covered by tests
# ensure white and black always work properly
# even for napari <0.4.19
if color.getHtml() == "000000":
colors.append(ensure_colormap("gray_r"))
if color == "FFFFFF":
if color.getHtml() == "FFFFFF":
colors.append(ensure_colormap("gray"))

Check warning on line 88 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L85-L88

Added lines #L85 - L88 were not covered by tests
else:
# if the colormap exists in napari, use it
# otherwise, create a custom colormap
colors.append(ensure_colormap("#" + color))
try:

Check warning on line 90 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L90

Added line #L90 was not covered by tests
# requires 0.4.19 or later
# if the colormap exists in napari, use it
# otherwise, create a custom napari colormap
colors.append(ensure_colormap("#" + color.getHtml()))
except KeyError:

Check warning on line 95 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L94-L95

Added lines #L94 - L95 were not covered by tests
# on napari <0.4.19 use vispy colormap
color = color.getRGB()
color = [r / 256 for r in color]
colors.append(Colormap([[0, 0, 0], color]))

Check warning on line 99 in src/napari_omero/plugins/loaders.py

View check run for this annotation

Codecov / codecov/patch

src/napari_omero/plugins/loaders.py#L97-L99

Added lines #L97 - L99 were not covered by tests

contrast_limits = [[ch.getWindowStart(), ch.getWindowEnd()] for ch in channels]

Expand Down

0 comments on commit 68a3468

Please sign in to comment.