From 387c0155bda99bc66159c2c4fe199791854e1abc Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Sep 2024 17:32:26 +1000 Subject: [PATCH 1/2] Add antimeridian test for roi extraction. Currently failing. --- tests/test_geom.py | 80 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/tests/test_geom.py b/tests/test_geom.py index 7ccea76..ee417f4 100644 --- a/tests/test_geom.py +++ b/tests/test_geom.py @@ -10,8 +10,8 @@ from affine import Affine from pytest import approx -from odc.geo._interop import have from odc.geo import CRS, CRSMismatchError, geom, wh_ +from odc.geo._interop import have from odc.geo.geobox import GeoBox, _round_to_res from odc.geo.geom import ( chop_along_antimeridian, @@ -22,6 +22,15 @@ projected_lon, triangulate, ) +from odc.geo.overlap import ( + _relative_rois, + native_pix_transform, + roi_boundary, + unstack_xy, + gbox_boundary, + stack_xy, + roi_from_points, +) from odc.geo.testutils import ( SAMPLE_WKT_WITHOUT_AUTHORITY, epsg3577, @@ -658,6 +667,73 @@ def test_wrap_dateline_sinusoidal(pts): assert not wrapped.intersects(geom.line([(0, -90), (0, 90)], crs=epsg4326)) +@pytest.mark.parametrize( + "dst_dstslices", + [ + [ + GeoBox( + (256, 256), + Affine( + 76.43702828517416, + 0.0, + 20017940.46354824, + 0.0, + -76.43702828518872, + -1976355.8033415154, + ), + "EPSG:3857", + ), + (slice(0, 256, None), slice(0, 256, None)), + ],[ + GeoBox( + (256, 256), + Affine( + 152.87405657034833, + 0.0, + -20037508.342789244, + 0.0, + -152.87405657034833, + -1995923.6825825237, + ), + "EPSG:3857", + ), + (slice(0, 256, None), slice(0, 256, None)), + ] + ] +) +def test_geobox_overlap(dst_dstslices): + dst, dst_slices = dst_dstslices + pts_per_side = 5 + padding = 1 + align = True + + src_affine = Affine(10.0, 0.0, 99960.0, 0.0, -10.0, 8100040.0) + src = GeoBox((10980, 10980), src_affine, "EPSG:32701") + + tr = native_pix_transform(src, dst) + + # _, roi_dst = _relative_rois(src, dst, tr, pts_per_side=pts_per_side, padding=padding, align=align) + + # This code is from _relative_rois, just to check the output + xy = tr.back(unstack_xy(gbox_boundary(dst, pts_per_side))) + roi_src = roi_from_points(stack_xy(xy), src.shape, padding, align=align) + + xys = tr(unstack_xy(roi_boundary(roi_src, pts_per_side))) + + MIN_PIXEL = 0 - 26 + MAX_PIXEL = 256 + 26 + + for xy in xys: + assert xy.x >= MIN_PIXEL + assert xy.x <= MAX_PIXEL + assert xy.y >= MIN_PIXEL + assert xy.y <= MAX_PIXEL + + # TODO: Get correct slice values in here. + # roi_dst = roi_from_points(stack_xy(xy), dst.shape, padding=0) + # assert roi_dst == dst_slices + + def test_wrap_dateline_utm(): poly = geom.box(618300, -1876800, 849000, -1642500, "EPSG:32660") @@ -1037,7 +1113,7 @@ def test_triangulate(crs): ], ) def test_explore_geom(geom_json): - from folium import Map, GeoJson + from folium import GeoJson, Map # Create Geometry geometry = geom.Geometry(geom_json, "EPSG:4326") From ce02c920314f046172b9f03e02cbc6fe0e01cf80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 07:34:20 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_geom.py b/tests/test_geom.py index ee417f4..4f78704 100644 --- a/tests/test_geom.py +++ b/tests/test_geom.py @@ -712,7 +712,7 @@ def test_geobox_overlap(dst_dstslices): tr = native_pix_transform(src, dst) - # _, roi_dst = _relative_rois(src, dst, tr, pts_per_side=pts_per_side, padding=padding, align=align) + # _, roi_dst = _relative_rois(src, dst, tr, pts_per_side=pts_per_side, padding=padding, align=align) # This code is from _relative_rois, just to check the output xy = tr.back(unstack_xy(gbox_boundary(dst, pts_per_side)))