@@ -95,3 +95,67 @@ def test_strip_map_pngs_from_records():
9595 assert "map_actual" not in records [0 ]["images" ]
9696 assert "map_pred" not in records [0 ]["images" ]
9797 assert records [0 ]["images" ]["scatter" ] == "c.png"
98+
99+
100+ def test_bundle_region_map_survives_referenced_assets (tmp_path : Path , monkeypatch ):
101+ """GeoJSON must be written after bundle_referenced_assets (which wipes assets/)."""
102+ from cybench .runs .analysis .collect_walk_forward_results import (
103+ write_model_comparison_dashboard ,
104+ )
105+
106+ output_dir = tmp_path / "paper_walk_forward_us_eos_v2"
107+ preds = output_dir / "preds" / "ridge_eos"
108+ preds .mkdir (parents = True )
109+ pd .DataFrame (
110+ {
111+ "adm_id" : ["US-01-001" ],
112+ "year" : [2020 ],
113+ "yield" : [10.0 ],
114+ "Ridge" : [9.5 ],
115+ }
116+ ).to_csv (preds / "maize_US_h10_year_2020.csv" , index = False )
117+
118+ scatter_src = preds / "report_assets"
119+ scatter_src .mkdir (parents = True )
120+ scatter_src .joinpath ("maize_US_scatter.png" ).write_bytes (b"png" )
121+
122+ summary_rows = [
123+ {
124+ "dataset" : "maize_US" ,
125+ "model" : "ridge" ,
126+ "horizon" : "eos" ,
127+ "model_col" : "Ridge" ,
128+ "nrmse" : 0.1 ,
129+ "r2" : 0.8 ,
130+ "r_spatial" : 0.5 ,
131+ "r_spatial_agg" : 0.5 ,
132+ "r_temporal" : 0.4 ,
133+ "r_temporal_agg" : 0.4 ,
134+ "r_res" : 0.3 ,
135+ "r2_res" : 0.2 ,
136+ "n_regions" : 1 ,
137+ "n_years" : 1 ,
138+ "n_samples" : 1 ,
139+ }
140+ ]
141+
142+ def _fake_export (country_code : str , dest : Path , ** kwargs ):
143+ dest .parent .mkdir (parents = True , exist_ok = True )
144+ dest .write_text (
145+ '{"type":"FeatureCollection","features":[{"type":"Feature",'
146+ '"properties":{"loc":"US-01-001"},"geometry":{"type":"Point","coordinates":[0,0]}}]}' ,
147+ encoding = "utf-8" ,
148+ )
149+ return dest
150+
151+ monkeypatch .setattr (
152+ "cybench.runs.viz.region_map_lib.export_region_geojson" ,
153+ _fake_export ,
154+ )
155+
156+ write_model_comparison_dashboard (output_dir , summary_rows , bundle_assets = True )
157+ geojson = output_dir / "assets" / "regions_US.geojson"
158+ assert geojson .is_file (), "regions_US.geojson must survive asset bundling"
159+ html = (output_dir / "compare_models.html" ).read_text (encoding = "utf-8" )
160+ assert "regions_US.geojson" in html
161+ assert (output_dir / "assets" / "maize_US_scatter.png" ).is_file ()
0 commit comments