Download make_demo_data.py from Tonic/protostar-climate-2026: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/make_demo_data.py
- Command line
-
hf download hf://datasets/Tonic/protostar-climate-2026/make_demo_data.py
-
curl -L -o make_demo_data.py https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/make_demo_data.py
1.93 kB
| """Export the small CSVs the demo Space needs into space_demo/data/.""" | |
| from __future__ import annotations | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| import pandas as pd | |
| ROOT = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(ROOT / "code")) | |
| from panel import Panel # noqa: E402 | |
| OUT = ROOT / "space_demo" / "data" | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| def main() -> None: | |
| panel = Panel(ROOT) | |
| # 1989-2018 normals per city-metric from the valid panel values. | |
| i0, i1 = panel.year_idx[1989], panel.year_idx[2018] | |
| rows = [] | |
| names = {} | |
| annual_root = ROOT / "data" / "_source" / "annual_indices" / "train-00000-of-00001.parquet" | |
| annual = pd.read_parquet(annual_root, columns=["ID", "Name"]) | |
| name_map = annual.drop_duplicates("ID").set_index("ID")["Name"].to_dict() | |
| for metric, vals in panel.values.items(): | |
| window = vals[:, i0:i1 + 1] | |
| with np.errstate(invalid="ignore"): | |
| w = np.where(np.isfinite(window), window, np.nan) | |
| normal = np.nanmean(w, axis=1) | |
| hist_max = np.nanmax(w, axis=1) | |
| hist_p90 = np.nanpercentile(w, 90, axis=1) | |
| for i, city in enumerate(panel.cities): | |
| rows.append({"city_id": city, "metric": metric, "normal_1989_2018": normal[i], | |
| "hist_max_1989_2018": hist_max[i], "hist_p90_1989_2018": hist_p90[i]}) | |
| pd.DataFrame(rows).to_csv(OUT / "normals.csv", index=False) | |
| pd.DataFrame({ | |
| "city_id": panel.cities, | |
| "name": [name_map.get(c, c) for c in panel.cities], | |
| "lat": panel.lat, "lon": panel.lon, | |
| }).to_csv(OUT / "cities.csv", index=False) | |
| shutil.copy(ROOT / "submission.csv", OUT / "forecasts.csv") | |
| shutil.copy(ROOT / "outputs" / "policy_city_risk.csv", OUT / "policy.csv") | |
| print(f"wrote demo data -> {OUT}") | |
| if __name__ == "__main__": | |
| main() | |