#!/usr/bin/env python3 """Test 7: the note's Figure 3 and Claim 6. Rules: RULES_figure3.txt. Fact-Checked Science, verification of florida-aurora-cycle-25. Standard library only; reads the downloads as data. python3 -I figure3.py Writes /figure3.txt, /figure3_events.csv and /storms_by_cycle.csv. Dst is the World Data Center for Geomagnetism, Kyoto's (final and provisional values only), for scientific, non-commercial use, with acknowledgement of the WDC and the observatories that supply its data. """ import csv import datetime as dt import math import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # our own code folder; -I leaves it out import fclib as F # noqa: E402 import fieldmodels as M # noqa: E402 # event (the note's date field), the note's Dst as printed, the Dst used for the model where Kyoto has none (nT, positive), # and the place(s) the row names: (name, north latitude, east longitude) KW, JAX, CHF = ("Key West", 24.56, -81.78), ("Jacksonville", 30.33, -81.66), ("Chiefland", 29.47, -82.86) EVENTS = [ ("1859-08-28/09-02", "-900 (+50/-150) [E]", 900, [KW], "A"), ("1872-02-04", "<= -834 [E]", 834, [("Mobile", 30.69, -88.04), JAX], "B"), ("1921-05-14/15", "-907 +/-132 [E]", 907, [("San Antonio", 29.42, -98.49), ("Austin", 30.27, -97.74)], "B"), ("1941-09-18/19", "n/a (pre-1957)", 415, [JAX], "A"), # 415 nT: Oulu's Dxt, through Love et al. (2025), Table 1 ("1958-02-11", "-426", None, [("Havana", 23.11, -82.37), ("Mexico City", 19.43, -99.13)], "B"), ("1981-04-12/13", "-311", None, [JAX], "A"), ("1989-03-13/14", "-589", None, [KW, JAX], "A"), ("2003-10-29/31", "-383", None, [JAX], "A"), ("2003-11-20", "-422", None, [CHF], "A"), ("2023-03-23/24", "-163", None, [CHF], "A"), ("2024-05-10/11", "~-410 (prov.)", None, [("Big Pine Key", 24.67, -81.35), ("Tallahassee", 30.44, -84.28)], "A"), ("2024-10-10/11", "-333", None, [KW, ("Lake Mary", 28.76, -81.32)], "A"), ("2025-11-11/12", "-217", None, [("Mims", 28.67, -80.84), ("New Port Richey", 28.24, -82.72)], "A"), ("2026-01-19/20", "-236 (daytime)", None, [("Gulf Coast 29.69N, 83.4W", 29.69, -83.4), KW], "A"), ] CYCLES = [(17, dt.datetime(1933, 9, 1)), (18, dt.datetime(1944, 2, 1)), (19, dt.datetime(1954, 4, 1)), (20, dt.datetime(1964, 10, 1)), (21, dt.datetime(1976, 3, 1)), (22, dt.datetime(1986, 9, 1)), (23, dt.datetime(1996, 8, 1)), (24, dt.datetime(2008, 12, 1)), (25, dt.datetime(2019, 12, 1))] SIGMA_LNL = 0.5478 * 0.2413 # the model's 68% range, as a shift in ln L def decimal_year(d): y0 = dt.date(d.year, 1, 1) return d.year + (d - y0).days / ((dt.date(d.year + 1, 1, 1) - y0).days) def main(): dl, outdir = sys.argv[1], sys.argv[2] kp, _ = F.read_kp(os.path.join(dl, "gfz-kp", "Kp_ap_Ap_SN_F107_since_1932.txt")) dst, kinds = F.read_dst_folder(os.path.join(dl, "kyoto-dst")) fm = os.path.join(dl, "field-models") igrf = M.read_igrf(os.path.join(fm, "igrf14coeffs.txt")) gufm = M.SplineModel(os.path.join(fm, "gufm1.txt"), "gufm1") lines = [] out = lines.append def cd(lat, lon, t): c = gufm.at(t) if t < 1900.0 else M.igrf_at(igrf, t) d = M.dipole(c) return M.cd_latitude(M.geocentric(lat), lon, d["plat"], d["plon"]) out("TEST 7. Figure 3 and Claim 6 (rules: RULES_figure3.txt)") out("") out("Part 1. The plotted values against Kyoto's Dst (lowest hourly value on the event's UT days and the day after)") rows = [] for date, note_dst, recon, places, path in EVENTS: d0, d1 = F.parse_event_dates(date) t0 = dt.datetime.combine(d0, dt.time()) t1 = dt.datetime.combine(d1, dt.time()) + dt.timedelta(days=2) vals = [(v, t) for t, v in dst.items() if t0 <= t < t1] ks = [v for t, v in kp.items() if t0 <= t < t1 - dt.timedelta(days=1)] kmax = F.kpname(max(ks)) if ks else "no Kp" if vals: low, when = min(vals) ym = when.strftime("%Y%m") kind = kinds.get(ym, "?") out(f" {date:17s} note {note_dst:20s} Kyoto {low:5d} nT at {when:%Y-%m-%d %H}-{(when + dt.timedelta(hours=1)):%H} UT ({kind}); highest Kp {kmax}") D = -low else: low, when, kind = None, None, "no Kyoto Dst before 1957" out(f" {date:17s} note {note_dst:20s} {kind}; the model below uses {recon} nT; highest Kp {kmax}") D = recon edge = F.love_edge_lat(D) lo_e, hi_e = F.love_edge_lat(D, +SIGMA_LNL), F.love_edge_lat(D, -SIGMA_LNL) for name, la, lon in places: c = cd(la, lon, decimal_year(d0)) rows.append([date, path, name, la, lon, f"{c:.2f}", low if low is not None else "", kind, D, kmax, f"{edge:.1f}", f"{lo_e:.1f}", f"{hi_e:.1f}", f"{edge - c:.1f}", f"{lo_e - c:.1f}", f"{hi_e - c:.1f}"]) out("") out("Part 2a. By Kp: the events' highest three-hour Kp on their UT days") seen = set() for r in rows: if r[0] not in seen: seen.add(r[0]) out(f" {r[0]:17s} Kp {r[9]:5s} Dst used {-r[8]:5d} nT") out("") out("Part 2b. Arc from each named place to the edge of overhead aurora on Love et al.'s model (degrees; 68% range in brackets)") out(" event path place cd lat D nT edge arc to edge") for r in rows: out(f" {r[0]:17s} {r[1]} {r[2]:26s} {r[5]:>6s} {r[8]:5d} {r[10]:>5s} {r[13]:>5s} [{r[14]} to {r[15]}]") out(" horizon arcs (no refraction): " + ", ".join(f"{h} km {math.degrees(math.acos(M.A_KM / (M.A_KM + h))):.1f} deg" for h in (250, 300, 400, 650, 950))) c25 = [float(r[13]) for r in rows if r[0] >= "2019"] pre = [float(r[13]) for r in rows if r[0] < "2019" and r[1] == "A"] out(f" cycle 25, Florida places: arcs {min(c25):.1f} to {max(c25):.1f} deg (median {sorted(c25)[len(c25) // 2]:.1f}); earlier Path A events: {min(pre):.1f} to {max(pre):.1f} deg") out(f" cycle-25 records beyond 24.8 deg: {sum(1 for a in c25 if a > 24.8)}; beyond 19.8 deg (400 km): {sum(1 for a in c25 if a > 19.8)}") out("") out("Part 2c. The whole supply of storms at Dst <= -200 nT, by era, with the note's hit flags (our rebuilt list, reading A)") with open(os.path.join(outdir, "our_storms_24h.csv"), encoding="utf-8", newline="") as f: storms = [r for r in csv.DictReader(x for x in f if not x.startswith("#"))] for era in ("1986-2019Nov", "C25"): S = sorted([(int(r["dst_min_nT"]), int(r["hit_path_a"]), r["start_UT"][:10]) for r in storms if r["stratum"] == "Dst<=-200" and r["era"] == era]) out(f" {era}: {len(S)} storms, {sum(h for _, h, _ in S)} hits") out(" " + "; ".join(f"{d}{'*' if h else ''}" for d, h, _ in S) + " (* = a Florida record in the note's Path A)") weakest_hit = max(d for d, h, _ in S if h) half = None for i in range(len(S)): frac = sum(h for _, h, _ in S[:i + 1]) / (i + 1) if frac >= 0.5: half = S[i][0] out(f" weakest storm with a hit: {weakest_hit} nT; weakest Dst at which half or more of the storms at least that strong have hits: {half} nT") if era == "1986-2019Nov": w0, h0 = weakest_hit, half else: w1, h1 = weakest_hit, half kp8 = sorted([(int(r["dst_min_nT"]), r["start_UT"][:10]) for r in storms if r["stratum"] == "Kp>=8-" and r["era"] == "C25" and r["hit_path_a"] == "1"]) out(f" cycle 25's weakest storm with a hit in any stratum (Kp >= 8-): {kp8[-1][0]} nT (window value) on {kp8[-1][1]}; Kyoto's lowest for March 2023 is in Part 1") for a, b, label in ((w0, w1, "weakest hit"), (h0, h1, "half-point"), (w0, -163, "weakest hit, with March 2023")): ea, eb = F.love_edge_lat(-a), F.love_edge_lat(-b) out(f" {label}: {a} nT then, {b} nT now: the model's edge at {ea:.1f} and {eb:.1f} deg, {eb - ea:.1f} deg apart") out(" what the dipole's change can do, by the published scalings (the 1 November page): 0-0.3 deg for the 1.04% fall of 2003-2024") out(" (up to about 0.5 deg at 30-36 deg); 0-3.0 deg for the 9.45% fall of 1859-2025") out("") out("Part 2e. Records at Florida's magnetic latitude that Figure 3 lacks (found by us; not a census), by the same measures") extra = [ ("1959-11-27/28", "Houston, Texas", 29.76, -95.37, "naked eye (AP, 28 Nov 1959); a Gulf equivalent"), ("1969-03-23/24", "Lake Charles, Louisiana", 30.23, -93.22, "naked eye (AP, 24 Mar 1969); a Gulf equivalent"), ("1982-09-21/22", "McDonald Observatory, Texas", 30.67, -104.02, "instruments (Rassoul et al. 1993); a Gulf-latitude equivalent"), ("2000-04-06/07", "Rosemary Hill Observatory, Florida", 29.40, -82.59, "photograph (the 1 November page)"), ("2000-07-15/16", "Florida, no place named", 30.33, -81.66, "a 2022 retelling (Spaceweather.com's blog); from Jacksonville"), ("2001-03-30/31", "Mexico and Texas, no place named", 29.76, -95.37, "a sentence at the time (Spaceweather.com); from Houston's latitude"), ("2001-11-05/06", "Florida, no place named", 30.33, -81.66, "a sentence at the time (Spaceweather.com); from Jacksonville"), ("2004-11-07/08", "Florida, by inference", 30.33, -81.66, "'every US state but Hawaii' (Spaceweather.com's index); from Jacksonville"), ("2023-04-23/24", "Terlingua, Texas", 29.33, -103.62, "camera (Spaceweather.com, 24 Apr 2023); a Gulf-latitude equivalent"), ] rows_extra = [] for date, place, la, lon, what in extra: d0, d1 = F.parse_event_dates(date) t0 = dt.datetime.combine(d0, dt.time()) t1 = dt.datetime.combine(d1, dt.time()) + dt.timedelta(days=2) vals = [(v, t) for t, v in dst.items() if t0 <= t < t1] ks = [v for t, v in kp.items() if t0 <= t < t1 - dt.timedelta(days=1)] low, when = min(vals) c = cd(la, lon, decimal_year(d0)) edge = F.love_edge_lat(-low) out(f" {date:14s} {place:34s} cd {c:5.1f} Kp {F.kpname(max(ks)):3s} Dst {low:5d} nT ({kinds.get(when.strftime('%Y%m'), '?')}) arc to the model's edge {edge - c:5.1f} | {what}") rows_extra.append([date, place, la, lon, f"{c:.2f}", low, kinds.get(when.strftime("%Y%m"), "?"), F.kpname(max(ks)), f"{edge:.1f}", f"{edge - c:.1f}", what]) with open(os.path.join(outdir, "figure3_records_not_in_note.csv"), "w", encoding="utf-8", newline="\n") as f: f.write("# Records at Florida's magnetic latitude that the note's Figure 3 lacks, as found by us (not a census). Kp: GFZ, CC BY 4.0.\n") f.write("# Dst: WDC for Geomagnetism, Kyoto, final or provisional; scientific, non-commercial use, with acknowledgement of the WDC and the observatories.\n") w = csv.writer(f, lineterminator="\n") w.writerow(["event", "place", "lat", "lon", "cd_lat", "kyoto_dst_min", "kyoto_kind", "kp_max", "love_edge", "arc_to_edge", "record"]) w.writerows(rows_extra) out("") out("Part 3. Storms per cycle (GFZ's Kp; a storm is a run of consecutive UT days at or above the threshold, the 1 November page's rule)") end = F.FREEZE rows3 = [] for i, (n, start) in enumerate(CYCLES): stop = CYCLES[i + 1][1] if i + 1 < len(CYCLES) else end years = (stop - start).total_seconds() / 86400 / 365.25 counts = [] for thr in (9.0, 8.667, 7.667): days = sorted({t.date() for t, v in kp.items() if start <= t < stop and v >= thr - 1e-3}) runs = 0 prev = None for d in days: if prev is None or (d - prev).days > 1: # runs of consecutive UT days, as aurora_numbers.py on the 1 November page runs += 1 prev = d counts.append(runs) note_rule = len([s for s in F.build_storms([t for t, v in kp.items() if start <= t < stop and v >= 8.667 - 1e-3], 3, 24, "A")]) rows3.append([n, start.strftime("%Y-%m"), f"{years:.2f}", counts[0], counts[1], counts[2], note_rule, f"{counts[1] / years:.2f}"]) out(f" cycle {n} ({start:%Y-%m}, {years:5.2f} yr): Kp 9o {counts[0]:2d}; Kp >= 9- {counts[1]:2d} ({counts[1] / years:.2f} a year; {note_rule} by the note's 24 h rule); Kp >= 8- {counts[2]:2d}") with open(os.path.join(outdir, "storms_by_cycle.csv"), "w", encoding="utf-8", newline="\n") as f: f.write("# Our count from GFZ's Kp (CC BY 4.0): storms per solar cycle; cycle 25 to 2026-10-30 14 UT.\n") w = csv.writer(f, lineterminator="\n") w.writerow(["cycle", "starts", "years", "kp_9o", "kp_9minus_or_more", "kp_8minus_or_more", "kp_9minus_or_more_note_rule", "kp_9minus_or_more_per_year"]) w.writerows(rows3) with open(os.path.join(outdir, "figure3_events.csv"), "w", encoding="utf-8", newline="\n") as f: f.write("# Our analysis of the events in S0 News research note 004: Kyoto's lowest Dst (final or provisional; scientific, non-commercial use,\n") f.write("# with acknowledgement of the WDC for Geomagnetism, Kyoto, and the observatories), GFZ's Kp (CC BY 4.0), and the arc to Love et al.'s (2025) edge.\n") w = csv.writer(f, lineterminator="\n") w.writerow(["event", "path", "place", "lat", "lon", "cd_lat", "kyoto_dst_min", "kyoto_kind", "D_used", "kp_max", "love_edge", "love_edge_lo", "love_edge_hi", "arc_to_edge", "arc_lo", "arc_hi"]) w.writerows(rows) with open(os.path.join(outdir, "figure3.txt"), "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(lines) + "\n") sys.stdout.reconfigure(encoding="utf-8", newline="\n") print("\n".join(lines)) if __name__ == "__main__": main()