"""RULES_dst.txt: storm minima and rankings from Kyoto's final and provisional hourly Dst (HAPI CSV files). Fact-Checked Science ("Our analysis"), 16 November 2026, for the check of Pierrard et al. (2026), npj Space Exploration 2, 43 (doi:10.1038/s44453-026-00064-7). What it does Reads hourly Dst saved from the HAPI server of the World Data Center for Geomagnetism, Kyoto (doi:10.17593/14515-74000). Each row's version code says whether the value is final (2x) or provisional (1x); a final value wins where both exist. Real-time values are never read (the script stops if it meets one). It writes the storms' minima in fixed windows, ranks the May and October 2024 storms among all storms at or below -100 nT since 2004 (and in the 20 years before each), and lists every storm at or below -250 nT from 1998 to 2023 (the storm list of RULES_meped.txt). Needs Python 3.9+ (standard library only). Run python3 dst.py [ ...] python3 dst.py /kyoto (a folder stands for every .csv file in it) Note the order: the output folder comes first. Our run used the three files fetch_inputs.py saves in /kyoto/: dst_final_1998_2003-09.csv dst_final_2003-10_2020.csv dst_provisional_2021_2026-09.csv Writes, in the output folder (Kyoto's terms of use apply to all of them: scientific, non-commercial use, with acknowledgement of the WDC and the observatories, https://wdc.kugi.kyoto-u.ac.jp/wdc/Sec3.html) dst_storms.json, dst_storm_minima.csv, dst_rankings.csv, dst_storms_le_-250_1998-2023.csv """ import csv import datetime as dt import json import os import sys TERMS = ("Hourly Dst from the World Data Center for Geomagnetism, Kyoto (doi:10.17593/14515-74000): final to " "December 2020, provisional from January 2021 to September 2026. Scientific, non-commercial use with " "acknowledgement of the WDC and the observatories (https://wdc.kugi.kyoto-u.ac.jp/wdc/Sec3.html). " "No real-time value is used.") def read(path): out = {} with open(path, encoding="utf-8") as f: for row in csv.reader(f): if not row or row[0].startswith("#"): continue t = dt.datetime.strptime(row[0][:19], "%Y-%m-%dT%H:%M:%S") v = int(row[1]) code = int(row[2]) if v == 99999: continue major = code // 10 if major not in (1, 2): sys.exit(f"{path}: version code {code} at {row[0]} is neither final nor provisional; stopping") out[t.replace(minute=0, second=0)] = (v, "final" if major == 2 else "provisional") return out def storms(series, thr, gap_h=48): hours = sorted(h for h, (v, s) in series.items() if v <= thr) groups = [] for h in hours: if groups and (h - groups[-1][-1]) < dt.timedelta(hours=gap_h): groups[-1].append(h) else: groups.append([h]) res = [] for g in groups: hmin = min(g, key=lambda h: (series[h][0], h)) res.append(dict(start=g[0], end=g[-1], min=series[hmin][0], min_hour=hmin, status=series[hmin][1])) return res def fmt(st): h = st["min_hour"] return dict(min_nT=st["min"], hour_UT=f"{h:%Y-%m-%d} {h:%H}-{(h + dt.timedelta(hours=1)):%H} UT", status=st["status"], run_start=f"{st['start']:%Y-%m-%d %H}", run_end=f"{st['end']:%Y-%m-%d %H}") def main(): if len(sys.argv) < 3: sys.exit("usage: python3 dst.py [...]") out = sys.argv[1] os.makedirs(out, exist_ok=True) paths = [] for a in sys.argv[2:]: # a folder stands for every .csv file in it (fetch_inputs.py's /kyoto) if os.path.isdir(a): paths += sorted(os.path.join(a, n) for n in os.listdir(a) if n.lower().endswith(".csv")) else: paths.append(a) series = {} for path in paths: for h, (v, s) in read(path).items(): if h not in series or s == "final": # a final value wins where both exist series[h] = (v, s) D = dt.datetime windows = { "May 2024": (D(2024, 5, 10), D(2024, 5, 13)), "October 2024": (D(2024, 10, 7), D(2024, 10, 13)), "June 2025": (D(2025, 6, 1), D(2025, 7, 1)), "January 2026": (D(2026, 1, 15), D(2026, 2, 1)), "February 2026": (D(2026, 2, 1), D(2026, 3, 1)), "July 2026 (20 Jun - 15 Jul)": (D(2026, 6, 20), D(2026, 7, 16)), "March 2015": (D(2015, 3, 16), D(2015, 3, 20)), "June 2015": (D(2015, 6, 21), D(2015, 6, 25)), } res = {"terms": TERMS, "minima": {}, "storms_le_-50": {}, "rankings": {}} for name, (a, b) in windows.items(): sub = {h: v for h, v in series.items() if a <= h < b} hmin = min(sub, key=lambda h: (sub[h][0], h)) res["minima"][name] = dict(min_nT=sub[hmin][0], hour_UT=f"{hmin:%Y-%m-%d} {hmin:%H}-{(hmin + dt.timedelta(hours=1)):%H} UT", status=sub[hmin][1], hours=len(sub)) res["storms_le_-50"][name] = [fmt(s) for s in storms(sub, -50)] all100 = storms(series, -100) rows = [] tests = { "May 2024": (D(2024, 5, 10), D(2024, 5, 13), {"W20": D(2004, 5, 11), "W2004": D(2004, 1, 1), "W2005": D(2005, 1, 1)}), "October 2024": (D(2024, 10, 7), D(2024, 10, 13), {"W20": D(2004, 10, 10), "W2004": D(2004, 1, 1), "W2005": D(2005, 1, 1)}), } for name, (a, b, wins) in tests.items(): for wname, w0 in wins.items(): inwin = [s for s in all100 if s["min_hour"] >= w0 and s["start"] < b] ranked = sorted(inwin, key=lambda s: (s["min"], s["min_hour"])) target = [s for s in ranked if a <= s["min_hour"] < b][0] rank = ranked.index(target) + 1 res["rankings"][f"{name} {wname} (from {w0:%Y-%m-%d})"] = { "rank": rank, "n_storms_le_-100": len(ranked), "top5": [fmt(s) for s in ranked[:5]]} for i, s in enumerate(ranked[:5]): f = fmt(s) rows.append([name, wname, f"{w0:%Y-%m-%d}", i + 1, f["min_nT"], f["hour_UT"], f["status"], "this storm" if s is target else ""]) with open(os.path.join(out, "dst_storms.json"), "w", newline="\n", encoding="utf-8") as f: json.dump(res, f, indent=1) with open(os.path.join(out, "dst_rankings.csv"), "w", newline="\n", encoding="utf-8") as f: w = csv.writer(f, lineterminator="\n") w.writerow(["# " + TERMS]) w.writerow(["storm", "window", "window_start", "rank", "min_dst_nT", "hour_UT", "status", "note"]) w.writerows(rows) with open(os.path.join(out, "dst_storm_minima.csv"), "w", newline="\n", encoding="utf-8") as f: w = csv.writer(f, lineterminator="\n") w.writerow(["# " + TERMS]) w.writerow(["window", "min_dst_nT", "hour_UT", "status"]) for name, m in res["minima"].items(): w.writerow([name, m["min_nT"], m["hour_UT"], m["status"]]) # the storm list of RULES_meped.txt: every storm at or below -250 nT, July 1998 - December 2023 big = [s for s in storms(series, -250) if D(1998, 1, 1) <= s["min_hour"] < D(2024, 1, 1)] with open(os.path.join(out, "dst_storms_le_-250_1998-2023.csv"), "w", newline="\n", encoding="utf-8") as f: w = csv.writer(f, lineterminator="\n") w.writerow(["# " + TERMS]) w.writerow(["min_dst_nT", "hour_UT", "status", "run_start_UT", "run_end_UT"]) for s in big: f2 = fmt(s) w.writerow([f2["min_nT"], f2["hour_UT"], f2["status"], f2["run_start"], f2["run_end"]]) print(json.dumps(res, indent=1)[:9000]) print("storms at or below -250 nT, 1998-2023:", [(fmt(s)["min_nT"], fmt(s)["hour_UT"]) for s in big]) if __name__ == "__main__": main()