#!/usr/bin/env python3 """Why two pages counted 185 and 187 storms at Kp 8o or more from 1932 to 22 March 2023 (281 and 284 at Kp 8- or more). Fact-Checked Science ("Our analysis"), for /florida-aurora-cycle-25/ and /s0-news-2026-11-11/. Standard library only. Run: python3 -I storm_count_reconcile.py [] Both pages merge "threshold intervals whose starts are 24 h or less apart", chained. They differ in what an interval is: A each three-hour value at or above the threshold is an interval (this page; reproduces the note's lists row for row); C consecutive values are first joined into runs, and a run is an interval (the first count on /s0-news-2026-11-11/). Under C a long run can end less than 24 h before the next run starts while its START is more than 24 h before it, so C splits what A joins. This script lists every storm the two readings count differently, and, if the note's own list is given, says which reading its rows follow in 1986-2026. Written after the two counts were seen to differ; it is a reconciliation, not a pre-registered test. """ import csv import datetime as dt import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from fclib import build_storms, kpname, read_kp # noqa: E402 sys.stdout.reconfigure(encoding="utf-8", newline="\n") PAST_BEFORE = dt.datetime(2023, 3, 23) THR = [("8o", 8.0), ("8-", 7.667), ("9-", 8.667)] def main(): kp, day = read_kp(sys.argv[1]) note = sys.argv[2] if len(sys.argv) > 2 else None print("GFZ Kp from", min(kp).date(), "to", max(kp).date()) for name, thr in THR: stamps = [t for t, v in kp.items() if v >= thr - 0.001 and t < PAST_BEFORE] a = build_storms(stamps, 3, 24, "A") c = build_storms(stamps, 3, 24, "C") runs = build_storms(stamps, 3, 0, "A") # gap 0: every value alone print("\nKp >= %s, 1932 to 22 March 2023: %d three-hour values; storms by reading A %d, by reading C %d" % (name, len(runs), len(a), len(c))) a_starts = {s[0] for s in a} extra = [s for s in c if s[0] not in a_starts] for s in extra: parent = max((x for x in a if x[0] <= s[0]), key=lambda x: x[0]) inside = sorted(t for t in stamps if parent[0] <= t <= parent[1]) prev = max(t for t in inside if t < s[0]) # the run that the split-off run follows run_start = prev while run_start - dt.timedelta(hours=3) in inside: run_start -= dt.timedelta(hours=3) print(" A has one storm %s to %s (%d values, highest Kp %s); C splits it at %s:" % (parent[0].strftime("%Y-%m-%d %H UT"), parent[1].strftime("%Y-%m-%d %H UT"), len(inside), kpname(max(kp[t] for t in inside)), s[0].strftime("%Y-%m-%d %H UT"))) print(" the run before it starts %s and its last value starts %s; the next run starts %.0f h after that" " run's start and %.0f h after its last value" % (run_start.strftime("%Y-%m-%d %H UT"), prev.strftime("%Y-%m-%d %H UT"), (s[0] - run_start).total_seconds() / 3600, (s[0] - prev).total_seconds() / 3600)) if note: with open(note, encoding="utf-8-sig", newline="") as f: rows = list(csv.DictReader(f)) print("\nThe note's own 24 h list (%d rows), 1986 to its freeze, against each reading:" % len(rows)) for name, thr, label in (("8-", 7.667, "Kp>=8-"), ("8o", 8.0, "Kp>=8o"), ("9-", 8.667, "Kp>=9-")): mine = [r for r in rows if r.get("stratum", "").replace(" ", "") in (label, label.replace(">=", "≥"))] if not mine: keys = sorted({r.get("stratum", "") for r in rows}) print(" stratum names in the file:", keys) break starts = sorted(r["start_UT"][:13] for r in mine) stamps = [t for t, v in kp.items() if v >= thr - 0.001 and dt.datetime(1986, 1, 1) <= t < dt.datetime(2026, 10, 30, 14)] for reading in ("A", "C"): ours = sorted(s[0].strftime("%Y-%m-%d %H") for s in build_storms(stamps, 3, 24, reading)) ours_n = sorted(x.replace(" ", "T") for x in ours) theirs_n = sorted(x.replace(" ", "T") for x in starts) only_ours = [x for x in ours_n if x not in theirs_n] only_theirs = [x for x in theirs_n if x not in ours_n] print(" %s reading %s: ours %d, the note's %d; in ours only %s; in the note's only %s" % (label, reading, len(ours_n), len(theirs_n), only_ours or "none", only_theirs or "none")) if __name__ == "__main__": main()