From 65083d932ff656d8c7178bbcd7e490fd1c43f2ba Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Tue, 26 Mar 2024 14:54:56 +0100 Subject: [PATCH 1/9] Fix FutureWarning: Labels.color is deprecated Replaces .color property of Labels layer by assigning colormap with DirectLabelColormap to match napari 0.5.0 --- napari_clusters_plotter/_plotter.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index 5ccde1ca..ef1f124a 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -7,6 +7,7 @@ from matplotlib.figure import Figure from napari.layers import Labels, Layer, Points, Surface from napari.utils.colormaps import ALL_COLORMAPS +from napari.utils import DirectLabelColormap from napari_tools_menu import register_dock_widget from qtpy import QtWidgets from qtpy.QtCore import Qt @@ -715,7 +716,7 @@ def run( for prediction in np.unique(self.cluster_ids) } # take care of background label - cmap_dict[0] = [0, 0, 0, 0] + cmap_dict[None] = [0, 0, 0, 0] keep_selection = list(self.viewer.layers.selection) @@ -816,7 +817,7 @@ def _update_cluster_image( layer_in_viewer.colormap = self.visualized_layer.colormap layer_in_viewer.contrast_limits = self.visualized_layer.contrast_limits elif isinstance(self.visualized_layer, Labels): - layer_in_viewer.color = self.visualized_layer.color + layer_in_viewer.colormap = self.visualized_layer.colormap else: print("Update failed") @@ -856,7 +857,7 @@ def _draw_cluster_image( cluster_layer = Layer.create( cluster_data, { - "color": cmap_dict, + "colormap": DirectLabelColormap(color_dict=cmap_dict), "name": "cluster_ids_in_space", "scale": self.layer_select.value.scale, }, @@ -874,7 +875,7 @@ def _draw_cluster_image( cluster_layer = Layer.create( cluster_data, { - "color": cmap_dict, + "colormap": DirectLabelColormap(color_dict=cmap_dict), "name": "cluster_ids_in_space", "scale": self.layer_select.value.scale, }, @@ -915,7 +916,7 @@ def _draw_cluster_image( cluster_layer = Layer.create( cluster_data, { - "color": cmap_dict, + "colormap": DirectLabelColormap(color_dict=cmap_dict), "name": "cluster_ids_in_space", "scale": self.layer_select.value.scale, }, From 00a7eeb29a1640ba171f026672436c792e44501c Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Tue, 26 Mar 2024 14:57:06 +0100 Subject: [PATCH 2/9] Fix bug when viewer is closed from code An Attribution Error raises if the viewer is closed from code because somehow an Image layer can be present at self.layer_select.value, which has no 'properties' property --- napari_clusters_plotter/_plotter.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index ef1f124a..a6920b9e 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -5,7 +5,7 @@ import numpy as np import pandas as pd from matplotlib.figure import Figure -from napari.layers import Labels, Layer, Points, Surface +from napari.layers import Labels, Layer, Points, Surface, Image from napari.utils.colormaps import ALL_COLORMAPS from napari.utils import DirectLabelColormap from napari_tools_menu import register_dock_widget @@ -498,9 +498,10 @@ def activate_property_autoupdate(self): self.last_connected.events.properties.disconnect( self.update_axes_and_clustering_id_lists ) - self.layer_select.value.events.properties.connect( - self.update_axes_and_clustering_id_lists - ) + if not isinstance(self.layer_select.value, Image): + self.layer_select.value.events.properties.connect( + self.update_axes_and_clustering_id_lists + ) self.last_connected = self.layer_select.value def update_axes_and_clustering_id_lists(self): From be58dc008fbfdcf6b20d6eaad7fd3cc57ae10dec Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Tue, 26 Mar 2024 14:58:59 +0100 Subject: [PATCH 3/9] Fix opacity attribution (again) This reverts opacity attribution to the layer (the value of the combobox), not to the combobox (which is 'layer_select') --- napari_clusters_plotter/_plotter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index a6920b9e..b83c9262 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -125,7 +125,7 @@ def manual_clustering_method(inside): plot_cluster_name=clustering_ID, ) if isinstance(self.analysed_layer, Labels): - self.layer_select.opacity = 0.2 + self.layer_select.value.opacity = 0.2 # Canvas Widget that displays the 'figure', it takes the 'figure' instance self.graphics_widget = MplCanvas( From 7d463a7949b16afc21c9aeea8d966a1a228f868f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:08:02 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- napari_clusters_plotter/_plotter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index b83c9262..3b9b8d03 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -5,9 +5,9 @@ import numpy as np import pandas as pd from matplotlib.figure import Figure -from napari.layers import Labels, Layer, Points, Surface, Image -from napari.utils.colormaps import ALL_COLORMAPS +from napari.layers import Image, Labels, Layer, Points, Surface from napari.utils import DirectLabelColormap +from napari.utils.colormaps import ALL_COLORMAPS from napari_tools_menu import register_dock_widget from qtpy import QtWidgets from qtpy.QtCore import Qt From aa06562b1d558002919206f828b4b55fe2e3a251 Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Thu, 28 Mar 2024 10:11:53 +0100 Subject: [PATCH 5/9] update requirements --- requirements.txt | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 94beb9dd..0acd1c7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ tornado~=6.2 numpy~=1.23.5 docutils~=0.17.1 pandas~=1.5.3 -napari~=0.4.17 +napari~=0.4.19 matplotlib~=3.7.1 magicgui~=0.7.2 qtpy~=2.3.0 diff --git a/setup.cfg b/setup.cfg index b09132bc..120018c1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,7 @@ install_requires = hdbscan qtpy dask - napari + napari>=0.4.19 magicgui scikit-image superqt From c6fc41d6780b3a1ecd9794f6fbe3c8e0f61f73b8 Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Fri, 12 Apr 2024 16:21:13 +0200 Subject: [PATCH 6/9] Revert "Fix opacity attribution (again)" This reverts commit be58dc008fbfdcf6b20d6eaad7fd3cc57ae10dec. --- napari_clusters_plotter/_plotter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index 3b9b8d03..50f6316f 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -125,7 +125,7 @@ def manual_clustering_method(inside): plot_cluster_name=clustering_ID, ) if isinstance(self.analysed_layer, Labels): - self.layer_select.value.opacity = 0.2 + self.layer_select.opacity = 0.2 # Canvas Widget that displays the 'figure', it takes the 'figure' instance self.graphics_widget = MplCanvas( From 9f777ea3bd0c5d2f56abe23c02ac76e84da2be19 Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Fri, 12 Apr 2024 16:24:08 +0200 Subject: [PATCH 7/9] revert checking image layer type --- napari_clusters_plotter/_plotter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index 50f6316f..4df2defa 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -498,10 +498,9 @@ def activate_property_autoupdate(self): self.last_connected.events.properties.disconnect( self.update_axes_and_clustering_id_lists ) - if not isinstance(self.layer_select.value, Image): - self.layer_select.value.events.properties.connect( - self.update_axes_and_clustering_id_lists - ) + self.layer_select.value.events.properties.connect( + self.update_axes_and_clustering_id_lists + ) self.last_connected = self.layer_select.value def update_axes_and_clustering_id_lists(self): From 1ddbffbe0c26e491f38bad95bf6ee95c76bfde0a Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Fri, 12 Apr 2024 16:25:15 +0200 Subject: [PATCH 8/9] remove unused layer type --- napari_clusters_plotter/_plotter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index 4df2defa..fd98629d 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -5,7 +5,7 @@ import numpy as np import pandas as pd from matplotlib.figure import Figure -from napari.layers import Image, Labels, Layer, Points, Surface +from napari.layers import Labels, Layer, Points, Surface from napari.utils import DirectLabelColormap from napari.utils.colormaps import ALL_COLORMAPS from napari_tools_menu import register_dock_widget From 7cdf261cb91059492ab09a026f6dc64318d44e25 Mon Sep 17 00:00:00 2001 From: Marcelo Zoccoler Date: Mon, 12 Aug 2024 15:34:17 +0200 Subject: [PATCH 9/9] remove unused variable --- napari_clusters_plotter/_plotter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/napari_clusters_plotter/_plotter.py b/napari_clusters_plotter/_plotter.py index 3022d12f..3242ca62 100644 --- a/napari_clusters_plotter/_plotter.py +++ b/napari_clusters_plotter/_plotter.py @@ -857,7 +857,6 @@ def _draw_cluster_image( cluster_data = generate_cluster_4d_labels( self.analysed_layer, plot_cluster_name ) - colormap = DirectLabelColormap(color_dict=cmap_dict) cluster_layer = Layer.create( cluster_data, {