From 46d5de442d29d94323fec3acdcafe8c4e5d891a7 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 2 Apr 2024 13:31:02 -0400 Subject: [PATCH 1/6] export plugin dataset filters * do not require being a layer in a viewer * add a filter for requiring to be from a plugin, and update language in UI * cleanup implementation of parent/child layer filters to avoid conflict with new default filters --- .../configs/default/plugins/export/export.py | 7 +++++ .../configs/default/plugins/export/export.vue | 8 ++++- jdaviz/core/template_mixin.py | 30 +++++++++++-------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index aa215bb27f..3b5431b193 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -89,6 +89,11 @@ class Export(PluginTemplateMixin, ViewerSelectMixin, SubsetSelectMixin, def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # NOTE: if adding export support for non-plugin products, also update the language + # in the UI as well as in _set_dataset_not_supported_msg + self.dataset.filters = ['is_not_wcs_only', 'not_child_layer', + 'from_plugin'] + self.plot = SelectPluginComponent(self, items='plot_items', selected='plot_selected', @@ -237,6 +242,8 @@ def _set_subset_not_supported_msg(self, msg=None): def _set_dataset_not_supported_msg(self, msg=None): if self.dataset.selected_obj is not None: if self.dataset.selected_obj.meta.get("Plugin", None) is None: + # NOTE: should not be a valid choice due to dataset filters, but we'll include + # another check here. self.data_invalid_msg = "Data export is only available for plugin generated data." elif not isinstance(self.dataset.selected_obj, (Spectrum1D, CCDData)): self.data_invalid_msg = "Export is not implemented for this type of data" diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index 9b999e45e3..138a0b046a 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -21,6 +21,9 @@ > + + Export viewer plot as an image. + Data + + Export data generated by plugins. + Subsets - Save subset as astropy region. + Export subset as astropy region. Date: Tue, 2 Apr 2024 13:32:22 -0400 Subject: [PATCH 2/6] use filter for spatial subsets --- jdaviz/configs/default/plugins/export/export.py | 3 +++ jdaviz/configs/default/plugins/export/export.vue | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 3b5431b193..1a854d2aea 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -94,6 +94,9 @@ def __init__(self, *args, **kwargs): self.dataset.filters = ['is_not_wcs_only', 'not_child_layer', 'from_plugin'] + # NOTE: if/when adding support for spectral subsets, update the languange in the UI + self.subset.filters = ['is_spatial'] + self.plot = SelectPluginComponent(self, items='plot_items', selected='plot_selected', diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index 138a0b046a..6b9da02eaf 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -121,7 +121,7 @@
Subsets - Export subset as astropy region. + Export spatial subset as astropy region. Date: Tue, 2 Apr 2024 13:36:50 -0400 Subject: [PATCH 3/6] changelog entry --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1c6070a52c..32231ff4d8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,7 +15,7 @@ New Features - "Export Plot" plugin is now replaced with the more general "Export" plugin. [#2722] -- "Export" plugin supports exporting plugin tables, data and non-composite spatial subsets.[#2755, #2760, #2772, #2770] +- "Export" plugin supports exporting plugin tables, data and non-composite spatial subsets.[#2755, #2760, #2772, #2770, #2780] - Opening a plugin in the tray (from the API or the toolbar buttons) now scrolls to that plugin. [#2768] From 01843c5fa7cb0fb95c2370b1b2a665891e3e7785 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 2 Apr 2024 14:20:16 -0400 Subject: [PATCH 4/6] update tests --- .../plugins/export/tests/test_export.py | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index 61de1908f9..8db93bfce2 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -92,9 +92,7 @@ def test_not_implemented(self, cubeviz_helper, spectral_cube_wcs): cubeviz_helper.app.session.edit_subset_mode.mode = NewMode cubeviz_helper.app.get_viewer("spectrum-viewer").apply_roi(XRangeROI(5, 15.5)) - export_plugin.subset.selected = 'Subset 2' - - assert export_plugin.subset_invalid_msg == 'Export for spectral subsets not supported.' + assert 'Subset 2' not in export_plugin.subset.choices def test_export_subsets_wcs(self, tmp_path, imviz_helper, spectral_cube_wcs): @@ -186,18 +184,6 @@ def test_basic_export_subsets_cubeviz(self, tmp_path, cubeviz_helper, spectral_c def test_export_data(cubeviz_helper, spectrum1d_cube): - cubeviz_helper.load_data(spectrum1d_cube, data_label="test") - export_plugin = cubeviz_helper.plugins["Export"]._obj - export_plugin.dataset_selected = 'test[FLUX]' - assert export_plugin.dataset_format.selected == 'fits' - assert 'test[FLUX]' in cubeviz_helper.app.data_collection.labels - with pytest.raises(NotImplementedError, - match='Data can not be exported'): - export_plugin.export() - assert export_plugin.data_invalid_msg == 'Data export is only available for plugin generated data.' # noqa - - -def test_disable_export_for_non_plugin_generated_data(cubeviz_helper, spectrum1d_cube): cubeviz_helper.load_data(spectrum1d_cube, data_label='test') mm = cubeviz_helper.plugins["Moment Maps"] mm.dataset = 'test[FLUX]' @@ -209,13 +195,10 @@ def test_disable_export_for_non_plugin_generated_data(cubeviz_helper, spectrum1d cubeviz_helper._default_flux_viewer_reference_name, 'moment 0' ) ep = cubeviz_helper.plugins["Export"]._obj - ep.dataset_selected = 'test[FLUX]' - with pytest.raises(NotImplementedError, - match='Data can not be exported'): - ep.export() - assert ep.data_invalid_msg == 'Data export is only available for plugin generated data.' + assert 'test[FLUX]' not in ep.dataset.choices ep.dataset_selected = 'moment 0' + assert ep.dataset_format.selected == 'fits' ep.export() assert os.path.isfile("cubeviz_export.fits") assert ep.data_invalid_msg == '' From b8e0a54e9b26e48282eeb71a01ac855af5d9207a Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 2 Apr 2024 14:38:57 -0400 Subject: [PATCH 5/6] fix viewer hint formatting --- jdaviz/configs/default/plugins/export/export.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index 6b9da02eaf..02057eeecf 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -13,6 +13,9 @@ > Viewers + + Export viewer plot as an image. + - - Export viewer plot as an image. - Date: Wed, 3 Apr 2024 09:35:05 -0400 Subject: [PATCH 6/6] add hint text for plugin tables/plots --- jdaviz/configs/default/plugins/export/export.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index 02057eeecf..3ac3e83738 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -153,6 +153,9 @@
Plugin Tables + + Export table from a plugin to a file. + Plugin Plots + + Export plot from a plugin as an image. +