#!/usr/bin/env python3 """The May 2024 storm's drivers, as Kitamura et al. (2026) describe them, checked against the public records. Fact-Checked Science, November 2026, for the paper check "ring-current-oxygen" ("Our analysis"). The rules were written before the OMNI and Kyoto files were fetched: RULES_paper_numbers.txt, beside this script. Standard library only. Run it python3 storm_numbers.py [folder] [--series FILE.csv] The folder (default: ./ring-current-oxygen-data) must hold, or will receive, the inputs below. A missing file is downloaded from its maker under a plain client name and checked against the SHA-256 of the copy we used on November 13, 2026 (GFZ's file grows every day, so its hash will differ; its values for 2024 are definitive). The script prints its log and writes storm-numbers.json into the folder. With --series it also writes the series our storm chart draws (SYM-H as 6-minute minima and maxima; OMNI's Bz and flow pressure every 5 minutes). Inputs Kp_ap_Ap_SN_F107_since_1932.txt GFZ (Kp, CC BY 4.0; daily F10.7 from DRAO/NRCan): https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt symh_20240510_12.csv World Data Center for Geomagnetism, Kyoto: one-minute SYM-H with its version code, doi:10.14989/267216, through the WDC's HAPI server. Used under the WDC's rules (https://wdc.kugi.kyoto-u.ac.jp/wdc/Sec3.html): scientific, non-commercial use, with acknowledgement. The script refuses to report a real-time value (version 0x). omni_hro_5min_20240510_12.csv NASA/GSFC OMNI 5-minute solar wind at the bow shock (King & Papitashvili), Space Physics Data Facility, through CDAWeb's HAPI server. omni2_f107_2001.csv, omni2_f107_2014.csv, omni2_f107_2024.csv OMNI2 hourly F10.7 (from NGDC/NOAA), CDAWeb HAPI: the series whose yearly means match the paper's (a follow-up test, added after the registered test missed). Added after the fresh review: the speed's median as the mean of the two middle values; and the energy-window arithmetic (how the solar wind's upper limit on pass 2 would grow if hydrogen's energy flux stayed flat above the instrument's 184.2 keV per charge). """ import datetime as dt import hashlib import json import math import os import sys import urllib.request UA = "factchecked-research/1.0" RULES_SHA256 = "076efb077c8c2a341e1946673d59aed13fcf4c7bfc154801c971446bb9e9371c" HAPI_K = "https://wdc.kugi.kyoto-u.ac.jp/hapi/data?id=min_asysym¶meters=symHValue,versionCode" HAPI_C = "https://cdaweb.gsfc.nasa.gov/hapi/data?id=" INPUTS = { "Kp_ap_Ap_SN_F107_since_1932.txt": ("https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt", "cc76277f192590b5918d4148e6d22d73608568032fb84f2bab18fb4268cd377e"), "symh_20240510_12.csv": (HAPI_K + "&time.min=2024-05-10T12:00:00Z&time.max=2024-05-12T00:00:00Z&format=csv", "adf65f16887b63c3083ed44fe42e7357e57a514b33b2115aa220df382cf8a391"), "omni_hro_5min_20240510_12.csv": (HAPI_C + "OMNI_HRO_5MIN¶meters=IMF,PLS,F,BY_GSM,BZ_GSM,flow_speed,proton_density," "Pressure,E&time.min=2024-05-10T16:00:00Z&time.max=2024-05-12T00:00:00Z&format=csv", "590a16b8e376c64b7ce875d47de56fdc81f8af10d32f25c7eb853576a223b14f"), "omni2_f107_2001.csv": (HAPI_C + "OMNI2_H0_MRG1HR¶meters=F10_INDEX1800&time.min=2001-01-01T00:00:00Z&time.max=2002-01-01T00:00:00Z&format=csv", "359e92fd211024a45b2f1c3d9a871fe6239c4b5a4cf87c4ff267a9de55765b24"), "omni2_f107_2014.csv": (HAPI_C + "OMNI2_H0_MRG1HR¶meters=F10_INDEX1800&time.min=2014-01-01T00:00:00Z&time.max=2015-01-01T00:00:00Z&format=csv", "ede19152910a824cd9277b84968e56e3fc18b05a03c2eaaad141f5b15c390d99"), "omni2_f107_2024.csv": (HAPI_C + "OMNI2_H0_MRG1HR¶meters=F10_INDEX1800&time.min=2024-01-01T00:00:00Z&time.max=2025-01-01T00:00:00Z&format=csv", "5dc8e452157831a658fc2ccb6c2aa108c09febae3b160acc1b4d031ae8cc4d63"), } FILL = {"F": 9999.99, "BY": 9999.99, "BZ": 9999.99, "V": 99999.9, "N": 999.99, "P": 99.99, "E": 999.99} ORBITS = {"Orbit 1": (dt.datetime(2024, 5, 10, 16, 48, 0), dt.datetime(2024, 5, 10, 18, 54, 5)), "Orbit 2": (dt.datetime(2024, 5, 11, 2, 36, 0), dt.datetime(2024, 5, 11, 4, 9, 11)), "Orbit 3": (dt.datetime(2024, 5, 11, 10, 54, 0), dt.datetime(2024, 5, 11, 13, 40, 14))} def sha256(path): h = hashlib.sha256() with open(path, "rb") as f: for chunk in iter(lambda: f.read(1 << 20), b""): h.update(chunk) return h.hexdigest() def fetch_inputs(folder, say): os.makedirs(folder, exist_ok=True) for name, (url, want) in INPUTS.items(): path = os.path.join(folder, name) if not os.path.exists(path): say("downloading %s" % url) req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=300) as r, open(path, "wb") as f: f.write(r.read()) got = sha256(path) say("%s SHA-256 %s (%s)" % (name, got, "same as the copy we used" if got == want else "DIFFERENT from the copy we used, %s" % want[:12])) def t(s): return dt.datetime.strptime(s[:19], "%Y-%m-%dT%H:%M:%S") def main(): args = [a for a in sys.argv[1:] if not a.startswith("--")] series_out = sys.argv[sys.argv.index("--series") + 1] if "--series" in sys.argv else None if series_out in args: args.remove(series_out) folder = args[0] if args else "ring-current-oxygen-data" log = [] def say(s): log.append(s) print(s) say("storm_numbers.py, run at %s UTC" % dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")) rules = os.path.join(os.path.dirname(os.path.abspath(__file__)), "RULES_paper_numbers.txt") if os.path.exists(rules): got = sha256(rules) say("rules SHA-256 %s (%s)" % (got, "as registered" if got == RULES_SHA256 else "NOT the registered file")) fetch_inputs(folder, say) res = {} # 1. F10.7 (GFZ: DRAO/NRCan observed and adjusted fluxes) daily = {} with open(os.path.join(folder, "Kp_ap_Ap_SN_F107_since_1932.txt"), encoding="utf-8") as f: for line in f: if line.startswith("#") or not line.strip(): continue p = line.split() daily[dt.date(int(p[0]), int(p[1]), int(p[2]))] = { "kp": [float(v) for v in p[7:15]], "obs": float(p[25]), "adj": float(p[26]), "D": int(p[27])} res["f107_obs_may2024"] = {} for k in range(6, 14): d = dt.date(2024, 5, k) res["f107_obs_may2024"][str(d)] = daily[d]["obs"] say("%s: F10.7 observed %.1f, adjusted %.1f; Kp max %.3f (flag %d)" % (d, daily[d]["obs"], daily[d]["adj"], max(daily[d]["kp"]), daily[d]["D"])) yearly = {} for y in range(1996, 2026): for key in ("obs", "adj"): vals = [v[key] for d, v in daily.items() if d.year == y and v[key] > 0] yearly.setdefault(str(y), {})[key] = round(sum(vals) / len(vals), 2) for c, yrs in {"23": range(1996, 2009), "24": range(2009, 2020), "25": range(2020, 2026)}.items(): best = max(yrs, key=lambda y: yearly[str(y)]["obs"]) say("cycle %s: largest yearly mean of observed F10.7 %d, %.1f" % (c, best, yearly[str(best)]["obs"])) res["f107_yearly_gfz"] = {y: yearly[y] for y in ("2001", "2014", "2024")} omni2 = {} for y in ("2001", "2014", "2024"): vals = [] with open(os.path.join(folder, "omni2_f107_%s.csv" % y), encoding="utf-8") as f: for line in f: a = line.strip().split(",") if len(a) == 2 and float(a[1]) < 999: vals.append(float(a[1])) omni2[y] = round(sum(vals) / len(vals), 2) res["f107_yearly_omni2"] = omni2 say("yearly F10.7, GFZ observed / adjusted / OMNI2: " + "; ".join( "%s %.1f / %.1f / %.1f" % (y, yearly[y]["obs"], yearly[y]["adj"], omni2[y]) for y in ("2001", "2014", "2024"))) # 2. SYM-H (provisional; no real-time value is reported) sym = [] with open(os.path.join(folder, "symh_20240510_12.csv"), encoding="utf-8") as f: for line in f: a = line.strip().split(",") if len(a) == 3: sym.append((t(a[0]), int(a[1]), int(a[2]))) versions = sorted(set(s[2] for s in sym)) if any(v < 10 for v in versions): sym = [s for s in sym if s[2] >= 10] say("real-time SYM-H values (version 0x) were dropped, under the WDC's rules") vmin = min(s[1] for s in sym) res["symh"] = {"min_nT": vmin, "min_times": [s[0].isoformat() for s in sym if s[1] == vmin], "version_codes": versions, "at_0236_11may": [s[1] for s in sym if s[0] == dt.datetime(2024, 5, 11, 2, 36)], "orbits": {}} for name, (a, b) in ORBITS.items(): vals = [s[1] for s in sym if a <= s[0] <= b] res["symh"]["orbits"][name] = [min(vals), max(vals)] say("SYM-H minimum %d nT at %s (version codes %s); %s nT at 02:36 UT on 11 May; by pass %s" % ( vmin, res["symh"]["min_times"], versions, res["symh"]["at_0236_11may"], res["symh"]["orbits"])) # 3. OMNI 5-minute solar wind rows = [] with open(os.path.join(folder, "omni_hro_5min_20240510_12.csv"), encoding="utf-8") as f: for line in f: a = line.strip().split(",") if len(a) != 10: continue r = {"t": t(a[0]), "F": float(a[3]), "BY": float(a[4]), "BZ": float(a[5]), "V": float(a[6]), "N": float(a[7]), "P": float(a[8]), "E": float(a[9])} for k, fv in FILL.items(): if r[k] >= fv: r[k] = None rows.append(r) def sel(a, b, key): return [(r["t"], r[key]) for r in rows if a <= r["t"] < b and r[key] is not None] v = sel(dt.datetime(2024, 5, 10, 18), dt.datetime(2024, 5, 11, 18), "V") vs = sorted(x[1] for x in v) # the median: the mean of the two middle values for an even count (corrected after the fresh review; the # registered run took the upper of the two, 727.6 km/s) v_median = (vs[(len(vs) - 1) // 2] + vs[len(vs) // 2]) / 2 n = sel(dt.datetime(2024, 5, 10, 17), dt.datetime(2024, 5, 11, 12), "N") bz = sel(dt.datetime(2024, 5, 10, 17), dt.datetime(2024, 5, 11, 18), "BZ") blocks = [] tb = dt.datetime(2024, 5, 10, 15) while tb < dt.datetime(2024, 5, 12): vals = [x[1] for x in sel(tb, tb + dt.timedelta(hours=3), "BZ")] if vals: blocks.append((tb.isoformat(), round(sum(vals) / len(vals), 1))) tb += dt.timedelta(hours=3) res["omni_checks"] = { "speed_share_above_700": sum(1 for x in vs if x > 700) / len(vs), "speed_share_above_680": sum(1 for x in vs if x > 680) / len(vs), "speed_median": v_median, "speed_min": vs[0], "density_max": max(n, key=lambda x: x[1])[1], "bz_share_negative": sum(1 for x in bz if x[1] < 0) / len(bz), "bz_3h_blocks": blocks} ext = {} for key, fn in (("BZ", min), ("F", max), ("V", max), ("N", max), ("P", max), ("E", max)): x = fn(sel(dt.datetime(2024, 5, 10, 16), dt.datetime(2024, 5, 12), key), key=lambda q: q[1]) ext[key] = [x[1], x[0].isoformat()] res["omni_extremes"] = ext res["omni_orbits"] = {} for name, (a, b) in ORBITS.items(): out = {} for key in ("V", "N", "P", "BZ"): s = [x[1] for x in sel(a, b + dt.timedelta(minutes=1), key)] out[key] = [min(s), round(sum(s) / len(s), 1), max(s), len(s)] res["omni_orbits"][name] = out say("OMNI: speed above 700 km/s in %.0f%% of samples (above 680: %.0f%%; median %.0f, minimum %.0f km/s); density up to %.1f per cm3; Bz negative in %.0f%%" % ( 100 * res["omni_checks"]["speed_share_above_700"], 100 * res["omni_checks"]["speed_share_above_680"], v_median, vs[0], res["omni_checks"]["density_max"], 100 * res["omni_checks"]["bz_share_negative"])) say("OMNI extremes: " + "; ".join("%s %s at %s" % (k, val[0], val[1]) for k, val in ext.items())) # 4. The energy window (added after the fresh review). MEP-i counts 9.6-184.2 keV per charge. If the energy flux # per unit energy stayed flat, energy density would grow as the square root of energy, since it is the integral of # J_E / v over energy. Pass 2's upper limits: H+ under about 10%, He under 4%, Earth's heavy ions the rest. lo_e, hi_e = 9.6, 184.2 span = math.sqrt(hi_e) - math.sqrt(lo_e) flat_contours = {str(q): round((math.sqrt(lo_e) + q * span) ** 2, 1) for q in (0.25, 0.5, 0.75)} h_in, he_in, heavy_in = 10.0, 4.0, 86.0 light_if_flat = {} for top in (300.0, 1000.0, 2000.0): h_all = h_in * (1 + (math.sqrt(top) - math.sqrt(hi_e)) / span) light_if_flat[str(int(top))] = round(100 * (h_all + he_in) / (h_all + he_in + heavy_in), 1) res["energy_window"] = {"flat_spectrum_cumulative_contours_keV": flat_contours, "light_ion_upper_limit_pass2_percent_if_H_flat_to_keV": light_if_flat} say("energy window (added after the review): for a flat spectrum the 0.25/0.5/0.75 contours fall at %s keV per charge; " "pass 2's light-ion upper limit if H+ stayed flat to 300 keV, 1 MeV, 2 MeV: %s%%" % ( ", ".join(str(v) for v in flat_contours.values()), ", ".join(str(v) for v in light_if_flat.values()))) if series_out: with open(series_out, "w", encoding="utf-8", newline="\n") as f: f.write("kind,time_utc,value\n") t0 = dt.datetime(2024, 5, 10, 16) while t0 < dt.datetime(2024, 5, 12): vals = [s for s in sym if t0 <= s[0] < t0 + dt.timedelta(minutes=6)] if vals: lo, hi = min(vals, key=lambda s: s[1]), max(vals, key=lambda s: s[1]) for s in sorted({lo, hi}, key=lambda s: s[0]): f.write("symh,%s,%d\n" % (s[0].isoformat(), s[1])) t0 += dt.timedelta(minutes=6) for r in rows: for key, name in (("BZ", "bz"), ("P", "pdyn")): if r[key] is not None: f.write("%s,%s,%s\n" % (name, r["t"].isoformat(), r[key])) say("wrote the chart series to %s (not hosted)" % series_out) out = os.path.join(folder, "storm-numbers.json") with open(out, "w", encoding="utf-8", newline="\n") as f: json.dump(res, f, indent=1) f.write("\n") say("wrote %s" % out) if __name__ == "__main__": main()