diff --git a/CHANGES.md b/CHANGES.md index a5536479b..daa419706 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -68,7 +68,7 @@ v0.13.0 (unreleased) * EditSubsetMode is now no longer a singleton class and is instead instantiated at the Application/Session level. [#1538] -* Improve performance of image viewer. [#1558] +* Improve performance of image viewer. [#1558, #1562] v0.12.4 (unreleased) -------------------- diff --git a/glue/utils/array.py b/glue/utils/array.py index ebc51a1e5..e18bb35a5 100644 --- a/glue/utils/array.py +++ b/glue/utils/array.py @@ -64,7 +64,8 @@ def view_shape(shape, view): """ Return the shape of a view of an array. - Returns equivalent of ``np.zeros(shape)[view].shape`` + Returns equivalent of ``np.zeros(shape)[view].shape`` but with minimal + memory usage. Parameters ---------- @@ -75,11 +76,8 @@ def view_shape(shape, view): """ if view is None: return shape - shp = tuple(slice(0, s, 1) for s in shape) - xy = np.broadcast_arrays(*np.ogrid[shp]) - assert xy[0].shape == shape - - return xy[0][view].shape + else: + return np.broadcast_to(1, shape)[view].shape def stack_view(shape, *views): diff --git a/glue/viewers/image/composite_array.py b/glue/viewers/image/composite_array.py index 25c6ea653..6a6ab591b 100644 --- a/glue/viewers/image/composite_array.py +++ b/glue/viewers/image/composite_array.py @@ -5,10 +5,13 @@ import numpy as np +from glue.utils import view_shape + from matplotlib.colors import ColorConverter, Colormap from astropy.visualization import (LinearStretch, SqrtStretch, AsinhStretch, LogStretch, ManualInterval, ContrastBiasStretch) + __all__ = ['CompositeArray'] COLOR_CONVERTER = ColorConverter() @@ -156,7 +159,7 @@ def __getitem__(self, view): if self.shape is None: return None else: - img = np.zeros(self.shape + (4,))[view] + img = np.zeros(view_shape(self.shape, view) + (4,)) else: img = np.clip(img, 0, 1) diff --git a/glue/viewers/image/layer_artist.py b/glue/viewers/image/layer_artist.py index 05de7dcd5..807c10f3e 100644 --- a/glue/viewers/image/layer_artist.py +++ b/glue/viewers/image/layer_artist.py @@ -280,25 +280,21 @@ def shape(self): full_shape = self.layer_state.layer.shape return full_shape[y_axis], full_shape[x_axis] - @property - def nan_array(self): - return np.ones(self.shape) * np.nan - def __getitem__(self, view=None): if (self.layer_artist is None or self.layer_state is None or self.viewer_state is None): - return self.nan_array + return None if not self.layer_artist._compatible_with_reference_data: - return self.nan_array + return None try: mask = self.layer_state.get_sliced_data(view=view) except IncompatibleAttribute: self.layer_artist.disable_incompatible_subset() - return self.nan_array + return None else: self.layer_artist.enable()