From 060e15ac59bd27d1168580fd153a32c08b320ce9 Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 23 Feb 2024 15:56:52 +0100 Subject: [PATCH 1/4] Add test for diagonal coverage --- tests/test_models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 1a6afdfa..b1ea2394 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -460,6 +460,7 @@ def test_imagedata_coverage(): coverage = im.get_coverage_array({"type": "Feature", "geometry": poly}) assert numpy.unique(coverage).tolist() == [0.25] + # non-default CRS poly = { "type": "Polygon", "coordinates": [ @@ -480,3 +481,19 @@ def test_imagedata_coverage(): {"type": "Feature", "geometry": poly}, shape_crs="epsg:3857" ) assert numpy.unique(coverage).tolist() == [0.25] + + # polygon with diagonal cut - requires higher cover_scale + im = ImageData( + numpy.ma.array((1, 2, 3, 4)).reshape((1, 2, 2)), + crs="epsg:4326", + bounds=(-180, -90, 180, 90), + ) + poly = { + "type": "Polygon", + "coordinates": [ + [[-90.0, -45.0], [90.0, -45.0], [-90.0, 45.0], [-90.0, -45.0]] + ], + } + + coverage = im.get_coverage_array(poly, cover_scale=100) + assert numpy.allclose(numpy.unique(coverage), [0, 0.125, 0.25], rtol=1e3) From eb2b151e0b079a08b017dbff70ba0fca15c282b2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 23 Feb 2024 16:13:18 +0100 Subject: [PATCH 2/4] Use round to have better control on decimals --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index b1ea2394..925932e7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -496,4 +496,4 @@ def test_imagedata_coverage(): } coverage = im.get_coverage_array(poly, cover_scale=100) - assert numpy.allclose(numpy.unique(coverage), [0, 0.125, 0.25], rtol=1e3) + assert numpy.round(numpy.unique(coverage), decimals=3).tolist() == [0, 0.125, 0.25] From 9cda3ae4bd01e216ada304e1d5c87801fd3e5ced Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 26 Feb 2024 13:47:08 +0100 Subject: [PATCH 3/4] Use finer cover_scale --- tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 925932e7..ad040d38 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -495,5 +495,5 @@ def test_imagedata_coverage(): ], } - coverage = im.get_coverage_array(poly, cover_scale=100) + coverage = im.get_coverage_array(poly, cover_scale=1000) assert numpy.round(numpy.unique(coverage), decimals=3).tolist() == [0, 0.125, 0.25] From cb52d539509bd51c3b2bd2abe667d9d7765d4246 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Wed, 6 Mar 2024 15:36:30 +0100 Subject: [PATCH 4/4] lint --- tests/test_models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index ad040d38..d64d8151 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -490,10 +490,8 @@ def test_imagedata_coverage(): ) poly = { "type": "Polygon", - "coordinates": [ - [[-90.0, -45.0], [90.0, -45.0], [-90.0, 45.0], [-90.0, -45.0]] - ], + "coordinates": [[[-90.0, -45.0], [90.0, -45.0], [-90.0, 45.0], [-90.0, -45.0]]], } - + coverage = im.get_coverage_array(poly, cover_scale=1000) assert numpy.round(numpy.unique(coverage), decimals=3).tolist() == [0, 0.125, 0.25]