From 560e3bf21816aa8e6ebc07c0359010d04cef70b5 Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Fri, 10 Nov 2023 09:54:35 -0500 Subject: [PATCH 1/4] Add visual test for scatterregionlayer --- glue/viewers/image/tests/test_viewer.py | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/glue/viewers/image/tests/test_viewer.py b/glue/viewers/image/tests/test_viewer.py index 426d54813..fc2aea81d 100644 --- a/glue/viewers/image/tests/test_viewer.py +++ b/glue/viewers/image/tests/test_viewer.py @@ -4,7 +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 def test_simple_viewer(): @@ -25,3 +28,33 @@ 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) + + return viewer.figure From 342439fa15b253c95dc26558afe2d493e11c4066 Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Fri, 10 Nov 2023 10:00:02 -0500 Subject: [PATCH 2/4] Fix codestyle --- glue/viewers/image/tests/test_viewer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/glue/viewers/image/tests/test_viewer.py b/glue/viewers/image/tests/test_viewer.py index fc2aea81d..1fbf875f3 100644 --- a/glue/viewers/image/tests/test_viewer.py +++ b/glue/viewers/image/tests/test_viewer.py @@ -9,6 +9,7 @@ from shapely.geometry import Polygon, MultiPolygon + @visual_test def test_simple_viewer(): From aebfb2ba3c22ef472f1c767f67cb00f0288846fc Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Fri, 10 Nov 2023 10:20:53 -0500 Subject: [PATCH 3/4] Add image hash --- glue/tests/visual/py311-test-visual.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glue/tests/visual/py311-test-visual.json b/glue/tests/visual/py311-test-visual.json index 6cf8c9759..7f091b301 100644 --- a/glue/tests/visual/py311-test-visual.json +++ b/glue/tests/visual/py311-test-visual.json @@ -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": "d1748fd1eede6d4aec2b955d0d21561dd2fe4d344b28ac9fecbfb9a7ca56cd5c" } From 7166d8b769ed7511e25ed68ff4bf9a6657e4d0fa Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Fri, 10 Nov 2023 10:43:02 -0500 Subject: [PATCH 4/4] Add subset for the regions --- glue/tests/visual/py311-test-visual.json | 2 +- glue/viewers/image/tests/test_viewer.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/glue/tests/visual/py311-test-visual.json b/glue/tests/visual/py311-test-visual.json index 7f091b301..e8a3b9c7c 100644 --- a/glue/tests/visual/py311-test-visual.json +++ b/glue/tests/visual/py311-test-visual.json @@ -3,5 +3,5 @@ "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.image.tests.test_viewer.test_region_layer": "d1748fd1eede6d4aec2b955d0d21561dd2fe4d344b28ac9fecbfb9a7ca56cd5c" + "glue.viewers.image.tests.test_viewer.test_region_layer": "b54088d1f31562d309d35c5e90c0a382c7ba4c16cc0db8134e9532f71f047076" } diff --git a/glue/viewers/image/tests/test_viewer.py b/glue/viewers/image/tests/test_viewer.py index 1fbf875f3..bb6f4606f 100644 --- a/glue/viewers/image/tests/test_viewer.py +++ b/glue/viewers/image/tests/test_viewer.py @@ -58,4 +58,6 @@ def test_region_layer(): 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