Skip to content

Commit

Permalink
Merge pull request #3171 from bmorris3/rampviz-slider-reset-limits
Browse files Browse the repository at this point in the history
Rampviz fixes for unexpected viewer limit resets
  • Loading branch information
bmorris3 authored Aug 30, 2024
2 parents c46a0df + 8c1d2e8 commit 3a0aa4c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ New Features

- The standalone version of jdaviz now uses solara instead of voila, resulting in faster load times. [#2909]

- New configuration for ramp/Level 1 data products from Roman WFI and JWST [#3120, #3148, #3167]
- New configuration for ramp/Level 1 data products from Roman WFI and JWST [#3120, #3148, #3167, #3171]

Cubeviz
^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion jdaviz/configs/default/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ def _expected_subset_layer_default(self, layer_state):
return

# default visibility based on the visibility of the "parent" data layer
layer_state.visible = self._get_layer(layer_state.layer.data.label).visible
if self.__class__.__name__ == 'RampvizProfileView':
# Rampviz doesn't show subset profiles by default:
layer_state.visible = False
else:
layer_state.visible = self._get_layer(layer_state.layer.data.label).visible

def _update_layer_icons(self):
# update visible_layers (TODO: move this somewhere that can update on color change, etc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def _on_subset_update(self, msg={}):
if getattr(mark, 'label', None) != subset_lbl
] + marks

self.integration_viewer.reset_limits()

def _on_subset_delete(self, msg={}):
subset_lbl = msg.subset.label
self.integration_viewer.figure.marks = [
Expand All @@ -200,7 +202,6 @@ def _update_subset_previews(self, msg={}):
if not hasattr(self.app._jdaviz_helper, '_default_integration_viewer_reference_name'):
return

redraw_limits = False
for mark in self.integration_viewer.figure.marks:
if isinstance(mark, PluginLine) and mark.label is not None:
new_visibility = (
Expand All @@ -209,10 +210,8 @@ def _update_subset_previews(self, msg={}):
)
if mark.visible != new_visibility:
mark.visible = new_visibility
redraw_limits = True

if redraw_limits:
self.integration_viewer.reset_limits()
self.integration_viewer.reset_limits()

@property
def _subset_preview_visible(self):
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/rampviz/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RampPerPixel(ProfileFromCube):
def on_mouse_move(self, data):
if data['event'] == 'mouseleave':
self._mark.visible = False
self._reset_profile_viewer_bounds()
self._profile_viewer.reset_limits()
return

x = int(np.round(data['domain']['x']))
Expand All @@ -41,3 +41,4 @@ def on_mouse_move(self, data):
return
self._mark.update_xy(np.arange(y_values.size), y_values)
self._mark.visible = True
self._profile_viewer.reset_limits()
27 changes: 18 additions & 9 deletions jdaviz/configs/rampviz/plugins/viewers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from astropy.nddata import NDDataArray
from glue.core import BaseData
from glue.core.subset import Subset
from glue_jupyter.bqplot.image import BqplotImageView

from jdaviz.configs.default.plugins.viewers import JdavizViewerMixin, JdavizProfileView
Expand Down Expand Up @@ -36,21 +37,29 @@ def _initialize_x_axis(self):
self.reset_limits()

def reset_limits(self):
super().reset_limits()

# override to reset to the global y limits including marks:
global_y_min = float(self.state.y_min)
global_y_max = float(self.state.y_max)
global_y_min = np.inf
global_y_max = -np.inf
for mark in self.figure.marks:
if len(mark.y) and mark.visible:
global_y_min = min(global_y_min, np.nanmin(mark.y))
global_y_max = max(global_y_max, np.nanmax(mark.y))

if global_y_min != self.state.y_min or global_y_max != self.state.y_max:
self.set_limits(
y_min=global_y_min * 0.9,
y_max=global_y_max * 1.1
)
for layer in self.state.layers:
if not isinstance(layer.layer, Subset) and layer.visible:
component = layer.layer.main_components[0]
layer_y_min = layer.layer.get_component(component).data.min()
layer_y_max = layer.layer.get_component(component).data.max()

global_y_min = min(global_y_min, layer_y_min)
global_y_max = max(global_y_max, layer_y_max)

y_buffer = 0.1

y_min = (1 - y_buffer) * global_y_min
y_max = (1 + y_buffer) * global_y_max
if y_min != self.state.y_min or y_max != self.state.y_max:
self.set_limits(y_min=y_min, y_max=y_max)

def set_plot_axes(self):

Expand Down

0 comments on commit 3a0aa4c

Please sign in to comment.