From b6d7ea8cef50cf669d7084bfc1c4695788b471e3 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 12 Dec 2023 15:27:48 -0500 Subject: [PATCH 1/3] Remove hard coded 'Subset' string checks --- jdaviz/app.py | 3 ++- jdaviz/core/helpers.py | 3 ++- jdaviz/core/template_mixin.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jdaviz/app.py b/jdaviz/app.py index 92b419e3ee..1e629fae2f 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -1899,13 +1899,14 @@ def vue_data_item_remove(self, event): # the reference data (which would leave 0 external_links). if len(self.data_collection) > 1 and len(self.data_collection.external_links) == 0: if self.config == "imviz" and imviz_refdata: + subset_labels = [sg.label for sg in self.data_collection.subset_groups] link_type = self._jdaviz_helper.plugins["Links Control"].link_type.selected.lower() self._jdaviz_helper.link_data(link_type=link_type, error_on_fail=True) # Hack to restore responsiveness to imviz layers for viewer_ref in self.get_viewer_reference_names(): viewer = self.get_viewer(viewer_ref) loaded_layers = [layer.layer.label for layer in viewer.layers if - "Subset" not in layer.layer.label] + layer.layer.label not in subset_labels] if len(loaded_layers): self.remove_data_from_viewer(viewer_ref, loaded_layers[-1]) self.add_data_to_viewer(viewer_ref, loaded_layers[-1]) diff --git a/jdaviz/core/helpers.py b/jdaviz/core/helpers.py index d3b2dddd13..2ceff9f408 100644 --- a/jdaviz/core/helpers.py +++ b/jdaviz/core/helpers.py @@ -865,7 +865,8 @@ def get_interactive_regions(self): # TODO: Remove this when Jdaviz support round-tripping, see # https://github.com/spacetelescope/jdaviz/pull/721 - if not subset_label.startswith('Subset'): + + if subset_label not in [sg.label for sg in self.app.data_collection.subset_groups]: continue try: diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 5271143b3e..08543ba33f 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1669,7 +1669,8 @@ def _update_subset(self, subset, attribute=None): if subset.label not in self.labels: # NOTE: this logic will need to be revisited if generic renaming of subsets is added # see https://github.com/spacetelescope/jdaviz/pull/1175#discussion_r829372470 - if subset.label.startswith('Subset') and self._is_valid_item(subset): + dc_subset_labels = [sg.label for sg in self.app.data_collection.subset_groups] + if subset.label in dc_subset_labels and self._is_valid_item(subset): # NOTE: += will not trigger traitlet update self.items = self.items + [self._subset_to_dict(subset)] # noqa else: From e1512900bc6c6cdaeb9e8e7a1e60b04ac7128764 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 12 Dec 2023 16:17:06 -0500 Subject: [PATCH 2/3] Debugging --- jdaviz/core/template_mixin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index bd3a3b2e88..e3ea3dc189 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1632,6 +1632,11 @@ def _reset_items(self): self.app.data_collection.subset_groups] self.items = self.manual_items + [s for s in all_subsets if self._is_valid_item(s)] + if hasattr(self.plugin, "_plugin_name"): + if self.plugin._plugin_name == "Line Analysis": + print("Resetting items") + print(f"All subsets: {all_subsets}") + print(f"Valid items: {self.items}") @staticmethod def _subset_type(subset): @@ -1691,7 +1696,12 @@ def _update_subset(self, subset, attribute=None): # the subset that was changed does not match the current filter return + if self.plugin._plugin_name == "Line Analysis": + print(f"Got UpdateSubset message: {subset} {attribute}") + if attribute == 'label': + if self.plugin._plugin_name == "Line Analysis": + print("Attribute is label") selected = self.selected # then rebuild the whole items list self._reset_items() @@ -1705,6 +1715,11 @@ def _update_subset(self, subset, attribute=None): # NOTE: this logic will need to be revisited if generic renaming of subsets is added # see https://github.com/spacetelescope/jdaviz/pull/1175#discussion_r829372470 dc_subset_labels = [sg.label for sg in self.app.data_collection.subset_groups] + print("Got to checking valid item") + if subset.label not in dc_subset_labels: + print("Not in dc_subset_labels") + elif not self._is_valid_item(subset): + print("Not a valid item") if subset.label in dc_subset_labels and self._is_valid_item(subset): # NOTE: += will not trigger traitlet update self.items = self.items + [self._subset_to_dict(subset)] # noqa @@ -1784,6 +1799,7 @@ def rename_selected(self, new_name): raise TypeError("current selection is not a subset") # this will trigger the SubsetUpdateMessage + print(f"Renaming {subset_group.label} to {new_name}") subset_group.label = new_name @cached_property From 70f922ce3cd54fe5e8601ba5845d9a5c2e50a58a Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 12 Dec 2023 16:32:02 -0500 Subject: [PATCH 3/3] Fix reset_items for selectors that care about spatial vs spectral --- jdaviz/core/template_mixin.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index e3ea3dc189..7a5b86ce54 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1632,11 +1632,6 @@ def _reset_items(self): self.app.data_collection.subset_groups] self.items = self.manual_items + [s for s in all_subsets if self._is_valid_item(s)] - if hasattr(self.plugin, "_plugin_name"): - if self.plugin._plugin_name == "Line Analysis": - print("Resetting items") - print(f"All subsets: {all_subsets}") - print(f"Valid items: {self.items}") @staticmethod def _subset_type(subset): @@ -1675,9 +1670,15 @@ def _delete_subset(self, subset): def _is_valid_item(self, subset): def is_spectral(subset): + if isinstance(subset, dict) and "type" in subset.keys(): + if subset["type"] == "spectral": + return True return get_subset_type(subset) == 'spectral' def is_spatial(subset): + if isinstance(subset, dict) and "type" in subset.keys(): + if subset["type"] == "spatial": + return True return get_subset_type(subset) == 'spatial' def is_not_composite(subset): @@ -1696,12 +1697,7 @@ def _update_subset(self, subset, attribute=None): # the subset that was changed does not match the current filter return - if self.plugin._plugin_name == "Line Analysis": - print(f"Got UpdateSubset message: {subset} {attribute}") - if attribute == 'label': - if self.plugin._plugin_name == "Line Analysis": - print("Attribute is label") selected = self.selected # then rebuild the whole items list self._reset_items() @@ -1715,11 +1711,6 @@ def _update_subset(self, subset, attribute=None): # NOTE: this logic will need to be revisited if generic renaming of subsets is added # see https://github.com/spacetelescope/jdaviz/pull/1175#discussion_r829372470 dc_subset_labels = [sg.label for sg in self.app.data_collection.subset_groups] - print("Got to checking valid item") - if subset.label not in dc_subset_labels: - print("Not in dc_subset_labels") - elif not self._is_valid_item(subset): - print("Not a valid item") if subset.label in dc_subset_labels and self._is_valid_item(subset): # NOTE: += will not trigger traitlet update self.items = self.items + [self._subset_to_dict(subset)] # noqa @@ -1799,7 +1790,6 @@ def rename_selected(self, new_name): raise TypeError("current selection is not a subset") # this will trigger the SubsetUpdateMessage - print(f"Renaming {subset_group.label} to {new_name}") subset_group.label = new_name @cached_property