Skip to content

Commit

Permalink
DNM: add global_limits as callback to ImageViewerState
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Mar 21, 2024
1 parent 5f45250 commit 2e08899
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions glue/viewers/image/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class ImageViewerState(MatplotlibDataViewerState):
'a single color (``One color per layer``)')

dpi = DDCProperty(72, docstring='The resolution (in dots per inch) of density maps, if present')
global_limits = DDCProperty(True, docstring='Calculate automatic levels on statistics '
'over the entire data cube or only the '
'current layer')

def __init__(self, **kwargs):

Expand Down Expand Up @@ -121,6 +124,8 @@ def __init__(self, **kwargs):
self.add_callback('x_att_world', self._on_xatt_world_change, priority=1000)
self.add_callback('y_att_world', self._on_yatt_world_change, priority=1000)

self.add_callback('global_limits', self._set_global_limits, priority=0)

aspect_display = {'equal': 'Square Pixels', 'auto': 'Automatic'}
ImageViewerState.aspect.set_choices(self, ['equal', 'auto'])
ImageViewerState.aspect.set_display_func(self, aspect_display.get)
Expand Down Expand Up @@ -315,6 +320,28 @@ def _set_default_slices(self):
else:
self.slices = (0,) * self.reference_data.ndim

def _set_global_limits(self, global_limits=True):
layer_state = self.layers[-1]
if global_limits:
self.remove_callback('slices', self._update_slice_subset)
layer_state.attribute_lim_helper.set_slice(None)

Check warning on line 327 in glue/viewers/image/state.py

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L324-L327

Added lines #L324 - L327 were not covered by tests
else:
self.add_callback('slices', self._update_slice_subset)
layer_state.attribute_lim_helper.set_slice(self.numpy_slice_aggregation_transpose[0])

Check warning on line 330 in glue/viewers/image/state.py

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L329-L330

Added lines #L329 - L330 were not covered by tests

def _update_slice_subset(self, slices):
"""
Select a subset slice for determining image levels.
Parameters
----------
slices : iterable of :class:`slice` or `None`
An iterable containing :class:`slice` objects that can instantiate
a :class:`~glue.core.subset.SliceSubsetState` and has to be consistent
with the shape of `self.data`; `None` to unslice.
"""
self.layers[-1].attribute_lim_helper.set_slice(self.numpy_slice_aggregation_transpose[0])

Check warning on line 343 in glue/viewers/image/state.py

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L343

Added line #L343 was not covered by tests

@property
def numpy_slice_aggregation_transpose(self):
"""
Expand Down Expand Up @@ -572,19 +599,6 @@ def flip_limits(self):
"""
self.attribute_lim_helper.flip_limits()

def set_slice(self, slices):
"""
Select a subset slice for determining image levels.
Parameters
----------
slices : iterable of :class:`slice` or `None`
An iterable containing :class:`slice` objects that can instantiate
a :class:`~glue.core.subset.SliceSubsetState` and has to be consistent
with the shape of `self.data`; `None` to unslice.
"""
self.attribute_lim_helper.set_slice(slices)

def reset_contrast_bias(self):
with delay_callback(self, 'contrast', 'bias'):
self.contrast = 1
Expand Down

0 comments on commit 2e08899

Please sign in to comment.