Skip to content

Commit

Permalink
Merge pull request #1562 from astrofrog/fix-performance-subset-large-…
Browse files Browse the repository at this point in the history
…image

Fix performance with incompatible subsets in large images
  • Loading branch information
astrofrog committed Mar 7, 2018
1 parent 8fe93c7 commit c3c66bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
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 @@ -274,25 +274,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

0 comments on commit c3c66bd

Please sign in to comment.