From aade68d67d2968f6702172e2471f34b0577e0606 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Fri, 30 Aug 2024 14:17:45 -0400 Subject: [PATCH] review comment from Kyle --- CHANGES.rst | 2 +- jdaviz/configs/default/plugins/viewers.py | 6 ++++- .../ramp_extraction/ramp_extraction.py | 7 +++-- jdaviz/configs/rampviz/plugins/tools.py | 3 ++- jdaviz/configs/rampviz/plugins/viewers.py | 27 ++++++++++++------- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 65aa42d629..7fc6da3887 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ^^^^^^^ diff --git a/jdaviz/configs/default/plugins/viewers.py b/jdaviz/configs/default/plugins/viewers.py index f99c039d3e..e42527c5c0 100644 --- a/jdaviz/configs/default/plugins/viewers.py +++ b/jdaviz/configs/default/plugins/viewers.py @@ -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': + layer_state.visible = self._get_layer(layer_state.layer.data.label).visible + else: + # Rampviz doesn't show subset profiles by default: + layer_state.visible = False def _update_layer_icons(self): # update visible_layers (TODO: move this somewhere that can update on color change, etc) diff --git a/jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py b/jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py index 8ac008b22f..332334e586 100644 --- a/jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py +++ b/jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py @@ -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 = [ @@ -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 = ( @@ -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): diff --git a/jdaviz/configs/rampviz/plugins/tools.py b/jdaviz/configs/rampviz/plugins/tools.py index a50fe7ffbe..321955db42 100644 --- a/jdaviz/configs/rampviz/plugins/tools.py +++ b/jdaviz/configs/rampviz/plugins/tools.py @@ -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'])) @@ -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() diff --git a/jdaviz/configs/rampviz/plugins/viewers.py b/jdaviz/configs/rampviz/plugins/viewers.py index 63b5a59b7f..2c88da7b9a 100644 --- a/jdaviz/configs/rampviz/plugins/viewers.py +++ b/jdaviz/configs/rampviz/plugins/viewers.py @@ -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 @@ -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):