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

Dependency cleanup & new colormap updating #40

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/test_and_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', '3.10']
python-version: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
Expand Down
22 changes: 20 additions & 2 deletions src/napari_feature_classifier/annotator_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import partial
from pathlib import Path
from typing import Optional, Sequence, cast
from napari.utils.colormaps import DirectLabelColormap

# pylint: disable=R0801
import napari
Expand Down Expand Up @@ -313,9 +314,26 @@ def update_single_color(self, label_layer, label):
)
/ len(self.cmap.colors)
)
self._annotations_layer.color[label] = color
colordict = self._annotations_layer.colormap.color_dict
colordict[label] = color
self._annotations_layer.colormap = DirectLabelColormap(color_dict=colordict)

# self._annotations_layer.colormap.color_dict[label] = \
# np.array(color, dtype=np.float32)
# self._annotations_layer.refresh()
# invalidate the cached color mapping
# self._annotations_layer._cached_labels = None
# self._annotations_layer._selected_color = \
# self._annotations_layer.get_color(
# self._annotations_layer.selected_label
# )
# self._annotations_layer.events.colormap()
# self._annotations_layer.events.selected_label()
# self._annotations_layer.refresh()
# self._annotations_layer.colormap.update(
# {"color_dict": {label: color, None: [0, 0, 0, 0]}}
# )
self._annotations_layer.opacity = 1.0
self._annotations_layer.color_mode = "direct"

def _on_save_clicked(self):
"""
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions src/napari_feature_classifier/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from napari.utils.notifications import show_info
from matplotlib.colors import ListedColormap
from napari.utils.colormaps import DirectLabelColormap
import matplotlib
import numpy as np
import napari
Expand Down Expand Up @@ -80,9 +81,9 @@ def reset_display_colormaps(
"""
colors = cmap(label_layer.features[feature_col].astype(float) / len(cmap.colors))
colordict = dict(zip(label_layer.features[label_column], colors))
display_layer.color = colordict
colordict[None] = [0, 0, 0, 0]
display_layer.colormap = DirectLabelColormap(color_dict=colordict)
display_layer.opacity = 1.0
display_layer.color_mode = "direct"


# # Check if it runs in napari
Expand Down Expand Up @@ -133,7 +134,6 @@ def emit(self, record):
log_entry = self.format(record)
napari_info(log_entry)


def get_valid_label_layers(viewer) -> list[str]:
"""
Get a list of label layers that are not `Annotations` or `Predictions`.
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# For more information about tox, see https://tox.readthedocs.io/en/latest/
[tox]
envlist = py{38,39,310}-{linux,macos,windows}
envlist = py{39,310,311}-{linux,macos,windows}
isolated_build=true

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311

[gh-actions:env]
PLATFORM =
Expand Down
Loading