#!/usr/bin/env python3 """Repeat our numbers for /march-2023-storm/ (Fact-Checked Science, "Our analysis"). Standard library only. python3 march_2023_storm.py [--until YYYY-MM-DD] [--no-fetch] It fetches the public inputs listed in inputs.tsv into (about 23 MB, 197 files; a missing file is fetched once, under the plain client name factchecked-research/1.0, with a pause between requests), checks each against the SHA-256 of the copy we used on 11 November 2026, runs the seven analyses beside this file, and writes their outputs into /out/. It then says whether each output equals ours. The inputs, and their terms: gfz_kp/ GFZ's Kp, ap and Ap since 1932 (CC BY 4.0; Matzka et al. 2021, doi:10.5880/Kp.0001). The file grows daily and its newest days are revised, so its hash will differ from ours; --until (default 2026-11-10, the last day in our copy) ignores later rows. kyoto_dst/ WDC Kyoto's hourly Dst, one page a month, March 2017 to September 2026 and March 1989: final pages where they exist, provisional pages otherwise (doi:10.17593/14515-74000). Scientific, non-commercial use, with acknowledgement of the World Data Center for Geomagnetism, Kyoto, and of the observatories that supply the data. This script never asks for a real-time (quicklook) page: Kyoto asks to be contacted before those are used. A provisional month may since have been revised or made final; the script says so. swpc_alerts/ NOAA SWPC's monthly archive of alerts, watches and warnings, March 2017 to March 2023. dtu_chaos87_spline/ CHAOS-8.7's spline coefficients (Kloss et al., DTU Space, CC BY 4.0). dtu_rc_index/ The RC index released with CHAOS-8.7 (Olsen et al. 2014; CC BY 4.0), 13 MB. igrf14/ IGRF-14's coefficients (IAGA V-MOD). horizons_2000_*/ JPL Horizons' positions of the Moon, Mars, Jupiter and Saturn for Rosemary Hill Observatory, 6-7 April 2000 (NASA/JPL); the header of each table carries the time of the request. The analyses (each has its rules file, fixed before its data were read): storm_rank.py RULES_rank.txt was the storm the strongest in six years? dst_recovery.py RULES_recovery.txt did Dst return to its level before the storm? rc_check.py RULES_recovery.txt the same on DTU's RC index (amendment 2) dipole_pace.py RULES_dipole.txt the dipole through 2023 in CHAOS-8.7 photo_geometry.py RULES_photo_geometry.txt where a photograph looks, and where aurora could stand photo_geometry_others.py the same rules, addenda G5 and G6: the photographs of April 2000 and January 2026 photo_stars.py the same rules, addenda G7 and G8: the Chiefland frame solved from its stars, from our measurements of the photograph (chiefland-star-points.tsv, chiefland-tree-line.tsv) Nothing fetched is executed: every input is parsed as text. """ import hashlib import json import os import subprocess import sys import time import urllib.error import urllib.request HERE = os.path.dirname(os.path.abspath(__file__)) UA = "factchecked-research/1.0" PAUSE = 0.6 def sha(path): with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() def get(url): req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=300) as r: return r.read() def fetch(folder, rel, url): """Fetch one input. For a Kyoto month, fall back from provisional to final (never to real-time).""" path = os.path.join(folder, rel.replace("/", os.sep)) os.makedirs(os.path.dirname(path), exist_ok=True) tries = [(rel, url)] if rel.startswith("kyoto_dst/dst_provisional_"): tries.append((rel.replace("dst_provisional_", "dst_final_"), url.replace("/dst_provisional/", "/dst_final/"))) for rel2, url2 in tries: if "/dst_realtime/" in url2: raise SystemExit("refusing to fetch a real-time Dst page") try: data = get(url2) except urllib.error.HTTPError as e: print(f" {url2}: HTTP {e.code}") time.sleep(PAUSE) continue except urllib.error.URLError as e: print(f" {url2}: {e.reason}") time.sleep(PAUSE) continue path2 = os.path.join(folder, rel2.replace("/", os.sep)) with open(path2, "wb") as f: f.write(data) time.sleep(PAUSE) if rel2 != rel: print(f" {rel}: no longer provisional; fetched the final page instead ({rel2})") return path2 return None def main(): args = [a for a in sys.argv[1:] if not a.startswith("--")] if not args: sys.exit(__doc__) folder = os.path.abspath(args[0]) until = "2026-11-10" if "--until" in sys.argv: until = sys.argv[sys.argv.index("--until") + 1] args = [a for a in args if a != until] folder = os.path.abspath(args[0]) no_fetch = "--no-fetch" in sys.argv os.makedirs(folder, exist_ok=True) out = os.path.join(folder, "out") os.makedirs(out, exist_ok=True) rows = [] with open(os.path.join(HERE, "inputs.tsv"), encoding="utf-8") as f: for line in f: if line.startswith("#") or not line.strip(): continue rel, size, digest, url = line.rstrip("\n").split("\t") rows.append((rel, int(size), digest, url)) print(f"{len(rows)} inputs listed; folder {folder}") missing, differ, fetched = [], [], 0 for rel, size, digest, url in rows: path = os.path.join(folder, rel.replace("/", os.sep)) alt = path.replace("dst_provisional_", "dst_final_") if not os.path.exists(path) and os.path.exists(alt): path = alt if not os.path.exists(path): if no_fetch: missing.append(rel) continue got = fetch(folder, rel, url) if got is None: missing.append(rel) continue path = got fetched += 1 if sha(path) != digest: differ.append(rel) print(f"fetched {fetched}; missing {len(missing)}; different from the copies we used: {len(differ)}") for rel in differ: why = (" (expected: the file grows daily)" if rel.startswith("gfz_kp/") else " (expected: the header carries the time of the request)" if rel.startswith("horizons_2000_") else "") print(f" differs: {rel}{why}") for rel in missing: print(f" missing: {rel}") if missing: sys.exit("Some inputs are missing; the analyses were not run.") def run(script, *a): print(f"\n=== {script}") r = subprocess.run([sys.executable, "-I", "-X", "utf8", os.path.join(HERE, script)] + list(a), capture_output=True, text=True, encoding="utf-8") tail = r.stdout.strip().splitlines()[-3:] print("\n".join(tail)) if r.returncode != 0: print(r.stderr) sys.exit(f"{script} failed") j = lambda *p: os.path.join(folder, *p) run("storm_rank.py", os.path.join(HERE, "RULES_rank.txt"), j("gfz_kp", "Kp_ap_Ap_SN_F107_since_1932.txt"), j("kyoto_dst"), j("swpc_alerts"), out, until) run("dst_recovery.py", os.path.join(HERE, "RULES_recovery.txt"), j("kyoto_dst"), out) run("rc_check.py", os.path.join(HERE, "RULES_recovery.txt"), j("dtu_rc_index", "RC_1997-2026_Sept26_v4_allLT.dat"), out) run("dipole_pace.py", os.path.join(HERE, "RULES_dipole.txt"), j("dtu_chaos87_spline", "CHAOS-8.7_spline-coefficients.dat"), j("igrf14", "igrf14coeffs.txt"), out) run("photo_geometry.py", os.path.join(HERE, "RULES_photo_geometry.txt"), out) run("photo_geometry_others.py", os.path.join(HERE, "RULES_photo_geometry.txt"), folder, j("dtu_chaos87_spline", "CHAOS-8.7_spline-coefficients.dat"), out) run("photo_stars.py", os.path.join(HERE, "RULES_photo_geometry.txt"), os.path.join(HERE, "chiefland-star-points.tsv"), os.path.join(HERE, "chiefland-tree-line.tsv"), out) print("\nAgainst the outputs hosted with the page:") for name in ("storm_rank.json", "dst_recovery.json", "rc_check.json", "dipole_pace.json", "photo_geometry.json", "photo_geometry_others.json", "photo_stars.json", "storms-2017-2026.csv", "dipole-yearly-pace.csv"): ours, theirs = os.path.join(HERE, name), os.path.join(out, name) if not os.path.exists(ours): print(f" {name}: no hosted copy beside this script to compare with") continue if name.endswith(".json"): same = json.load(open(ours, encoding="utf-8")) == json.load(open(theirs, encoding="utf-8")) else: same = open(ours, encoding="utf-8").read() == open(theirs, encoding="utf-8").read() print(f" {name}: {'the same' if same else 'DIFFERS (an input has changed since our run, or --until was changed)'}") if __name__ == "__main__": main()