Skip to content

Commit

Permalink
Merge pull request #2461 from jfoster17/add-scatterregionlayer-test
Browse files Browse the repository at this point in the history
Add visual test for ScatterRegionLayerArtist
  • Loading branch information
astrofrog authored Nov 10, 2023
2 parents ebd566a + 7166d8b commit 4701241
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion glue/tests/visual/py311-test-visual.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"glue.viewers.histogram.tests.test_viewer.test_simple_viewer": "cb08123fbad135ab614bb7ec13475fcc83321057d884fe80c3a32970b2d14762",
"glue.viewers.image.tests.test_viewer.test_simple_viewer": "72abd60b484d14f721254f027bb0ab9b36245d5db77eb87693f4dd9998fd28be",
"glue.viewers.profile.tests.test_viewer.test_simple_viewer": "f68a21be5080fec513388b2d2b220512e7b0df5498e2489da54e58708de435b3",
"glue.viewers.scatter.tests.test_viewer.test_simple_viewer": "1020a7bd3abe40510b9e03047c3b423b75c3c64ac18e6dcd6257173cec1ed53f"
"glue.viewers.scatter.tests.test_viewer.test_simple_viewer": "1020a7bd3abe40510b9e03047c3b423b75c3c64ac18e6dcd6257173cec1ed53f",
"glue.viewers.image.tests.test_viewer.test_region_layer": "b54088d1f31562d309d35c5e90c0a382c7ba4c16cc0db8134e9532f71f047076"
}
36 changes: 36 additions & 0 deletions glue/viewers/image/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from glue.viewers.image.viewer import SimpleImageViewer
from glue.core.application_base import Application
from glue.core.data import Data
from glue.core.link_helpers import LinkSame
from glue.core.data_region import RegionData

from shapely.geometry import Polygon, MultiPolygon


@visual_test
Expand All @@ -25,3 +29,35 @@ def test_simple_viewer():
app.data_collection.new_subset_group(label='subset1', subset_state=data1.pixel_component_ids[1] > 1.2)

return viewer.figure


@visual_test
def test_region_layer():
poly_1 = Polygon([(20, 20), (60, 20), (60, 40), (20, 40)])
poly_2 = Polygon([(60, 50), (60, 70), (80, 70), (80, 50)])
poly_3 = Polygon([(10, 10), (15, 10), (15, 15), (10, 15)])
poly_4 = Polygon([(10, 20), (15, 20), (15, 30), (10, 30), (12, 25)])

polygons = MultiPolygon([poly_3, poly_4])

geoms = np.array([poly_1, poly_2, polygons])
values = np.array([1, 2, 3])
region_data = RegionData(regions=geoms, values=values)

image_data = Data(x=np.arange(10000).reshape((100, 100)), label='data1')
app = Application()
app.data_collection.append(image_data)
app.data_collection.append(region_data)

link1 = LinkSame(region_data.center_x_id, image_data.pixel_component_ids[0])
link2 = LinkSame(region_data.center_y_id, image_data.pixel_component_ids[1])
app.data_collection.add_link(link1)
app.data_collection.add_link(link2)

viewer = app.new_data_viewer(SimpleImageViewer)
viewer.add_data(image_data)
viewer.add_data(region_data)

app.data_collection.new_subset_group(label='subset1', subset_state=region_data.id['values'] > 2)

return viewer.figure

0 comments on commit 4701241

Please sign in to comment.