Filter labels created after dated imagery
This commit is contained in:
@@ -88,3 +88,47 @@ def test_spatial_leakage_audit_fails_cross_split_neighbors() -> None:
|
||||
assert audit["status"] == "failed"
|
||||
assert audit["findings"][0]["left"] == "train-a"
|
||||
assert audit["findings"][0]["right"] == "val-a"
|
||||
|
||||
|
||||
def test_normalizer_rejects_features_created_after_dated_imagery(tmp_path: Path) -> None:
|
||||
raster_path = tmp_path / "image.tif"
|
||||
with rasterio.open(
|
||||
raster_path,
|
||||
"w",
|
||||
driver="GTiff",
|
||||
width=100,
|
||||
height=100,
|
||||
count=3,
|
||||
dtype="uint8",
|
||||
crs="EPSG:4326",
|
||||
transform=from_origin(4.0, 51.0, 0.001, 0.001),
|
||||
) as dataset:
|
||||
dataset.write(np.zeros((3, 100, 100), dtype="uint8"))
|
||||
geometry = {
|
||||
"type": "Polygon",
|
||||
"coordinates": [[[4.01, 50.99], [4.02, 50.99], [4.02, 50.98], [4.01, 50.98], [4.01, 50.99]]],
|
||||
}
|
||||
reference_path = tmp_path / "reference.geojson"
|
||||
reference_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{"type": "Feature", "id": "old", "properties": {"BEGINDATUM": "2024-01-01"}, "geometry": geometry},
|
||||
{"type": "Feature", "id": "new", "properties": {"BEGINDATUM": "2026-01-01"}, "geometry": geometry},
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
normalized, audit = module.normalize(
|
||||
reference_path=reference_path,
|
||||
raster_path=raster_path,
|
||||
source_name="grb",
|
||||
min_label_px=3,
|
||||
imagery_observed_at="2025-01-01T00:00:00Z",
|
||||
imagery_valid_to="2025-12-31T23:59:59Z",
|
||||
reference_observed_at="2026-07-01T00:00:00Z",
|
||||
)
|
||||
assert len(normalized["features"]) == 1
|
||||
assert audit["decision_counts"] == {"accepted": 1, "created_after_imagery_period": 1}
|
||||
|
||||
Reference in New Issue
Block a user