Skip to content

Commit

Permalink
Merge pull request #1208 from kecnry/per-viewer-uncertainty-toggle
Browse files Browse the repository at this point in the history
Per viewer uncertainty toggle
  • Loading branch information
pllim authored Mar 29, 2022
2 parents b42d67b + 5be55f7 commit 0712a8c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Mosviz
Specviz
^^^^^^^

- Exposed toggle in Plot Options plugin for viewing uncertainties. [#1189]
- Exposed toggle in Plot Options plugin for viewing uncertainties. [#1189, #1208]

API Changes
-----------
Expand Down
27 changes: 13 additions & 14 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from traitlets import Any, observe, Bool
from ipywidgets.widgets import widget_serialization

from jdaviz.configs.specviz.plugins.viewers import SpecvizProfileView
from jdaviz.core.events import AddDataMessage, RemoveDataMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import TemplateMixin, ViewerSelectMixin
Expand All @@ -15,7 +16,9 @@ class PlotOptions(TemplateMixin, ViewerSelectMixin):
viewer_widget = Any().tag(sync=True, **widget_serialization)
layer_widget = Any().tag(sync=True, **widget_serialization)

# Toggle for showing uncertainty in viewer
# Whether the currently selected viewer has the ability to toggle uncertainty
has_show_uncertainty = Bool(False).tag(sync=True)
# Toggle for showing uncertainty in the currently selected viewer
show_uncertainty = Bool(False).tag(sync=True)

def __init__(self, *args, **kwargs):
Expand All @@ -39,24 +42,20 @@ def _viewer_selected_changed(self, event={}):
return

viewer = self.viewer.selected_obj
self.has_show_uncertainty = isinstance(viewer, SpecvizProfileView)
if self.has_show_uncertainty:
# TODO: refactor so that an API call to viewer.show_uncertainties, which would
# set viewer.display_uncertainties would then update the widget state.
self.show_uncertainty = viewer.display_uncertainties
self.viewer_widget = viewer.viewer_options
self.layer_widget = viewer.layer_options

@observe("show_uncertainty")
def _toggle_uncertainty(self, event):
if self.app.state.settings.get("configuration") == "cubeviz":
viewer = "cubeviz-3"
elif self.app.state.settings.get("configuration") == "specviz":
viewer = "specviz-0"
elif self.app.state.settings.get("configuration") == "specviz2d":
viewer = "specviz2d-1"
elif self.app.state.settings.get("configuration") == "mosviz":
viewer = "mosviz-2"
else:
if not self.has_show_uncertainty:
# the currently selected viewer does not support uncertainties
return
spec_viewer = self.app.get_viewer_by_id(viewer)

if self.show_uncertainty:
spec_viewer.show_uncertainties()
self.viewer.selected_obj.show_uncertainties()
else:
spec_viewer._clean_error()
self.viewer.selected_obj._clean_error()
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<jupyter-widget v-if="viewer_selected" :widget="viewer_widget"></jupyter-widget>
</v-row>

<v-row v-if="['specviz', 'mosviz', 'specviz2d', 'cubeviz'].indexOf(config)!==-1">
<v-row v-if="has_show_uncertainty">
<v-switch
v-model="show_uncertainty"
label="Plot Uncertainty"
Expand Down

0 comments on commit 0712a8c

Please sign in to comment.