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

stretch_global switch in plot options #2814

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 20 additions & 3 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class PlotOptions(PluginTemplateMixin):
not exposed for Specviz
* ``stretch_preset`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
not exposed for Specviz
* ``stretch_global`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
Whether to apply the stretch preset based on the data in entire cube (as opposed
to the currently selected slice). Only exposed for Cubeviz.
* ``stretch_vmin`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
not exposed for Specviz
* ``stretch_vmax`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
Expand Down Expand Up @@ -326,6 +329,9 @@ class PlotOptions(PluginTemplateMixin):
stretch_preset_value = Any().tag(sync=True) # glue will pass either a float or string
stretch_preset_sync = Dict().tag(sync=True)

stretch_global_value = Bool().tag(sync=True)
stretch_global_sync = Dict().tag(sync=True)

stretch_vstep = Float(0.1).tag(sync=True) # dynamic based on full range from image

stretch_vmin_value = Float().tag(sync=True)
Expand Down Expand Up @@ -439,6 +445,9 @@ def supports_line(state):
def is_image(state):
return isinstance(state, BqplotImageLayerState)

def is_image_cube(state):
return is_image(state) and state.layer.ndim == 3

def not_image(state):
return not is_image(state)

Expand Down Expand Up @@ -563,6 +572,9 @@ def state_attr_for_line_visible(state):
self.stretch_preset = PlotOptionsSyncState(self, self.viewer, self.layer, 'percentile',
'stretch_preset_value', 'stretch_preset_sync',
state_filter=is_image)
self.stretch_global = PlotOptionsSyncState(self, self.viewer, self.layer, 'stretch_global',
'stretch_global_value', 'stretch_global_sync',
state_filter=is_image_cube)
self.stretch_vmin = PlotOptionsSyncState(self, self.viewer, self.layer, 'v_min',
'stretch_vmin_value', 'stretch_vmin_sync',
state_filter=is_image)
Expand Down Expand Up @@ -683,7 +695,7 @@ def user_api(self):
expose = ['multiselect', 'viewer', 'viewer_multiselect', 'layer', 'layer_multiselect',
'select_all', 'subset_visible']
if self.config == "cubeviz":
expose += ['collapse_function', 'uncertainty_visible']
expose += ['collapse_function', 'uncertainty_visible', 'stretch_global']
if self.config != "imviz":
expose += ['x_min', 'x_max', 'y_min', 'y_max',
'axes_visible', 'line_visible', 'line_color', 'line_width', 'line_opacity',
Expand Down Expand Up @@ -890,7 +902,7 @@ def _update_stretch_hist_sync(self, msg={}):
'mixed': bool(np.any([sync.get('mixed', False) for sync in all_syncs]))} # noqa

@observe('is_active', 'layer_selected', 'viewer_selected',
'stretch_hist_zoom_limits')
'stretch_hist_zoom_limits', 'stretch_global_value')
@skip_if_no_updates_since_last_active()
@with_spinner('stretch_hist_spinner')
def _update_stretch_histogram(self, msg={}):
Expand Down Expand Up @@ -974,6 +986,8 @@ def _update_stretch_histogram(self, msg={}):
y_min = max(y_limits.min(), 0)
y_max = y_limits.max()
arr = comp.data[y_min:y_max, x_min:x_max]
if hasattr(viewer, 'slice') and not self.stretch_global_value:
arr = arr.take(viewer.slice, viewer.slice_index)
if self.config == "imviz":
# Downsample input data to about 400px (as per compass.vue) for performance.
xstep = max(1, round(arr.shape[1] / 400))
Expand Down Expand Up @@ -1006,7 +1020,10 @@ def _update_stretch_histogram(self, msg={}):
arr = comp[::ystep, ::xstep]
else:
# include all data, regardless of zoom limits
arr = comp.data
if hasattr(viewer, 'slice') and not self.stretch_global_value:
arr = comp.data.take(viewer.slice, viewer.slice_index)
else:
arr = comp.data
sub_data = arr.ravel()

# filter out nans (or else bqplot will fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,15 @@
></v-select>
</glue-state-sync-wrapper>

<glue-state-sync-wrapper :sync="stretch_global_sync" :multiselect="layer_multiselect" @unmix-state="unmix_state('stretch_global')">
<v-switch
v-model="stretch_global_value"
label="Global stretch"
hint="Determine stretch from stretch preset and display stretch histogram based on data of entire cube (instead of currently selected slice)."
:persistent-hint="true"
/>
</glue-state-sync-wrapper>

<!-- for multiselect, show vmin/max here, otherwise they'll be in the "more stretch options" expandable section -->
<glue-state-sync-wrapper v-if="layer_multiselect" :sync="stretch_vmin_sync" :multiselect="layer_multiselect" @unmix-state="unmix_state('stretch_vmin')">
<v-text-field
Expand Down
Loading