Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #2825 on branch v3.9.x (Re-enable exporting cubeviz spectrum viewer) #2828

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Bug Fixes
Cubeviz
^^^^^^^

- Re-enable support for exporting spectrum-viewer. [#2825]

Imviz
^^^^^

Expand Down
33 changes: 22 additions & 11 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -221,17 +222,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):
Expand Down Expand Up @@ -341,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
Expand Down
13 changes: 13 additions & 0 deletions jdaviz/configs/default/plugins/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading