Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Mar 21, 2024
1 parent 2e42b8f commit 717635e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 64 deletions.
22 changes: 18 additions & 4 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from glue_jupyter.bqplot.image import BqplotImageView

from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty
from glue.core.message import SubsetCreateMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, SelectPluginComponent,
ViewerSelectMixin, DatasetMultiSelectMixin,
Expand Down Expand Up @@ -68,8 +69,8 @@ class Export(PluginTemplateMixin, ViewerSelectMixin,

filename = Unicode().tag(sync=True)

# to trigger an overlay warning that exporting is not yet available for selected item
not_supported_warn = Bool(False).tag(sync=True)
# if selected subset is spectral or composite, display message and disable export
subset_invalid_msg = Unicode().tag(sync=True)

# For Cubeviz movie.
movie_enabled = Bool(False).tag(sync=True)
Expand Down Expand Up @@ -119,8 +120,7 @@ def __init__(self, *args, **kwargs):
self.subset = SubsetSelect(self,
'subset_items',
'subset_selected',
default_mode='empty',
filters=['is_spatial'])
default_mode='empty')

# default selection:
self.dataset._default_mode = 'empty'
Expand All @@ -132,6 +132,9 @@ def __init__(self, *args, **kwargs):
if self.config == "cubeviz":
self.session.hub.subscribe(self, AddDataMessage, handler=self._on_cubeviz_data_added) # noqa: E501

# self.hub.subscribe(self, SubsetCreateMessage,
# handler=lambda _: self._sync_singleselect(event=''))

@property
def user_api(self):
# TODO: backwards compat for save_figure, save_movie,
Expand Down Expand Up @@ -186,6 +189,16 @@ def _sync_singleselect(self, event):
if name != attr:
setattr(self, attr, '')

if attr =='subset_selected':
# check if subset is spectral or composite, and disable export and warn
# until this is supported
subset = self.app.get_subsets(self.subset.selected)
if self.app._is_subset_spectral(subset[0]):
self.subset_invalid_msg = 'Export for spectral subsets not supported.'
if len(subset) > 1:
self.subset_invalid_msg = 'Export for composite subsets not supported.'


