Skip to content

Commit

Permalink
Disable export for unsupported units (spacetelescope#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay authored Apr 4, 2024
1 parent b4decc1 commit e023dad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ New Features
- "Export Plot" plugin is now replaced with the more general "Export" plugin. [#2722, #2782]

- "Export" plugin supports exporting plugin tables, plugin plots, data, and
non-composite spatial subsets.[#2755, #2774, #2760, #2772, #2770, #2780]
non-composite spatial subsets.[#2755, #2774, #2760, #2772, #2770, #2780, #2784]

- Opening a plugin in the tray (from the API or the toolbar buttons) now scrolls to that plugin.
[#2768]
Expand Down
3 changes: 3 additions & 0 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from jdaviz.core.events import AddDataMessage, SnackbarMessage
from jdaviz.core.user_api import PluginUserApi
from specutils import Spectrum1D
from astropy import units as u
from astropy.nddata import CCDData

try:
Expand Down Expand Up @@ -257,6 +258,8 @@ def _set_dataset_not_supported_msg(self, msg=None):
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 yet implemented for this type of data"
elif (data_unit := self.dataset.selected_obj.unit) == u.Unit('DN/s'):
self.data_invalid_msg = f'Export Disabled: The unit {data_unit} could not be saved in native FITS format.' # noqa: E501
else:
self.data_invalid_msg = ''
else:
Expand Down
20 changes: 20 additions & 0 deletions jdaviz/configs/default/plugins/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ def test_export_data(cubeviz_helper, spectrum1d_cube):
assert ep.data_invalid_msg == ''


def test_disable_export_for_unsupported_units(specviz2d_helper):
dn_per_s = u.DN / u.s
data = np.zeros((5, 10))
data[3] = np.arange(10)
data = Spectrum1D(flux=data*dn_per_s, spectral_axis=data[3]*u.um)
specviz2d_helper.load_data(data)

gs = specviz2d_helper.plugins["Gaussian Smooth"]
smooth_source_dataset = "Spectrum 1D"
gs.dataset = smooth_source_dataset
gs.stddev = 3
gs.smooth(add_data=True)

ep = specviz2d_helper.plugins["Export"]._obj
assert "Spectrum 1D smooth stddev-3.0" in ep.dataset.choices
ep.dataset_selected = "Spectrum 1D smooth stddev-3.0"
assert ep.dataset.selected_obj.unit == "DN/s"
assert ep.data_invalid_msg == "Export Disabled: The unit DN / s could not be saved in native FITS format." # noqa


class TestExportPluginPlots():

def test_basic_export_plugin_plots(tmp_path, imviz_helper):
Expand Down

0 comments on commit e023dad

Please sign in to comment.