Handle VMM WCS edge grid rounding
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-16 13:45:58 +02:00
parent 512e15f24b
commit 153cff06c0
2 changed files with 131 additions and 11 deletions
@@ -5,7 +5,6 @@ from uuid import uuid4
import numpy as np
import pytest
import rasterio
from fastapi.testclient import TestClient
from pyproj import Transformer
from rasterio.io import MemoryFile
@@ -104,6 +103,23 @@ def depth_tiff(*, normalized_metres: bool = False) -> bytes:
return memory.read()
def edge_depth_tiff(*, left: float, top: float, x_resolution: float, y_resolution: float = 5.0) -> bytes:
values = np.full((20, 20), 100.0, dtype="float32")
with MemoryFile() as memory:
with memory.open(
driver="GTiff",
width=20,
height=20,
count=1,
dtype="float32",
crs="EPSG:31370",
transform=from_origin(left, top, x_resolution, y_resolution),
nodata=0.0,
) as output:
output.write(values, 1)
return memory.read()
def test_flood_hazard_registry_is_complete_and_semantically_honest() -> None:
products = FloodHazardAcquisitionService.list_products()
@@ -151,6 +167,39 @@ def test_flood_hazard_tiles_stay_below_the_observed_vmm_coverage_limit() -> None
)
def test_flood_hazard_mosaic_harmonizes_only_bounded_wcs_edge_grid_rounding() -> None:
regular = edge_depth_tiff(left=200_000, top=210_100, x_resolution=5.0)
rounded_edge = edge_depth_tiff(
left=200_100,
top=210_100,
x_resolution=4.76555,
y_resolution=5.0008,
)
diagnostics: dict[str, object] = {}
mosaic = FloodHazardAcquisitionService._mosaic_geotiffs(
[regular, rounded_edge],
expected_resolution_m=5.0,
diagnostics=diagnostics,
)
with MemoryFile(mosaic) as memory, memory.open() as dataset:
assert dataset.res == pytest.approx((5.0, 5.0))
assert diagnostics["harmonized_tile_indexes"] == [1]
assert diagnostics["harmonization_method"] == "rasterio_merge_target_resolution"
unsafe_edge = edge_depth_tiff(left=200_100, top=210_100, x_resolution=4.5)
with pytest.raises(AppError) as exc_info:
FloodHazardAcquisitionService._mosaic_geotiffs(
[regular, unsafe_edge],
expected_resolution_m=5.0,
)
assert exc_info.value.code == "FLOOD_HAZARD_TILE_MISMATCH"
assert exc_info.value.details["invalid_resolution_tiles"] == [
{"tile_index": 1, "resolution": [4.5, 5.0]}
]
def test_flood_hazard_xml_provider_error_is_exposed_without_losing_the_canonical_error() -> None:
response = b"""<?xml version="1.0"?>
<ExceptionReport xmlns="http://www.opengis.net/ows/1.1">