Skip to content

Commit

Permalink
Add slices callback from self.viewer_state
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Apr 1, 2024
1 parent 1f738f9 commit a2ac49b
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions glue/viewers/image/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DeferredDrawSelectionCallbackProperty as DDSCProperty)
from glue.core.state_objects import StateAttributeLimitsHelper
from glue.utils import defer_draw, view_shape
from echo import callback_property, delay_callback
from echo import delay_callback
from glue.core.data_combo_helper import ManualDataComboHelper, ComponentIDComboHelper
from glue.core.exceptions import IncompatibleDataException
from glue.viewers.common.stretch_state_mixin import StretchStateMixin
Expand Down Expand Up @@ -572,49 +572,24 @@ def _get_image(self, view=None):

def _set_global_limits(self, global_limits=True):
if global_limits:
self.remove_callback('slice_subset_state', self._update_slice_subset)
self.viewer_state.remove_callback('slices', self._update_slice_subset)
self.attribute_lim_helper.set_slice(None)

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

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L574-L576

Added lines #L574 - L576 were not covered by tests
else:
self.add_callback('slice_subset_state', self._update_slice_subset)
slices = [slice(s) if s is None else s for s in self.slice_subset_state]
self.attribute_lim_helper.set_slice(slices)
self.viewer_state.add_callback('slices', self._update_slice_subset)
self.attribute_lim_helper.set_slice(self.viewer_state.numpy_slice_aggregation_transpose[0])

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

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L578-L579

Added lines #L578 - L579 were not covered by tests

def _update_slice_subset(self, slice_subset_state):
def _update_slice_subset(self, slices):
"""
Select a subset slice for determining image levels.
Parameters
----------
slice_subset_state : iterable of :class:`slice` or `None`
slice : 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.
"""
slices = [slice(s) if s is None else s for s in slice_subset_state]
self.attribute_lim_helper.set_slice(slices)

@callback_property
def slice_subset_state(self):
"""
Returns slicing information usable by :class:`~glue.core.subset.SliceSubsetState`.
slice_subset_state = DDCProperty(docstring='Slices iterable describing the current '
'slice along all dimensions as subset')
"""
# Need a safety check here if self.viewer_state is already fully initialised.
if self.viewer_state.reference_data is None or self.viewer_state.x_att is None:
return None
else:
slices = []
for i in range(self.viewer_state.reference_data.ndim):
if i == self.viewer_state.x_att.axis or i == self.viewer_state.y_att.axis:
slices.append(None)
else:
if isinstance(self.viewer_state.slices[i], AggregateSlice):
slices.append(self.viewer_state.slices[i].slice)
else:
slices.append(self.viewer_state.slices[i])
return slices # self.viewer_state.numpy_slice_aggregation_transpose[0]
self.attribute_lim_helper.set_slice(self.viewer_state.numpy_slice_aggregation_transpose[0])

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

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/state.py#L592

Added line #L592 was not covered by tests

def flip_limits(self):
"""
Expand Down

0 comments on commit a2ac49b

Please sign in to comment.