@with_spinner()
def export(self, filename=None, show_dialog=None):
"""
Expand Down Expand Up @@ -459,6 +472,7 @@ def save_subset_as_region(self, selected_subset_label, filename):
region = region[0][f'{"sky_" if link_type == "wcs" else ""}region']

region.write(filename, overwrite=True)


def vue_interrupt_recording(self, *args): # pragma: no cover
self.movie_interrupt = True
Expand Down
81 changes: 30 additions & 51 deletions jdaviz/configs/default/plugins/export/export.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,56 +89,35 @@
</plugin-inline-select>
</div>

<div style="display: grid; position: relative"> <!-- overlay container -->
<div style="grid-area: 1/1">
<div v-if="subset_items.length > 0">

<j-plugin-section-header style="margin-top: 12px">Subsets</j-plugin-section-header>
<plugin-inline-select
:items="subset_items"
:selected.sync="subset_selected"
:multiselect="multiselect"
:single_select_allow_blank="true"
>
</plugin-inline-select>
</div>
<v-row v-if="subset_selected" class="row-min-bottom-padding">
<v-select
:menu-props="{ left: true }"
attach
v-model="subset_format_selected"
:items="subset_format_items.map(i => i.label)"
label="Format"
hint="Format for exporting subsets."
persistent-hint
>
</v-select>
</v-row>

<v-overlay
absolute
opacity=1.0
:value="not_supported_warn"
:zIndex=3
style="grid-area: 1/1;
margin-left: -24px;
margin-right: -24px">

<v-card color="transparent" elevation=0 >
<v-card-text width="100%">
<div class="white--text">
Exporting composite subsets is not supported.
</div>
</v-card-text>
<div v-if="subset_items.length > 0">
<j-plugin-section-header style="margin-top: 12px">Subsets</j-plugin-section-header>
<plugin-inline-select
:items="subset_items"
:selected.sync="subset_selected"
:multiselect="multiselect"
:single_select_allow_blank="true"
>
</plugin-inline-select>
</div>

<v-card-actions>
<v-row justify="end">
<v-btn tile small color="primary" class="mr-2" @click="not_supported_warn=false">OK</v-btn>
</v-row>
</v-card-actions>
</v-card>
<v-row v-if="subset_invalid_msg.length > 0">
<span class="v-messages v-messages__message text--secondary" style="color: red !important">
{{subset_invalid_msg}}
</span>
</v-row>

</v-overlay>
<v-row v-if="subset_selected" class="row-min-bottom-padding">
<v-select
:menu-props="{ left: true }"
attach
v-model="subset_format_selected"
:items="subset_format_items.map(i => i.label)"
label="Format"
hint="Format for exporting subsets."
persistent-hint
>
</v-select>
</v-row>

<div v-if="table_items.length > 0">
<j-plugin-section-header style="margin-top: 12px">Plugin Tables</j-plugin-section-header>
Expand Down Expand Up @@ -192,7 +171,7 @@
:results_isolated_to_plugin="true"
@click="interrupt_recording"
:disabled="!movie_recording"
>
traitlets.String>
<v-icon>stop</v-icon>
</plugin-action-button>
</j-tooltip>
Expand All @@ -202,13 +181,13 @@
@click="export_from_ui"
:spinner="spinner"
:disabled="filename.length === 0 ||
movie_recording ||
movie_recording ||
subset_invalid_msg.length > 0 ||
(viewer_selected.length > 0 && viewer_format_selected == 'mp4' && !movie_enabled)"
>
Export
</plugin-action-button>
</v-row>


</j-tray-plugin>
</template>
43 changes: 34 additions & 9 deletions jdaviz/configs/default/plugins/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from astropy.io import fits
from astropy.nddata import NDData
import astropy.units as u
from glue.core.edit_subset_mode import AndMode
from glue.core.roi import CircularROI
from glue.core.edit_subset_mode import AndMode, NewMode
from glue.core.roi import CircularROI, XRangeROI
from regions import Regions, CircleSkyRegion
from specutils import Spectrum1D

Expand All @@ -31,6 +31,7 @@ def test_basic_export_subsets_imviz(self, tmp_path, imviz_helper):
export_plugin.subset.selected = 'Subset 1'

assert export_plugin.subset_format.selected == 'fits' # default format
assert export_plugin.subset_invalid_msg == '' # for non-composite spatial

export_plugin.export()
assert os.path.isfile('imviz_export.fits')
Expand Down Expand Up @@ -65,14 +66,36 @@ def test_basic_export_subsets_imviz(self, tmp_path, imviz_helper):
match=re.escape("x not one of ['fits', 'reg'], reverting selection to reg")): # noqa
export_plugin.subset_format.selected = 'x'

# test that attempting to save a composite subset raises an error
imviz_helper.app.session.edit_subset_mode.mode = AndMode
imviz_helper.app.get_viewer('imviz-0').apply_roi(CircularROI(xc=255, yc=255, radius=50))
imviz_helper.app.get_viewer('imviz-0').apply_roi(CircularROI(xc=200, yc=250, radius=50))

with pytest.raises(NotImplementedError,
match='Export not yet supported for composite subsets.'):
export_plugin.export()
def test_not_implemented(self, cubeviz_helper, spectral_cube_wcs):
"""
Test that trying to export non-supported subsets
(spectral and composite) produces
the correct warning message to display in UI).
"""

data = Spectrum1D(flux=np.ones((500, 500, 2)) * u.nJy,
wcs=spectral_cube_wcs)
cubeviz_helper.load_data(data)

cubeviz_helper.app.get_viewer('flux-viewer').apply_roi(CircularROI(xc=255,
yc=255,
radius=50))
cubeviz_helper.app.session.edit_subset_mode.mode = AndMode
cubeviz_helper.app.get_viewer('flux-viewer').apply_roi(CircularROI(xc=200,
yc=250,
radius=50))

export_plugin = cubeviz_helper.plugins['Export']._obj
export_plugin.subset.selected = 'Subset 1'

assert export_plugin.subset_invalid_msg == 'Export for composite subsets not supported.'

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.'

def test_export_subsets_wcs(self, tmp_path, imviz_helper, spectral_cube_wcs):

Expand All @@ -94,6 +117,8 @@ def test_export_subsets_wcs(self, tmp_path, imviz_helper, spectral_cube_wcs):
export_plugin = imviz_helper.plugins['Export']._obj
export_plugin.subset.selected = 'Subset 1'

assert export_plugin.subset_invalid_msg == '' # for non-composite spatial

# test changing link type results in an output file with a sky region
export_plugin.filename = 'sky_region'
export_plugin.subset_format.selected = 'reg'
Expand Down

0 comments on commit 717635e

Please sign in to comment.