report what an area selection actually measured
Four ways a selection produced a confident number about a different area than the operator drew: Flood hazard divided the inundated cells by every cell in the drawn rectangle, including cells the VMM raster does not model at all. A selection reaching past the modelled extent therefore reported a diluted risk share, turning missing data into an implied absence of risk. Terrain, bathymetry and thematic raster already divided by valid cells; flood hazard was the outlier. It now reports the three populations separately, states model coverage next to the drawn area, and returns a null fraction rather than a zero when nothing was modelled. geometry_mask selects a cell when its centre falls inside the geometry, so a rectangle smaller than one cell — or one landing between four centres — selected nothing and the analysis returned zeros indistinguishable on screen from "we looked and there is nothing here". On a 100 m population raster a 40 m rectangle over a city block reported no inhabitants. Selection now falls back to the touched cells and says that it did, since the answer then covers more ground than was requested. rasterio.mask applies the same centre rule when cropping, so that call is widened too; the cells that count are still decided by the centre rule wherever it selects anything. The object count treated any feature touching the selection as whole, while intersection_area clipped it — two headline numbers on one panel describing different populations. The count stays whole-feature, which is what "objecten" means to an operator, but now reports how many the edge cuts and is marked an estimate when it does. The area_weighted_sum branch reuses that same count instead of issuing its own near-identical query. Partitioned selection de-duplicated the count on source_feature_id but returned the raw rows, so a building on a municipal boundary was counted once and drawn twice. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -287,8 +287,20 @@ def test_flood_hazard_analysis_reports_scenario_metrics_without_claiming_waterbo
|
||||
metrics = {item["metric_key"]: item for item in result["summary"]["metrics"]}
|
||||
|
||||
assert result["inundated_cell_count"] == 200
|
||||
assert result["inundated_fraction"] == pytest.approx(0.5)
|
||||
# The fixture models the left half and marks the right half nodata. All of
|
||||
# the modelled half is wet, and the model covers half the selection. The
|
||||
# earlier 0.5 conflated "not modelled" with "modelled dry" and reported
|
||||
# half the risk that the model actually describes.
|
||||
assert result["valid_cell_count"] == 200
|
||||
assert result["no_data_cell_count"] == 200
|
||||
assert result["inundated_fraction"] == pytest.approx(1.0)
|
||||
assert result["data_coverage_ratio"] == pytest.approx(0.5)
|
||||
assert "50.0%" in result["coverage_warning"]
|
||||
assert metrics["modelled_inundated_share_pct"]["metric_value"] == pytest.approx(100.0)
|
||||
assert metrics["model_coverage_pct"]["metric_value"] == pytest.approx(50.0)
|
||||
assert metrics["modelled_inundated_area_ha"]["metric_value"] == pytest.approx(0.5)
|
||||
assert metrics["modelled_area_ha"]["metric_value"] == pytest.approx(0.5)
|
||||
assert metrics["selection_area_ha"]["metric_value"] == pytest.approx(1.0)
|
||||
assert metrics["modelled_depth_mean_m"]["metric_value"] == pytest.approx(1.0)
|
||||
assert metrics["modelled_max_depth_area_integral_m3"]["metric_value"] == pytest.approx(5000.0)
|
||||
assert "concurrent_flood_volume_m3" in result["unsupported_metrics"]
|
||||
|
||||
Reference in New Issue
Block a user