Skip to content

Commit

Permalink
API access (hidden) to disable moment map server-side saving (spacete…
Browse files Browse the repository at this point in the history
…lescope#2469)

* optionally disable moment map server-side saving
  • Loading branch information
kecnry authored and bmorris3 committed Sep 22, 2023
1 parent a7a5aec commit 2ae34ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 14 additions & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class MomentMap(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMix
moment_available = Bool(False).tag(sync=True)
overwrite_warn = Bool(False).tag(sync=True)

# export_enabled controls whether saving the moment map to a file is enabled via the UI. This
# is a temporary measure to allow server-installations to disable saving server-side until
# saving client-side is supported
export_enabled = Bool(True).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand All @@ -58,6 +63,11 @@ def __init__(self, *args, **kwargs):
self.dataset.add_filter('is_cube')
self.add_results.viewer.filters = ['is_image_viewer']

if self.app.state.settings.get('server_is_remote', False):
# when the server is remote, saving the file in python would save on the server, not
# on the user's machine, so export support in cubeviz should be disabled
self.export_enabled = False

@property
def _default_image_viewer_reference_name(self):
return self.jdaviz_helper._default_image_viewer_reference_name
Expand Down Expand Up @@ -138,6 +148,10 @@ def vue_overwrite_fits(self, *args):
def _write_moment_to_fits(self, overwrite=False, *args):
if self.moment is None or not self.filename: # pragma: no cover
return
if not self.export_enabled:
# this should never be triggered since this is intended for UI-disabling and the
# UI section is hidden, but would prevent any JS-hacking
raise ValueError("Writing out moment map to file is currently disabled")

# Make sure file does not end up in weird places in standalone mode.
path = os.path.dirname(self.filename)
Expand Down
6 changes: 3 additions & 3 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
@click:action="calculate_moment"
></plugin-add-results>

<j-plugin-section-header>Results</j-plugin-section-header>
<j-plugin-section-header v-if="export_enabled">Results</j-plugin-section-header>

<div style="display: grid; position: relative"> <!-- overlay container -->
<div style="grid-area: 1/1">
<div v-if="moment_available">
<div v-if="moment_available && export_enabled">
<v-row>
<v-text-field
v-model="filename"
Expand All @@ -77,7 +77,7 @@
<v-overlay
absolute
opacity=1.0
:value="overwrite_warn"
:value="overwrite_warn && export_enabled"
:zIndex=3
style="grid-area: 1/1;
margin-left: -24px;
Expand Down
5 changes: 4 additions & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_valid_function(cubeviz_helper, spectrum1d_cube):
assert cubeviz_helper.specviz.get_data(data_label="test[FLUX]").flux.ndim == 1


def test_remote_server_disable_movie():
def test_remote_server_disable_save_serverside():
config = get_configuration('cubeviz')
config['settings']['server_is_remote'] = True

Expand All @@ -82,6 +82,9 @@ def test_remote_server_disable_movie():
ep = cubeviz_helper.plugins['Export Plot']
assert ep._obj.movie_enabled is False

mm = cubeviz_helper.plugins['Moment Maps']
assert mm._obj.export_enabled is False


def test_get_data_spatial_and_spectral(cubeviz_helper, spectrum1d_cube_larger):
data_label = "test"
Expand Down

0 comments on commit 2ae34ac

Please sign in to comment.