Download infer_example.py from summerAIO/sunstar-plus: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/summerAIO/sunstar-plus/resolve/main/infer_example.py
- Command line
-
hf download hf://summerAIO/sunstar-plus/infer_example.py
-
curl -L -o infer_example.py https://huggingface.co/summerAIO/sunstar-plus/resolve/main/infer_example.py
2.18 kB
| """Sun*+ 推論例 (ローカル/オフライン実行用)。 | |
| python infer_example.py --station 0658 --start 2026-10-01 --end 2026-10-03 # 観測なしダウンスケーリング (ARCO-ERA5 を自動取得) | |
| python infer_example.py --station 0658 --start 2026-10-01 --end 2026-10-03 --nc era5_dir --static static.nc # 取得済み NetCDF を使う | |
| 予測対象時刻の前後24時間の余白を自動的に含めて取得します。出力は CSV (時刻 UTC)。""" | |
| import argparse, pandas as pd, numpy as np | |
| from sunstar_plus import SunstarPlus, era5io | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--station", required=True, help="stations_nationwide.csv の block_no (例 0658=新見)。カンマ区切り可") | |
| ap.add_argument("--start", required=True); ap.add_argument("--end", required=True) | |
| ap.add_argument("--nc"); ap.add_argument("--static"); ap.add_argument("--out", default="sunstar_plus_pred.csv") | |
| ap.add_argument("--known", action="store_true", help="学習に使った地点なら指定 (σ の未知地点拡大を外す)") | |
| a = ap.parse_args() | |
| st = pd.read_csv("data/stations_nationwide.csv", dtype={"block_no": str}); ids = a.station.split(",") | |
| sel = st[st.block_no.isin(ids)].reset_index(drop=True); assert len(sel), "block_no が見つかりません" | |
| t0, t1 = pd.Timestamp(a.start) - pd.Timedelta(hours=24), pd.Timestamp(a.end) + pd.Timedelta(hours=24) | |
| if a.nc: | |
| import glob; times, fields, grid = era5io.load_nc(glob.glob(a.nc + "/20??-??.nc"), a.static); keep = (times >= t0) & (times <= t1) | |
| times = times[keep]; fields = {k: v[keep] for k, v in fields.items()} | |
| else: times, fields, grid = era5io.fetch_arco(t0, t1) | |
| m = SunstarPlus(".") | |
| out = m.downscale(times, fields, grid, sel, sigma=True, heldout=not a.known) | |
| rows = [] | |
| for j, r in sel.iterrows(): | |
| d = pd.DataFrame({"time_utc": times, "block_no": r.block_no}) | |
| for v, (mean, sg) in out.items(): | |
| d[v] = mean[:, j] | |
| if sg is not None: d[v + "_sigma"] = sg[:, j] | |
| rows.append(d) | |
| res = pd.concat(rows); res = res[(res.time_utc >= pd.Timestamp(a.start)) & (res.time_utc <= pd.Timestamp(a.end))] | |
| res.to_csv(a.out, index=False); print(res.head(), "->", a.out) | |