From 479d17f8a14e84f44d3e488ee69fc40302861ef4 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 23 Apr 2024 08:30:56 -0400 Subject: [PATCH 1/3] enable option to export spectrum viewer in cubeviz --- jdaviz/configs/default/plugins/export/export.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 094a70ea0b..4c798dcda6 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -221,17 +221,6 @@ def _sync_singleselect(self, event): self._set_subset_not_supported_msg() if attr == 'dataset_selected': self._set_dataset_not_supported_msg() - elif self.config == "cubeviz" and attr == "viewer_selected": - self._disable_viewer_format_combo(event) - - @observe('viewer_format_selected') - def _disable_viewer_format_combo(self, event): - if (self.config == "cubeviz" and self.viewer_selected == "spectrum-viewer" - and self.viewer_format_selected == "png"): - msg = "Exporting the spectrum viewer as a PNG in Cubeviz is not yet supported" - else: - msg = "" - self.viewer_invalid_msg = msg @observe('filename') def _is_filename_changed(self, event): From efd92402acf2a0dc67c5cbc72e4a343015c4dabf Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 23 Apr 2024 08:56:42 -0400 Subject: [PATCH 2/3] temporarily "clean" incompatible marks by removing any unicode characters and restoring after export --- CHANGES.rst | 2 ++ .../configs/default/plugins/export/export.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index cf5e968799..ec9728b153 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -75,6 +75,8 @@ Bug Fixes Cubeviz ^^^^^^^ +- Re-enable support for exporting spectrum-viewer. [#2825] + Imviz ^^^^^ diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index 4c798dcda6..0d91d410c2 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -5,6 +5,7 @@ from glue_jupyter.bqplot.image import BqplotImageView from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty +from jdaviz.core.marks import ShadowMixin from jdaviz.core.registries import tray_registry from jdaviz.core.template_mixin import (PluginTemplateMixin, SelectPluginComponent, ViewerSelectMixin, DatasetMultiSelectMixin, @@ -330,11 +331,32 @@ def export(self, filename=None, show_dialog=None, overwrite=False, raise FileExistsError(f"{filename} exists but overwrite=False") return + # temporarily "clean" incompatible marks of unicode characters, etc + restores = [] + for mark in viewer.figure.marks: + restore = {} + if len(getattr(mark, 'text', [])): + if not isinstance(mark, ShadowMixin): + # if it is shadowing another mark, that will automatically get updated + # when the other mark is restored, but we'll still ensure that the mark + # is clean of unicode before exporting. + restore['text'] = [t for t in mark.text] + mark.text = [t.strip() for t in mark.text] + if len(getattr(mark, 'labels', [])): + restore['labels'] = mark.labels[:] + mark.labels = [lbl.strip() for lbl in mark.labels] + restores.append(restore) + if filetype == "mp4": self.save_movie(viewer, filename, filetype) else: self.save_figure(viewer, filename, filetype, show_dialog=show_dialog) + # restore marks to their original state + for restore, mark in zip(restores, viewer.figure.marks): + for k, v in restore.items(): + setattr(mark, k, v) + elif len(self.plugin_plot.selected): plot = self.plugin_plot.selected_obj._obj filetype = self.plugin_plot_format.selected From 929ec1e91e25c76dc1bc1aa8350e29527160c930 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 23 Apr 2024 11:19:36 -0400 Subject: [PATCH 3/3] test coverage --- .../default/plugins/export/tests/test_export.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jdaviz/configs/default/plugins/export/tests/test_export.py b/jdaviz/configs/default/plugins/export/tests/test_export.py index a321befa7c..d4729a6f4a 100644 --- a/jdaviz/configs/default/plugins/export/tests/test_export.py +++ b/jdaviz/configs/default/plugins/export/tests/test_export.py @@ -203,6 +203,19 @@ def test_basic_export_subsets_cubeviz(self, cubeviz_helper, spectral_cube_wcs): export_plugin.export() +@pytest.mark.usefixtures('_jail') +def test_export_cubeviz_spectrum_viewer(cubeviz_helper, spectrum1d_cube): + cubeviz_helper.load_data(spectrum1d_cube, data_label='test') + + ep = cubeviz_helper.plugins["Export"] + ep.viewer = 'spectrum-viewer' + ep.viewer_format = 'png' + ep.export() + + ep.viewer_format = 'svg' + ep.export() + + @pytest.mark.usefixtures('_jail') def test_export_data(cubeviz_helper, spectrum1d_cube): cubeviz_helper.load_data(spectrum1d_cube, data_label='test')