Skip to content

Commit

Permalink
fix type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Dec 19, 2024
1 parent a0d77f5 commit fa6fb8b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Bug Fixes

- Fixed broken histogram pan/zoom in Plot Options plugin. [#3361]

- Fixed bug with Plot Options select_all when data is float32. [#3366]


Cubeviz
^^^^^^^
- Removed the deprecated ``save as fits`` option from the Collapse, Moment Maps, and Spectral Extraction plugins; use the Export plugin instead. [#3256]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,30 @@ def test_segmentation_image(imviz_helper):
assert plot_opts.stretch_function.value == 'linear'
assert plot_opts.image_bias.value == 0.5
assert plot_opts.image_contrast.value == 1.0


def test_imviz_select_all_layers(imviz_helper):
"""
Test to catch a (fixed) bug that was revealed when trying to select
all layers when data is float32. This was caused when trying to set
`stretch_vmin_value`.
"""

arr = np.arange(36.).reshape(6, 6).astype(np.float32)

# load three images in one viewer
with imviz_helper.batch_load():
for i in range(3):
imviz_helper.load_data(arr, data_label=f"data_{i}")

plot_options = imviz_helper.plugins['Plot Options']

plot_options.layer.multiselect = True
plot_options.select_all()

# all layers selected, set stretch function to log for all
plot_options.stretch_function = 'log'

# and make sure each layer picked up this change
for layer in plot_options.image_colormap.linked_states:
assert layer.as_dict()['stretch'] == 'log'
27 changes: 11 additions & 16 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4401,22 +4401,16 @@ def is_mixed(self, glue_values):
return len(np.unique(glue_values, axis=0)) > 1

def _update_mixed_state(self):
if len(self.linked_states) <= 1:
mixed = False
else:

if len(self.linked_states) >= 1:
current_glue_values = []
for state in self.linked_states:
current_glue_values.append(self._get_glue_value(state))
mixed = self.is_mixed(current_glue_values)
# ensure the value corresponds to the first entry, this prevents the case where a glue
# change to one of the linked_states changes the value that will be adopted when
# unmixing something in mixed state and results in more consistent and predictable
# behavior
self._processing_change_from_glue = True
self.value = current_glue_values[0]
self._processing_change_from_glue = False
self.sync = {**self.sync,
'mixed': mixed}

if len(current_glue_values) and current_glue_values[0] is not None:
# sync the initial value of the widget, avoiding recursion
self._on_glue_value_changed(current_glue_values[0],
update_mixed_state=False)

def _on_value_changed(self, msg):
if self._processing_change_from_glue:
Expand Down Expand Up @@ -4477,7 +4471,7 @@ def _on_glue_layer_visible_changed(self, value):
self._processing_change_from_glue = False
self._update_mixed_state()

def _on_glue_value_changed(self, value):
def _on_glue_value_changed(self, value, update_mixed_state=True):
if self._glue_name in ('color_mode', 'linewidth'):
# then we need to force updates to the layer-icon colors
# NOTE: this will only trigger when the change to color_mode was handled
Expand Down Expand Up @@ -4512,8 +4506,9 @@ def _on_glue_value_changed(self, value):
# it is not skipped if it has already been called since an actual traitlet change)
self.plugin._update_stretch_curve()

# need to recompute mixed state
self._update_mixed_state()
if update_mixed_state:
# recompute mixed state
self._update_mixed_state()
self._processing_change_from_glue = False

def unmix_state(self, new_value=None):
Expand Down

0 comments on commit fa6fb8b

Please sign in to comment.