Files
geointel/backend/tests/test_sprint199_reviewed_accuracy_expansion.py
T
Jens faeb58ef6d
GeoIntel release gates / Compile, test, contracts and builds (push) Successful in 1m49s
GeoIntel release gates / Python and npm vulnerability policy (push) Successful in 21s
GeoIntel release gates / Production AI image, SBOM and container scan (push) Successful in 5m39s
GeoIntel release gates / Deploy exact gated revision to Unraid (push) Failing after 58m43s
Initial public release
2026-08-31 21:56:53 +02:00

80 lines
2.6 KiB
Python

from __future__ import annotations
import importlib.util
import math
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[2]
def load_sample_preparer():
script_path = ROOT / "scripts" / "prepare_operator_real_data_samples.py"
spec = importlib.util.spec_from_file_location("reviewed_accuracy_samples", script_path)
assert spec is not None
assert spec.loader is not None
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def distance_m(left, right) -> float:
radius_m = 6_371_008.8
left_lat = math.radians(left.center_lat)
right_lat = math.radians(right.center_lat)
delta_lat = right_lat - left_lat
delta_lon = math.radians(right.center_lon - left.center_lon)
haversine = (
math.sin(delta_lat / 2) ** 2
+ math.cos(left_lat) * math.cos(right_lat) * math.sin(delta_lon / 2) ** 2
)
return 2 * radius_m * math.asin(math.sqrt(haversine))
def test_reviewed_accuracy_expansion_is_training_only_and_holdout_separated() -> None:
module = load_sample_preparer()
expected = {
"arendonk_center",
"dessel_center",
"meerhout_center",
"laakdal_center",
"nijlen_center",
"hulshout_center",
}
protected_holdouts = {
"turnhout",
"retie",
"westerlo",
"vosselaar_center",
"grobbendonk_center",
*module.MOL_OPERATIONAL_VALIDATION_SAMPLE_SLUGS,
}
assert module.REVIEWED_ACCURACY_EXPANSION_SAMPLE_SLUGS == frozenset(expected)
assert expected.isdisjoint(module.DEFAULT_VALIDATION_SAMPLE_SLUGS)
assert protected_holdouts.issubset(module.DEFAULT_VALIDATION_SAMPLE_SLUGS)
for slug in expected:
sample = module.SAMPLES[slug]
assert sample.sample_role == "reference"
assert sample.allow_empty_reference is False
assert sample.operational_zone == "reviewed_accuracy_training"
assert sample.municipality
assert module.recommended_split_for_sample(sample) == "train"
assert min(
distance_m(sample, module.SAMPLES[holdout_slug])
for holdout_slug in protected_holdouts
) >= 2_000
def test_reviewed_accuracy_expansion_centers_are_unique() -> None:
module = load_sample_preparer()
samples = [module.SAMPLES[slug] for slug in module.REVIEWED_ACCURACY_EXPANSION_SAMPLE_SLUGS]
centers = {(sample.center_lon, sample.center_lat) for sample in samples}
municipalities = {sample.municipality for sample in samples}
assert len(centers) == len(samples)
assert len(municipalities) == len(samples)