Datasets:
Download code/extra_freeze.py from sleonca/sl-protostar-climate-ceviche: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/sleonca/sl-protostar-climate-ceviche/resolve/main/code/extra_freeze.py
- Command line
-
hf download hf://datasets/sleonca/sl-protostar-climate-ceviche/code/extra_freeze.py
-
curl -L -o extra_freeze.py https://huggingface.co/datasets/sleonca/sl-protostar-climate-ceviche/resolve/main/code/extra_freeze.py
1.65 kB
| """PROMPT_SIGUIENTE Step A: freeze the origin-2018 forecasts of the new candidates and append their SHA-256 | |
| to results/forecasts_frozen/MANIFEST.csv (existing rows are never rewritten). | |
| Run: python code/extra_freeze.py [names...] (default: all new candidates) | |
| """ | |
| import sys | |
| from datetime import datetime, timezone | |
| import pandas as pd | |
| from arima_forecast import write | |
| from arima_freeze import OUT, sha256 | |
| from candidates_2018 import EXTRA, build | |
| from common import METRICS, ROOT, load_annual, long_valid | |
| NEW = list(EXTRA) + ["weighted_ensemble"] | |
| def freeze(names, lv, coords, build_fn=build): | |
| man_f = OUT / "MANIFEST.csv" | |
| man = pd.read_csv(man_f) | |
| clash = set(names) & set(man.name) | |
| if clash: | |
| raise SystemExit(f"already frozen, refusing to overwrite: {sorted(clash)}") | |
| rows = [] | |
| for name in names: | |
| pred = pd.concat([build_fn(name, m, lv, coords) for m in METRICS], ignore_index=True) | |
| path = OUT / f"{name}.csv" | |
| sub, n_fb = write(pred, lv, path) | |
| rows.append(dict(name=name, file=str(path.relative_to(ROOT)), | |
| frozen_at_utc=datetime.now(timezone.utc).isoformat(timespec="seconds"), | |
| rows=len(sub), sha256=sha256(path))) | |
| print(f"{name:20s} rows={len(sub)} fallback_rows={n_fb} sha256={rows[-1]['sha256'][:16]}...", flush=True) | |
| pd.concat([man, pd.DataFrame(rows)], ignore_index=True).to_csv(man_f, index=False) | |
| def main(): | |
| names = sys.argv[1:] or NEW | |
| A = load_annual() | |
| lv = long_valid(A) | |
| coords = A.groupby("ID")[["Lat", "Lon"]].first() | |
| freeze(names, lv, coords) | |
| if __name__ == "__main__": | |
| main() | |