Skip to content

Commit

Permalink
Add test for diagonal coverage with cover_scale (#679)
Browse files Browse the repository at this point in the history
* Add test for diagonal coverage

* Use round to have better control on decimals

* Use finer cover_scale

* lint

---------

Co-authored-by: vincentsarago <vincent.sarago@gmail.com>
  • Loading branch information
j08lue and vincentsarago authored Mar 6, 2024
1 parent 73175d0 commit 6343b57
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -480,3 +481,17 @@ 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=1000)
assert numpy.round(numpy.unique(coverage), decimals=3).tolist() == [0, 0.125, 0.25]

0 comments on commit 6343b57

Please sign in to comment.