Skip to content

Commit 4b5fc19

Browse files
world map
1 parent d8b727e commit 4b5fc19

3 files changed

Lines changed: 62 additions & 15 deletions

File tree

cybench/runs/analysis/model_family_radar_lib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,22 @@ def build_radar_payload(
775775
by_horizon[hz] = by_crop
776776

777777
crops = sorted({str(c) for c in df["crop"].dropna().unique()}) if "crop" in df.columns else []
778+
benchmark_map_isos = (
779+
sorted({map_iso_for_cybencH(str(c)) for c in df["country"].dropna().unique()})
780+
if "country" in df.columns
781+
else []
782+
)
778783
return {
779784
"output_root": str(output_root.resolve()),
780785
"n_summary_files": len(paths),
781786
"n_rows": int(len(df)),
782787
"n_countries": int(df["country"].nunique()) if "country" in df.columns else 0,
783788
"countries": sorted(df["country"].unique()) if "country" in df.columns else [],
789+
"benchmark_map_isos": benchmark_map_isos,
790+
"map_coverage_note": (
791+
"Only CY-Bench countries are colored; all other land is neutral gray. "
792+
"ISO country polygons are used as-is (e.g. the United States outline includes Alaska)."
793+
),
784794
"crops": crops,
785795
"views": list(EVALUATION_VIEWS),
786796
"family_catalog": {

cybench/runs/viz/model_family_radar_template.html

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ <h2>World map</h2>
257257
<div class="toolbar" id="winner-aspect-toolbar"></div>
258258
</div>
259259
<p class="muted" id="map-mode-note">Colors show which model family wins in each country for the selected evaluation aspect.</p>
260+
<p class="muted" id="map-coverage-note"></p>
260261
<div class="world-map-wrap" id="winner-map-wrap"><p class="muted">Loading map…</p></div>
261262
<div class="winner-legend" id="winner-legend"></div>
262263
<div class="benefit-legend" id="benefit-legend" style="display:none;">
@@ -290,6 +291,24 @@ <h2>World map</h2>
290291
const benefitLegend = document.getElementById("benefit-legend");
291292
const benefitLegendLabel = document.getElementById("benefit-legend-label");
292293
const winnerSummary = document.getElementById("winner-summary");
294+
const mapCoverageNote = document.getElementById("map-coverage-note");
295+
296+
const MAP_FILL_OUTSIDE = "#e8eaed";
297+
const MAP_FILL_NO_DATA = "#f5f5f5";
298+
const benchmarkIsos = new Set(DATA.benchmark_map_isos || []);
299+
if (mapCoverageNote) {
300+
mapCoverageNote.textContent = DATA.map_coverage_note || (
301+
"Only CY-Bench countries are colored; other land is neutral gray."
302+
);
303+
}
304+
305+
function isBenchmarkIso(iso) {
306+
return benchmarkIsos.has(iso);
307+
}
308+
309+
function mapBaseFill(iso) {
310+
return isBenchmarkIso(iso) ? MAP_FILL_NO_DATA : MAP_FILL_OUTSIDE;
311+
}
293312

294313
let radarMode = "relative";
295314
let mapMode = "winner";
@@ -759,19 +778,25 @@ <h2>World map</h2>
759778
.attr("class", "country")
760779
.attr("d", mapPath)
761780
.attr("fill", d => {
762-
const rec = winners.get(d.properties.ISO_A2);
763-
if (!rec) return "#f0f0f0";
781+
const iso = d.properties.ISO_A2;
782+
if (!isBenchmarkIso(iso)) return MAP_FILL_OUTSIDE;
783+
const rec = winners.get(iso);
784+
if (!rec) return MAP_FILL_NO_DATA;
764785
return colors[rec.winner_family] || "#999";
765786
})
766-
.attr("stroke", null)
767-
.attr("stroke-width", null);
787+
.attr("stroke", d => isBenchmarkIso(d.properties.ISO_A2) ? "#fff" : "#d0d7de")
788+
.attr("stroke-width", d => isBenchmarkIso(d.properties.ISO_A2) ? 0.5 : 0.25);
768789

769790
countriesSel.selectAll("title")
770791
.data(d => [d])
771792
.join("title")
772793
.text(d => {
773-
const rec = winners.get(d.properties.ISO_A2);
774-
if (!rec) return `${d.properties.NAME || d.properties.ISO_A2}: no data`;
794+
const iso = d.properties.ISO_A2;
795+
if (!isBenchmarkIso(iso)) {
796+
return `${d.properties.NAME || iso}: not in CY-Bench`;
797+
}
798+
const rec = winners.get(iso);
799+
if (!rec) return `${d.properties.NAME || iso}: no data for this horizon/crop`;
775800
return `${rec.country}: ${rec.winner_family} (${rec.winner_model}), ${byAspect.metric}=${rec.value.toFixed(3)}`;
776801
});
777802

@@ -800,26 +825,36 @@ <h2>World map</h2>
800825
.attr("class", "country")
801826
.attr("d", mapPath)
802827
.attr("fill", d => {
803-
const rec = byCountry.get(d.properties.ISO_A2);
804-
if (!rec || rec.benefit_pct == null) return "#f0f0f0";
828+
const iso = d.properties.ISO_A2;
829+
if (!isBenchmarkIso(iso)) return MAP_FILL_OUTSIDE;
830+
const rec = byCountry.get(iso);
831+
if (!rec || rec.benefit_pct == null) return MAP_FILL_NO_DATA;
805832
return benefitColor(rec.benefit_pct, extent);
806833
})
807834
.attr("stroke", d => {
808-
const rec = byCountry.get(d.properties.ISO_A2);
809-
if (!rec || !benefitOffScale(rec.benefit_pct, extent)) return null;
810-
return "#1f2328";
835+
const iso = d.properties.ISO_A2;
836+
if (!isBenchmarkIso(iso)) return "#d0d7de";
837+
const rec = byCountry.get(iso);
838+
if (rec && benefitOffScale(rec.benefit_pct, extent)) return "#1f2328";
839+
return "#fff";
811840
})
812841
.attr("stroke-width", d => {
813-
const rec = byCountry.get(d.properties.ISO_A2);
814-
return rec && benefitOffScale(rec.benefit_pct, extent) ? 1.1 : null;
842+
const iso = d.properties.ISO_A2;
843+
if (!isBenchmarkIso(iso)) return 0.25;
844+
const rec = byCountry.get(iso);
845+
return rec && benefitOffScale(rec.benefit_pct, extent) ? 1.1 : 0.5;
815846
});
816847

817848
countriesSel.selectAll("title")
818849
.data(d => [d])
819850
.join("title")
820851
.text(d => {
821-
const rec = byCountry.get(d.properties.ISO_A2);
822-
if (!rec) return `${d.properties.NAME || d.properties.ISO_A2}: no data`;
852+
const iso = d.properties.ISO_A2;
853+
if (!isBenchmarkIso(iso)) {
854+
return `${d.properties.NAME || iso}: not in CY-Bench`;
855+
}
856+
const rec = byCountry.get(iso);
857+
if (!rec) return `${d.properties.NAME || iso}: no data for this horizon/crop`;
823858
const offScale = benefitOffScale(rec.benefit_pct, extent)
824859
? ` (color saturated; scale ±${extent}%)`
825860
: "";

tests/runs/test_model_family_radar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ def test_build_radar_payload_structure(tmp_path: Path):
258258
assert RADAR_ABSOLUTE_NOTE in payload["absolute_note"]
259259
assert payload["radar_scales"]["absolute"]["Overall"]["lo"] == 0.1
260260
assert "sample_scatter" in payload
261+
assert "benchmark_map_isos" in payload
262+
assert "DE" in payload["benchmark_map_isos"]
261263
assert "winner_maps" in payload
262264
assert "ai_benefit_maps" in payload
263265
assert "all" in payload["winner_maps"]["eos"]

0 commit comments

Comments
 (0)