fix: partition regional land use retrieval
This commit is contained in:
@@ -8,6 +8,10 @@ from pathlib import Path
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
import numpy as np
|
||||
import rasterio
|
||||
from rasterio.transform import from_origin
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPTS = ROOT / "scripts"
|
||||
@@ -98,7 +102,8 @@ def test_regional_coordinator_builds_explicit_population_and_forest_commands(tmp
|
||||
max_landuse_features=500000,
|
||||
)
|
||||
|
||||
commands = dict(module.build_operator_commands(args, scope, tmp_path / "boundary.geojson"))
|
||||
members_path = tmp_path / "municipalities.geojson"
|
||||
commands = dict(module.build_operator_commands(args, scope, tmp_path / "boundary.geojson", members_path))
|
||||
|
||||
assert set(commands) == {"population", "forest"}
|
||||
assert commands["population"][0] == sys.executable
|
||||
@@ -107,6 +112,8 @@ def test_regional_coordinator_builds_explicit_population_and_forest_commands(tmp
|
||||
assert scope.project_name in commands["population"]
|
||||
assert commands["forest"][0] == sys.executable
|
||||
assert "--max-features" in commands["forest"]
|
||||
assert "--partition-boundaries-path" in commands["forest"]
|
||||
assert str(members_path) in commands["forest"]
|
||||
assert ",".join(scope.nis_codes) in commands["forest"]
|
||||
assert "--force" not in commands["population"]
|
||||
assert "--fetch-only" not in commands["forest"]
|
||||
@@ -128,6 +135,39 @@ def test_regional_forest_provenance_does_not_claim_one_municipality() -> None:
|
||||
assert municipal["nis_code"] == "13025"
|
||||
|
||||
|
||||
def test_regional_forest_partition_rasters_merge_without_resolution_loss(tmp_path: Path) -> None:
|
||||
module = load_script("provision_official_landuse_timeseries.py")
|
||||
left = tmp_path / "left.tif"
|
||||
right = tmp_path / "right.tif"
|
||||
profile = {
|
||||
"driver": "GTiff",
|
||||
"height": 2,
|
||||
"width": 2,
|
||||
"count": 1,
|
||||
"dtype": "uint8",
|
||||
"crs": "EPSG:31370",
|
||||
"transform": from_origin(100000, 200000, 10, 10),
|
||||
"nodata": 0,
|
||||
}
|
||||
with rasterio.open(left, "w", **profile) as target:
|
||||
target.write(np.full((1, 2, 2), 12, dtype="uint8"))
|
||||
with rasterio.open(
|
||||
right,
|
||||
"w",
|
||||
**{**profile, "transform": from_origin(100020, 200000, 10, 10)},
|
||||
) as target:
|
||||
target.write(np.full((1, 2, 2), 17, dtype="uint8"))
|
||||
|
||||
destination = tmp_path / "regional.tif"
|
||||
result = module.merge_partition_rasters([left, right], destination)
|
||||
|
||||
assert result["width"] == 4
|
||||
assert result["height"] == 2
|
||||
assert result["resolution_metres"] == 10.0
|
||||
with rasterio.open(destination) as merged:
|
||||
assert merged.read(1).tolist() == [[12, 12, 17, 17], [12, 12, 17, 17]]
|
||||
|
||||
|
||||
def test_regional_timeseries_operator_is_packaged_and_release_checked() -> None:
|
||||
dockerfile = (ROOT / "deploy/unraid/Dockerfile.all-in-one").read_text(encoding="utf-8")
|
||||
readiness = (ROOT / "scripts/run_readiness_check.sh").read_text(encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user