From 31a5550ab552a744a1a140b18ec05b6f9e7e709a Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 23 Apr 2024 11:25:35 -0400 Subject: [PATCH 01/17] Starting to add spectral subsets to export --- jdaviz/configs/default/plugins/export/export.py | 4 +++- jdaviz/configs/default/plugins/export/export.vue | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index d3af6a8810..6428dd0475 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -269,7 +269,9 @@ def _set_subset_not_supported_msg(self, msg=None): if self.subset.selected == '': self.subset_invalid_msg = '' elif self.app._is_subset_spectral(subset[0]): - self.subset_invalid_msg = 'Export for spectral subsets not yet supported.' + self.subset_invalid_msg = '' + self.subset_format_items = ['ecsv',] + self.subset_format.items = self.subset_format_items elif len(subset) > 1: self.subset_invalid_msg = 'Export for composite subsets not yet supported.' else: diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index 979738f5f1..f86244d4ea 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -33,7 +33,7 @@ :items="viewer_format_items.map(i => i.label)" label="Format" hint="Image format for exporting viewers." - :disabled="viewer_selected.length == 0" + :disabled="viewer_selected.length == 0" persistent-hint > @@ -126,7 +126,7 @@
- Spatial Subsets + Subsets Export spatial subset as astropy region. @@ -200,10 +200,10 @@ :single_select_allow_blank="false" > - + :widget="plugin_plot_selected_widget"/> Date: Thu, 25 Apr 2024 16:25:28 -0400 Subject: [PATCH 02/17] Update SelectPluginComponent to allow use of disabled item property, use it in export subset --- .../configs/default/plugins/export/export.py | 28 ++++++++++++++++--- .../configs/default/plugins/export/export.vue | 4 ++- jdaviz/core/template_mixin.py | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 6428dd0475..d5fa2b417d 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -112,7 +112,7 @@ def __init__(self, *args, **kwargs): 'from_plugin'] # NOTE: if/when adding support for spectral subsets, update the languange in the UI - self.subset.filters = ['is_spatial'] + #self.subset.filters = ['is_spatial'] viewer_format_options = ['png', 'svg'] if self.config == 'cubeviz': @@ -135,7 +135,10 @@ def __init__(self, *args, **kwargs): selected='plugin_table_format_selected', manual_options=plugin_table_format_options) - subset_format_options = ['fits', 'reg'] + subset_format_options = [{'label': 'fits', 'value': 'fits', 'disabled': False}, + {'label': 'reg', 'value': 'reg', 'disabled': False}, + {'label': 'ecsv', 'value': 'ecsv', 'disabled': True}] + #subset_format_options = ['fits', 'reg'] self.subset_format = SelectPluginComponent(self, items='subset_format_items', selected='subset_format_selected', @@ -226,6 +229,7 @@ def _sync_singleselect(self, event): if name != attr: setattr(self, attr, '') if attr == 'subset_selected': + self._update_subset_format_disabled() self._set_subset_not_supported_msg() if attr == 'dataset_selected': self._set_dataset_not_supported_msg() @@ -258,6 +262,24 @@ def _is_filename_changed(self, event): # Clear overwrite warning when user changes filename self.overwrite_warn = False + def _update_subset_format_disabled(self): + print("Updating disabled formats") + new_items = [] + if self.subset.selected is not None: + subset = self.app.get_subsets(self.subset.selected) + if self.app._is_subset_spectral(subset[0]): + good_formats = ["ecsv"] + else: + good_formats = ["fits", "reg"] + for item in self.subset_format_items: + if item["label"] in good_formats: + item["disabled"] = False + else: + item["disabled"] = True + new_items.append(item) + self.subset_format_items = [] + self.subset_format_items = new_items + def _set_subset_not_supported_msg(self, msg=None): """ Check if selected subset is spectral or composite, and warn and @@ -270,8 +292,6 @@ def _set_subset_not_supported_msg(self, msg=None): self.subset_invalid_msg = '' elif self.app._is_subset_spectral(subset[0]): self.subset_invalid_msg = '' - self.subset_format_items = ['ecsv',] - self.subset_format.items = self.subset_format_items elif len(subset) > 1: self.subset_invalid_msg = 'Export for composite subsets not yet supported.' else: diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index f86244d4ea..ac9d0294a4 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -150,7 +150,9 @@ :menu-props="{ left: true }" attach v-model="subset_format_selected" - :items="subset_format_items.map(i => i.label)" + :items="subset_format_items" + item-text="label" + item-disabled="disabled" label="Format" hint="Format for exporting subsets." :disabled="subset_selected == null || subset_selected.length == 0" diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 7d5e826d32..8f02901f88 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -725,7 +725,7 @@ def __init__(self, *args, **kwargs): manual_options = [default_text] + manual_options self._manual_options = manual_options - self.items = [{"label": opt} for opt in manual_options] + self.items = [{"label": opt} if isinstance(opt, str) else opt for opt in manual_options] # set default values for traitlets if default_text is not None: self.selected = default_text From e99963969524625cb54aa275673550afd05e71ca Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 30 Apr 2024 13:29:38 -0400 Subject: [PATCH 03/17] Add handling for disabling bad subset/format combinations --- .../configs/default/plugins/export/export.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index d5fa2b417d..0e5dba6f59 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -229,7 +229,8 @@ def _sync_singleselect(self, event): if name != attr: setattr(self, attr, '') if attr == 'subset_selected': - self._update_subset_format_disabled() + if self.subset.selected != '': + self._update_subset_format_disabled() self._set_subset_not_supported_msg() if attr == 'dataset_selected': self._set_dataset_not_supported_msg() @@ -263,7 +264,6 @@ def _is_filename_changed(self, event): self.overwrite_warn = False def _update_subset_format_disabled(self): - print("Updating disabled formats") new_items = [] if self.subset.selected is not None: subset = self.app.get_subsets(self.subset.selected) @@ -276,10 +276,28 @@ def _update_subset_format_disabled(self): item["disabled"] = False else: item["disabled"] = True + if item["label"] == self.subset_format.selected: + self.subset_format.selected = good_formats[0] new_items.append(item) self.subset_format_items = [] self.subset_format_items = new_items + @observe('subset_format_selected') + def _disable_subset_format_combo(self, event): + if self.subset.selected == '' or self.subset.selected is None: + return + # Disable selecting a bad subset+format combination from the API + subset = self.app.get_subsets(self.subset.selected) + bad_combo = False + if self.app._is_subset_spectral(subset[0]): + if self.subset_format.selected.lower != "ecsv": + bad_combo = True + elif self.subset_format.selected.lower == "ecsv": + bad_combo = True + + if bad_combo: + raise ValueError(f"Cannot export {self.subset.selected} as {self.subset_format.selected}") + def _set_subset_not_supported_msg(self, msg=None): """ Check if selected subset is spectral or composite, and warn and From 04654d0aee24ade4d81a24a4181dbce72fb4a5fc Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 30 Apr 2024 13:38:38 -0400 Subject: [PATCH 04/17] Fix codestyle --- jdaviz/configs/default/plugins/export/export.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 0e5dba6f59..889ee6b21e 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -111,9 +111,6 @@ 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'] - viewer_format_options = ['png', 'svg'] if self.config == 'cubeviz': if not self.app.state.settings.get('server_is_remote'): @@ -136,9 +133,8 @@ def __init__(self, *args, **kwargs): manual_options=plugin_table_format_options) subset_format_options = [{'label': 'fits', 'value': 'fits', 'disabled': False}, - {'label': 'reg', 'value': 'reg', 'disabled': False}, - {'label': 'ecsv', 'value': 'ecsv', 'disabled': True}] - #subset_format_options = ['fits', 'reg'] + {'label': 'reg', 'value': 'reg', 'disabled': False}, + {'label': 'ecsv', 'value': 'ecsv', 'disabled': True}] self.subset_format = SelectPluginComponent(self, items='subset_format_items', selected='subset_format_selected', @@ -296,7 +292,8 @@ def _disable_subset_format_combo(self, event): bad_combo = True if bad_combo: - raise ValueError(f"Cannot export {self.subset.selected} as {self.subset_format.selected}") + raise ValueError(f"Cannot export {self.subset.selected} in " + f"{self.subset_format.selected.upper} format") def _set_subset_not_supported_msg(self, msg=None): """ From 60a075d3f98178ee7cf837e78b3617ba46ab774b Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 30 Apr 2024 13:57:27 -0400 Subject: [PATCH 05/17] Update tests --- .../configs/default/plugins/export/tests/test_export.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index 9c7794deb7..b280bc9bb0 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -66,7 +66,7 @@ def test_basic_export_subsets_imviz(self, imviz_helper): # test that invalid file extension raises an error with pytest.raises(ValueError, - match=re.escape("x not one of ['fits', 'reg'], reverting selection to reg")): # noqa + match=re.escape("x not one of ['fits', 'reg', 'ecsv'], reverting selection to reg")): # noqa export_plugin.subset_format.selected = 'x' def test_not_implemented(self, cubeviz_helper, spectral_cube_wcs): @@ -93,10 +93,6 @@ def test_not_implemented(self, cubeviz_helper, spectral_cube_wcs): assert export_plugin.subset_invalid_msg == 'Export for composite subsets not yet supported.' - cubeviz_helper.app.session.edit_subset_mode.mode = NewMode - cubeviz_helper.app.get_viewer("spectrum-viewer").apply_roi(XRangeROI(5, 15.5)) - assert 'Subset 2' not in export_plugin.subset.choices - def test_export_subsets_wcs(self, imviz_helper, spectral_cube_wcs): # using cube WCS instead of 2d imaging wcs for consistancy with @@ -193,7 +189,7 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): # test that invalid file extension raises an error with pytest.raises(ValueError, - match=re.escape("x not one of ['fits', 'reg'], reverting selection to reg")): # noqa + match=re.escape("x not one of ['fits', 'reg', 'ecsv'], reverting selection to reg")): # noqa export_plugin.subset_format.selected = 'x' # test that attempting to save a composite subset raises an error From 6670683a599295ed7d3c95d15903d8e8c41da583 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 30 Apr 2024 16:38:08 -0400 Subject: [PATCH 06/17] Add code to actually save the spectral region, add tests --- .../configs/default/plugins/export/export.py | 19 ++++++++++++++----- .../plugins/export/tests/test_export.py | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 889ee6b21e..95e4fcd395 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -280,20 +280,20 @@ def _update_subset_format_disabled(self): @observe('subset_format_selected') def _disable_subset_format_combo(self, event): + # Disable selecting a bad subset+format combination from the API if self.subset.selected == '' or self.subset.selected is None: return - # Disable selecting a bad subset+format combination from the API subset = self.app.get_subsets(self.subset.selected) bad_combo = False if self.app._is_subset_spectral(subset[0]): - if self.subset_format.selected.lower != "ecsv": + if event['new'] != "ecsv": bad_combo = True - elif self.subset_format.selected.lower == "ecsv": + elif event['new'] == "ecsv": bad_combo = True if bad_combo: raise ValueError(f"Cannot export {self.subset.selected} in " - f"{self.subset_format.selected.upper} format") + f"{self.subset_format.selected.upper()} format") def _set_subset_not_supported_msg(self, msg=None): """ @@ -459,7 +459,12 @@ def export(self, filename=None, show_dialog=None, overwrite=False, if raise_error_for_overwrite: raise FileExistsError(f"{filename} exists but overwrite=False") return - self.save_subset_as_region(selected_subset_label, filename) + + if self.subset_format.selected in ('fits', 'reg'): + self.save_subset_as_region(selected_subset_label, filename) + elif self.subset_format.selected == 'ecsv': + self.save_subset_as_table(filename) + elif len(self.dataset.selected): filetype = self.dataset_format.selected @@ -692,6 +697,10 @@ def save_subset_as_region(self, selected_subset_label, filename): region.write(filename, overwrite=True) + def save_subset_as_table(self, filename): + region = self.app.get_subsets(subset_name=self.subset.selected) + region.write(filename) + def vue_interrupt_recording(self, *args): # pragma: no cover self.movie_interrupt = True # TODO: this will need updating when batch/multiselect support is added diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index b280bc9bb0..c0e884829d 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -192,6 +192,10 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): match=re.escape("x not one of ['fits', 'reg', 'ecsv'], reverting selection to reg")): # noqa export_plugin.subset_format.selected = 'x' + # Test that selecting disabled option raises an error + with pytest.raises(ValueError, match="Cannot export Subset 1 in ECSV format"): + export_plugin.subset_format.selected = 'ecsv' + # test that attempting to save a composite subset raises an error cubeviz_helper.app.session.edit_subset_mode.mode = AndMode cubeviz_helper.app.get_viewer('flux-viewer').apply_roi(CircularROI(xc=25, yc=25, radius=5)) @@ -201,6 +205,18 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): match='Subset can not be exported - Export for composite subsets not yet supported.'): # noqa export_plugin.export() + # Test saving spectral subset + 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' + + # Format should auto-update to first non-disabled entry + assert export_plugin.subset_format.selected == 'ecsv' + + export_plugin.filename = "test_spectral_region" + export_plugin.export() + assert os.path.isfile('test_spectral_region.ecsv') + @pytest.mark.usefixtures('_jail') def test_export_cubeviz_spectrum_viewer(cubeviz_helper, spectrum1d_cube): From 11b8869138f163beff150829713fd3e1f987e070 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 12:52:31 -0400 Subject: [PATCH 07/17] Update specutils pin --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 52bf994860..e48e909f8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ "ipywidgets>=8.0.6", "voila>=0.4,<0.5", "pyyaml>=5.4.1", - "specutils>=1.9", + "specutils>=1.15", "specreduce>=1.3.0,<1.4.0", "photutils>=1.4", "glue-astronomy>=0.10", From 7386258b435f57ff5a008953661de8c51d65c946 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 13:02:29 -0400 Subject: [PATCH 08/17] Update changelog --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ca3f5c893a..4c939e2eb9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,9 @@ New Features - Adding Data Quality plugin for Imviz and Cubeviz. [#2767, #2817] +- Enable exporting spectral regions to ECSV files readable by ``astropy.table.QTable`` or + ``specutils.SpectralRegion`` [#2843] + Cubeviz ^^^^^^^ From d8e652fb617513f78591fcce0854efa9d278d2df Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 13:03:32 -0400 Subject: [PATCH 09/17] Delete extra line --- jdaviz/configs/default/plugins/export/export.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 95e4fcd395..31310e926b 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -465,7 +465,6 @@ def export(self, filename=None, show_dialog=None, overwrite=False, elif self.subset_format.selected == 'ecsv': self.save_subset_as_table(filename) - elif len(self.dataset.selected): filetype = self.dataset_format.selected filename = self._normalize_filename(filename, filetype, overwrite=overwrite) From 2da3ad678044972d48f3aad5115d8f41945ac34b Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 14:09:24 -0400 Subject: [PATCH 10/17] Debugging tests on CI --- jdaviz/configs/default/plugins/export/tests/test_export.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index c0e884829d..1ef8b130bd 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -215,6 +215,8 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): export_plugin.filename = "test_spectral_region" export_plugin.export() + # Testing CI failure + print(os.listdir()) assert os.path.isfile('test_spectral_region.ecsv') From 0fca14bfe1bfa1b33888b2dfc5a30b5f293b10ce Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 14:32:41 -0400 Subject: [PATCH 11/17] Update to account for recent changes --- jdaviz/configs/default/plugins/export/tests/test_export.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index 1ef8b130bd..cae6d081a8 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -213,10 +213,8 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): # Format should auto-update to first non-disabled entry assert export_plugin.subset_format.selected == 'ecsv' - export_plugin.filename = "test_spectral_region" + export_plugin.filename_value = "test_spectral_region" export_plugin.export() - # Testing CI failure - print(os.listdir()) assert os.path.isfile('test_spectral_region.ecsv') From 4e33fba38d676c5bf466a2f257b2ec205d11267f Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Wed, 1 May 2024 15:33:10 -0400 Subject: [PATCH 12/17] Address review comments --- CHANGES.rst | 2 ++ jdaviz/configs/default/plugins/export/tests/test_export.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 4c939e2eb9..440408d940 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -76,6 +76,8 @@ Other Changes and Additions - Line menu in Redshift from Centroid section of Line Analysis now shows values in current units. [#2816, #2831] +- Bump required specutils version to 1.15. [#2843] + 3.9.2 (unreleased) ================== diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index cae6d081a8..78686e97c6 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -212,6 +212,11 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): # Format should auto-update to first non-disabled entry assert export_plugin.subset_format.selected == 'ecsv' + for format in export_plugin.subset_format.items: + if format['label'] != 'ecsv': + assert format['disabled'] + else: + assert format['disabled'] is False export_plugin.filename_value = "test_spectral_region" export_plugin.export() From 443d93cc482d8dd42a20308db9a6a8e812adb0b3 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Thu, 2 May 2024 11:49:01 -0400 Subject: [PATCH 13/17] Address review comments --- jdaviz/configs/default/plugins/export/export.py | 8 ++++++-- jdaviz/configs/default/plugins/export/export.vue | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 31310e926b..73978196d1 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -292,8 +292,12 @@ def _disable_subset_format_combo(self, event): bad_combo = True if bad_combo: - raise ValueError(f"Cannot export {self.subset.selected} in " - f"{self.subset_format.selected.upper()} format") + # Set back to a good value and raise error + good_format = [format["label"] for format in self.subset_format_items if + format["disabled"] is False][0] + self.subset_format.selected = good_format + raise ValueError(f"Cannot export {self.subset.selected} in {event['new']}" + f" format, reverting selection to {self.subset_format.selected}") def _set_subset_not_supported_msg(self, msg=None): """ diff --git a/jdaviz/configs/default/plugins/export/export.vue b/jdaviz/configs/default/plugins/export/export.vue index ac9d0294a4..16354a61bb 100644 --- a/jdaviz/configs/default/plugins/export/export.vue +++ b/jdaviz/configs/default/plugins/export/export.vue @@ -128,7 +128,7 @@
Subsets - Export spatial subset as astropy region. + Export spatial subset as astropy region or spectral subset as specutils SpectralRegion.
- + Date: Thu, 2 May 2024 11:56:05 -0400 Subject: [PATCH 14/17] Updated docs --- docs/specviz/export_data.rst | 7 ++++++- docs/specviz/plugins.rst | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/specviz/export_data.rst b/docs/specviz/export_data.rst index 5f7111bad0..886098751c 100644 --- a/docs/specviz/export_data.rst +++ b/docs/specviz/export_data.rst @@ -14,7 +14,7 @@ those data currently back into your Jupyter notebook: specviz.get_spectra() -which yields a either a single `specutils.Spectrum1D` object or a dictionary of +which yields a either a single `specutils.Spectrum1D` object or a dictionary of `specutils.Spectrum1D` (if there are multiple displayed spectra) that you can manipulate however you wish. You can then load the modified spectrum back into the notebook via the API described in :ref:`specviz-import-api`. @@ -70,6 +70,11 @@ To extract the spectral region you want: myregion = regions["Subset 2"] +.. seealso:: + + :ref:`Export From Plugins ` + Spectral region subsets can also be exported to disk as an ECSV file. + .. _specviz-export-model: Model Fits diff --git a/docs/specviz/plugins.rst b/docs/specviz/plugins.rst index 72d0c1ebd3..a65f44ea7f 100644 --- a/docs/specviz/plugins.rst +++ b/docs/specviz/plugins.rst @@ -320,4 +320,8 @@ using the |icon-line-select| (line selector) tool in the spectrum viewer. Export ====== -This plugin allows a given viewer's plot to be exported to various image formats. +This plugin allows exporting a the contents of a viewer or a plot within a plugin to various image formats. +Additionally, spatial and spectral regions can be exported to files, as astropy regions saves as FITS or REG +files (in the case of spatial regions), or as ECSV files in the case of spectral regions via specutils SpectralRegion. +Note that multiple spectral regions can be saved out to the same file, as long as they are subregions of a single +subset rather than independent subsets. \ No newline at end of file From 34f593797759a468572e125f6135f2057d89894c Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Thu, 2 May 2024 12:04:20 -0400 Subject: [PATCH 15/17] Fix typo --- docs/specviz/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/specviz/plugins.rst b/docs/specviz/plugins.rst index a65f44ea7f..38a0fbf286 100644 --- a/docs/specviz/plugins.rst +++ b/docs/specviz/plugins.rst @@ -320,7 +320,7 @@ using the |icon-line-select| (line selector) tool in the spectrum viewer. Export ====== -This plugin allows exporting a the contents of a viewer or a plot within a plugin to various image formats. +This plugin allows exporting the contents of a viewer or a plot within a plugin to various image formats. Additionally, spatial and spectral regions can be exported to files, as astropy regions saves as FITS or REG files (in the case of spatial regions), or as ECSV files in the case of spectral regions via specutils SpectralRegion. Note that multiple spectral regions can be saved out to the same file, as long as they are subregions of a single From c7f7cea7a9f59d62973a8f715453a5446416139b Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Thu, 2 May 2024 12:05:09 -0400 Subject: [PATCH 16/17] typo --- docs/specviz/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/specviz/plugins.rst b/docs/specviz/plugins.rst index 38a0fbf286..8770eb7be8 100644 --- a/docs/specviz/plugins.rst +++ b/docs/specviz/plugins.rst @@ -321,7 +321,7 @@ Export ====== This plugin allows exporting the contents of a viewer or a plot within a plugin to various image formats. -Additionally, spatial and spectral regions can be exported to files, as astropy regions saves as FITS or REG +Additionally, spatial and spectral regions can be exported to files, as astropy regions saved as FITS or REG files (in the case of spatial regions), or as ECSV files in the case of spectral regions via specutils SpectralRegion. Note that multiple spectral regions can be saved out to the same file, as long as they are subregions of a single subset rather than independent subsets. \ No newline at end of file From 3a415ec0f8f77db51fc86963129bdbc58d92ff93 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Thu, 2 May 2024 14:54:28 -0400 Subject: [PATCH 17/17] Fix test --- jdaviz/configs/default/plugins/export/tests/test_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index 78686e97c6..b340cb67e0 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -193,7 +193,7 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): export_plugin.subset_format.selected = 'x' # Test that selecting disabled option raises an error - with pytest.raises(ValueError, match="Cannot export Subset 1 in ECSV format"): + with pytest.raises(ValueError, match="Cannot export Subset 1 in ecsv format, reverting selection to fits"): # noqa export_plugin.subset_format.selected = 'ecsv' # test that attempting to save a composite subset raises an error