Download selftest.py from summerAIO/sunstar-plus: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/summerAIO/sunstar-plus/resolve/main/selftest.py
- Command line
-
hf download hf://summerAIO/sunstar-plus/selftest.py
-
curl -L -o selftest.py https://huggingface.co/summerAIO/sunstar-plus/resolve/main/selftest.py
1.91 kB
| """自己検証: 本パッケージ (SunstarPlus.downscale) の予測が、評価パイプライン (eval_stream.py) の予測 (lead 0) と一致するか。 | |
| python selftest.py <評価chunk.npz> <chunk 開始時刻> <ERA5月別ncディレクトリ> <static.nc> (開発環境用; 配布物には評価データは含まれない)""" | |
| import sys, glob, numpy as np, pandas as pd | |
| from sunstar_plus import SunstarPlus, era5io | |
| chunk, t_start, era_dir, static = sys.argv[1:5] | |
| z = np.load(chunk); t = z["L0_t"]; s = z["L0_s"]; sp = z["L0_sp"] | |
| st = pd.read_csv("data/stations_nationwide.csv", dtype={"block_no": str}).reset_index(drop=True) | |
| T0 = pd.Timestamp("2023-01-01"); times_abs = T0 + pd.to_timedelta(t, "h") | |
| w0 = pd.Timestamp(t_start) + pd.Timedelta(hours=48); w1 = w0 + pd.Timedelta(hours=72) | |
| stn = np.unique(s)[::max(1, len(np.unique(s)) // 12)][:12] | |
| sel = st.iloc[stn].reset_index(drop=True) | |
| times, fields, grid = era5io.load_nc(sorted(glob.glob(era_dir + "/20??-??.nc"))[-1:] if False else [f for f in glob.glob(era_dir + "/20??-??.nc") if f[-10:-3] in (pd.Timestamp(t_start).strftime("%Y-%m"), (pd.Timestamp(t_start) - pd.Timedelta(days=5)).strftime("%Y-%m"))], static) | |
| keep = (times >= w0 - pd.Timedelta(hours=24)) & (times <= w1 + pd.Timedelta(hours=24)); times = times[keep]; fields = {k: v[keep] for k, v in fields.items()} | |
| m = SunstarPlus("."); out = m.downscale(times, fields, grid, sel, sigma=False) | |
| VARS = ["temp_c", "wind_u_ms", "wind_v_ms", "humidity_pct", "wind_speed_ms", "precip_mm"] | |
| for k, v in enumerate(VARS): | |
| d = [] | |
| for j, si in enumerate(stn): | |
| mk = (s == si) & (times_abs >= w0) & (times_abs <= w1) | |
| if not mk.any(): continue | |
| idx = np.searchsorted(times, times_abs[mk]); d.append(np.abs(out[v][0][idx, j] - sp[mk, k])) | |
| d = np.concatenate(d); d = d[np.isfinite(d)] | |
| print(f"{v:14s} n={len(d):5d} max|diff|={d.max():.4g} mean|diff|={d.mean():.4g}") | |