Skip to content

Commit

Permalink
Added a test (originally in glue-qt) for IndexedData in the image vie…
Browse files Browse the repository at this point in the history
…wer test suite, and fix bug
  • Loading branch information
astrofrog committed Jul 12, 2024
1 parent 262671d commit 63281df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions glue/viewers/image/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from collections import defaultdict

from glue.core import BaseData
from glue.core import BaseData, Data
from glue.config import colormaps
from glue.viewers.matplotlib.state import (MatplotlibDataViewerState,
MatplotlibLayerState,
Expand Down Expand Up @@ -620,7 +620,7 @@ def reset_contrast_bias(self):

def _update_attribute_display_unit_choices(self, *args):

if self.layer is None or self.attribute is None:
if self.layer is None or self.attribute is None or not isinstance(self.layer, Data):
ImageLayerState.attribute_display_unit.set_choices(self, [])
return

Expand Down
30 changes: 30 additions & 0 deletions glue/viewers/image/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from glue.core.data import Data
from glue.core.link_helpers import LinkSame
from glue.core.data_region import RegionData
from glue.core.data_derived import IndexedData
from astropy.wcs import WCS

from shapely.geometry import Polygon, MultiPolygon, Point
Expand Down Expand Up @@ -265,3 +266,32 @@ def test_flipped_wcs_viewer(self):
assert np.array_equal(original_path_patch, np.flip(new_path_patch, axis=1))

return self.viewer.figure


def test_indexed_data():

# Make sure that the image viewer works properly with IndexedData objects

data_4d = Data(label='hypercube_wcs',
x=np.random.random((3, 5, 4, 3)),
coords=WCS(naxis=4))

data_2d = IndexedData(data_4d, (2, None, 3, None))

application = Application()

session = application.session

hub = session.hub

data_collection = session.data_collection
data_collection.append(data_4d)
data_collection.append(data_2d)

viewer = application.new_data_viewer(SimpleImageViewer)
viewer.add_data(data_2d)

assert viewer.state.x_att is data_2d.pixel_component_ids[1]
assert viewer.state.y_att is data_2d.pixel_component_ids[0]
assert viewer.state.x_att_world is data_2d.world_component_ids[1]
assert viewer.state.y_att_world is data_2d.world_component_ids[0]

0 comments on commit 63281df

Please sign in to comment.