88
99import pandas as pd
1010
11+ from cybench .runs .analysis .index_map_lib import map_iso_for_cybencH
12+
1113_PAPER_DIR_RE = re .compile (
1214 r"^paper_walk_forward_(?P<country>[a-z]{2})_(?P<horizon>eos|mid|qtr|early)_v(?P<version>\d+)$"
1315)
2830# Process baselines evaluated only at end-of-season (no mid/qtr walk-forward runs).
2931EOS_ONLY_HORIZON_CURVE_MODELS : frozenset [str ] = frozenset ({"lpjml_bc" })
3032
33+ # Fixed choropleth scales (aligned with insights heatmap cell coloring).
34+ METRIC_MAP_SCALES : dict [str , dict [str , Any ]] = {
35+ "nrmse" : {"lo" : 0.0 , "hi" : 0.5 , "higher_better" : False , "label" : "NRMSE" },
36+ "r2" : {"lo" : 0.0 , "hi" : 1.0 , "higher_better" : True , "label" : "R²" },
37+ "r" : {"lo" : - 1.0 , "hi" : 1.0 , "higher_better" : True , "label" : "r" },
38+ }
39+
40+ MAP_COVERAGE_NOTE = (
41+ "Only CY-Bench countries are colored; all other land is neutral gray. "
42+ "ISO country polygons are used as-is (e.g. the United States outline includes Alaska). "
43+ "France is metropolitan only (French Guiana is not colored)."
44+ )
45+
3146
3247def horizons_in_data (df : pd .DataFrame ) -> tuple [str , ...]:
3348 """Horizons present in a summary frame, ordered by increasing season progress."""
@@ -1298,6 +1313,9 @@ def build_insights_payload(output_root: Path, *, version: int = 1) -> dict[str,
12981313 crops = _crop_keys (df )
12991314 baseline_models = sorted ({str (m ) for m in df ["model" ].unique () if is_baseline_model (m )})
13001315 horizon_labels = {hz : HORIZON_DISPLAY_LABELS .get (hz , hz ) for hz in available_horizons }
1316+
1317+ country_map_cc = {str (cc ): map_iso_for_cybencH (str (cc )) for cc in countries }
1318+ benchmark_map_isos = sorted (set (country_map_cc .values ()))
13011319 return {
13021320 "output_root" : str (output_root .resolve ()),
13031321 "dashboard_hrefs" : build_dashboard_hrefs (output_root , version = version ),
@@ -1316,6 +1334,10 @@ def build_insights_payload(output_root: Path, *, version: int = 1) -> dict[str,
13161334 "model_country_skilled" : model_country_skilled ,
13171335 "horizon_skill_curves" : build_horizon_skill_curves_payload (df ),
13181336 "crop_comparison" : build_crop_comparison_payload (df ),
1337+ "country_map_cc" : country_map_cc ,
1338+ "benchmark_map_isos" : benchmark_map_isos ,
1339+ "map_coverage_note" : MAP_COVERAGE_NOTE ,
1340+ "metric_map_scales" : METRIC_MAP_SCALES ,
13191341 }
13201342
13211343
0 commit comments