diff --git a/src/box_manager/_qt/SelectMetric.py b/src/box_manager/_qt/SelectMetric.py index fcd0768..597826a 100644 --- a/src/box_manager/_qt/SelectMetric.py +++ b/src/box_manager/_qt/SelectMetric.py @@ -724,7 +724,11 @@ def _handle_insert(self, event): layer.editable = False if len(np.unique(get_size(layer))) == 1: - set_size(layer, np.ones(len(layer.data), dtype=bool), np.atleast_1d(get_size(layer)[0])[0]) + set_size( + layer, + np.ones(len(layer.data), dtype=bool), + np.atleast_1d(get_size(layer)[0])[0], + ) layer.refresh() layer.events.set_data.connect(self._update_on_data) layer.events.editable.connect(self._update_editable) @@ -1072,20 +1076,27 @@ def _update_on_data(self, event): return if not check_equal(layer, self.prev_valid_layers[layer.name][1]): + """ + We need to identify which coordinates have actually changed. + For this we use two sets and identify the old and new indices. + New indices are getting their feaures filled. + """ old_data = self.prev_valid_layers[layer.name][1] - if self.napari_viewer.dims.ndim == 3: - set_old = {tuple(row.ravel().tolist()) for row in old_data} - set_new = { + if self.napari_viewer.dims.ndim == 3 and layer.ndim == 3: + set_old_coordinates = { + tuple(row.ravel().tolist()) for row in old_data + } + set_new_coordinates = { tuple(row.ravel().tolist()) for row in layer.data } indices_old = { row[self.napari_viewer.dims.order[0]] - for row in set_old - set_new + for row in set_old_coordinates - set_new_coordinates } indices_new = { row[self.napari_viewer.dims.order[0]] - for row in set_new - set_old + for row in set_new_coordinates - set_old_coordinates } current_slices = list(indices_new | indices_old) if indices_new: @@ -1095,6 +1106,8 @@ def _update_on_data(self, event): .sort_values() .iloc[layer.features.shape[0] // 2] ) + elif self.napari_viewer.dims.ndim == 3 and layer.ndim == 2: + current_slices = [0] elif self.napari_viewer.dims.ndim == 2: current_slices = [0] else: