51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
from collections import Counter
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SPEC = importlib.util.spec_from_file_location(
|
|
"building_portfolio", ROOT / "scripts" / "provision_belgium_building_training_portfolio.py"
|
|
)
|
|
assert SPEC and SPEC.loader
|
|
module = importlib.util.module_from_spec(SPEC)
|
|
sys.modules[SPEC.name] = module
|
|
SPEC.loader.exec_module(module)
|
|
|
|
|
|
def test_portfolio_covers_every_region_split_and_context_family() -> None:
|
|
assert len({aoi.slug for aoi in module.AOIS}) == len(module.AOIS)
|
|
counts = Counter((aoi.region, aoi.split) for aoi in module.AOIS)
|
|
for region in module.REGION_CONTRACT:
|
|
assert counts[(region, "train")] >= 15
|
|
assert counts[(region, "val")] >= 2
|
|
assert counts[(region, "calibration")] >= 3
|
|
assert counts[(region, "test")] >= 3
|
|
assert counts[(region, "background-test")] >= 2
|
|
|
|
|
|
def test_portfolio_bbox_is_metric_sized() -> None:
|
|
bbox = module.bbox_for_center(4.35, 50.85, 256.0)
|
|
to_metric = module.Transformer.from_crs("EPSG:4326", "EPSG:31370", always_xy=True)
|
|
bounds = to_metric.transform_bounds(bbox["min_x"], bbox["min_y"], bbox["max_x"], bbox["max_y"])
|
|
assert 255 <= bounds[2] - bounds[0] <= 258
|
|
assert 255 <= bounds[3] - bounds[1] <= 258
|
|
|
|
|
|
def test_failure_driven_expansion_is_train_only_and_context_complete() -> None:
|
|
additions = [aoi for aoi in module.AOIS if aoi.slug.endswith("-v31") or "-v31-bg" in aoi.slug]
|
|
assert len(additions) == 18
|
|
assert {aoi.split for aoi in additions} == {"train"}
|
|
assert {aoi.region for aoi in additions} == {"flanders", "wallonia"}
|
|
contexts = {(aoi.region, aoi.context) for aoi in additions}
|
|
assert {
|
|
("flanders", "industrial"),
|
|
("flanders", "ribbon-development"),
|
|
("flanders", "coastal-urban"),
|
|
("wallonia", "dense-urban"),
|
|
("wallonia", "rural-town"),
|
|
("wallonia", "regional-architecture"),
|
|
} <= contexts
|