Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance with incompatible subsets in large images #1562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
10 changes: 4 additions & 6 deletions glue/utils/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion glue/viewers/image/composite_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 3 additions & 7 deletions glue/viewers/image/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down