#!/usr/bin/env python3 """Draw the three charts of /florida-aurora-cycle-25/ from our own outputs, as HTML and inline SVG. Fact-Checked Science ("Our analysis"). Standard library only. python3 -I charts.py Reads /our_storms_24h.csv (storm_lists.py) and the field-model files in /field-models. Writes, into /charts/: chart_pvalues.html (the note's three tests under four counts for cycle 25, on two baselines), chart_strips.svg.html (every storm at Dst -200 nT or below since 1986, and which left a Florida record, with its numbers in /storms_dst200_records.csv) and chart_latitude.svg.html (Orlando's magnetic latitude, 1859-2026); /florida-latitude-series.csv, the numbers behind the third; and /latitude_changes.txt, the table of the page's section 8. None of them redraws a figure of S0 News's note: they chart our own analysis of public data. Colours are classes styled by the page's page.css with the site's --chart-* tokens; every mark also differs in shape and carries its value in text or in a title. Kp: GFZ Helmholtz Centre for Geosciences, CC BY 4.0. Dst: WDC for Geomagnetism, Kyoto, 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 math import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) # our own code folder; -I leaves it out import fclib as F # noqa: E402 import fieldmodels as M # noqa: E402 MINUS = "−" # Our record for each storm at Dst <= -200 nT (by the UT date its Dst interval starts in our_storms_24h.csv), from # records_storms.csv and the page's section 4. Kinds: "eye" reported seen at the time (version 2, after the fresh review: October # 2024 is classed with May 2024, as its accounts are of the same kind); "cam" camera only; "add" a Florida record that the note's list lacks; # "inf" Florida by inference or a later retelling, or a record from the Gulf coast only; anything else: nothing found. RECORDS = { "1989-03-13": ("eye", "March 1989: reports from Florida (in the note’s list)"), "2003-10-29": ("eye", "October 2003: Florida named at the time (in the note’s list)"), "2003-11-20": ("eye", "November 20, 2003: Florida named at the time (in the note’s list)"), "2000-04-06": ("add", "April 6–7, 2000: a photograph from central Florida (not in the note’s list)"), "2001-11-06": ("add", "November 5–6, 2001: Florida named at the time (not in the note’s list)"), "2000-07-15": ("inf", "July 2000: Florida named only in a later retelling"), "2004-11-08": ("inf", "November 7–8, 2004: Florida by inference (every US state except Hawaii)"), "2001-03-31": ("inf", "March 30–31, 2001: Texas and Mexico named; Florida not"), "2023-04-24": ("inf", "April 23–24, 2023: a camera record from Terlingua, Texas; none from Florida"), "2024-05-10": ("eye", "May 10–11, 2024: reported seen across Florida at the time (in the note’s list)"), "2024-10-10": ("eye", "October 10–11, 2024: reported seen at the time, from Key West to Tallahassee; the note marks it mostly camera (in the note’s list)"), "2025-11-12": ("eye", "November 11–12, 2025: seen by eye, faintly, by several accounts (in the note’s list)"), "2026-01-20": ("cam", "January 19–20, 2026: one photographer’s phone camera; the note marks it camera-dominant (in the note’s list)"), } # (start date, text, where the label goes: "below", "above" or "top"; text anchor; x offset) LABELS = { "1989-03-13": ("Mar 1989", "below", "middle", 0), "2003-11-20": ("Nov 2003", "below", "start", -4), "2003-10-29": ("Oct 2003", "below", "end", 6), "2000-04-06": ("Apr 2000, Nov 2001", "below", "middle", 0), "2024-05-10": ("May 2024", "below", "middle", 0), "2024-10-10": ("Oct 2024", "below", "middle", 0), "2025-11-12": ("Nov 2025", "above", "middle", 0), "2026-01-20": ("Jan 2026", "below", "start", -6), } def f1(x): return "%.1f" % x def num(v): return ("%d" % v).replace("-", MINUS) def write(outdir, name, text): with open(os.path.join(outdir, name), "w", encoding="utf-8", newline="\n") as f: f.write(text + "\n") def pfmt(p): if p >= 0.0995: return "%.2f" % p if p >= 0.00995: return "%.3f" % p return "%.4f" % p # ---------------------------------------------------------------- 1: the three tests under four counts def chart_pvalues(outdir): """Version 2, after the fresh review of 2026-11-11 (M1): the first group applies the note's own flags to both eras (R2 leniently, R1 strictly); the second adds the Florida records we found, holding October 2024 and the 2000-2003 records alike (counted together, or set aside together; the second of these is not a registered reading).""" xs = lambda p: 100.0 * (math.log10(p) + 4.0) / 4.0 # (group title, group note, rows): each row is (k, Fisher hits of 4, baseline events in cycles 10-24, # events in cycles 22-24, baseline hits of 19 storms, label) groups = [ ("The note’s baseline, with its own flags applied to both eras", "9 events in 15 cycles, 3 in Cycles 22–24, 3 hits in 19 storms, unless the row says otherwise", [ (5, 4, 9, 3, 3, "all five records, as the note counts"), (4, 4, 9, 3, 3, "March 2023 set aside"), (3, 3, 9, 3, 3, "by its flags, read leniently: the rows marked camera-only and camera-dominant set aside"), (2, 2, 8, 2, 2, "by its flags, read strictly: “mostly camera” and a 2003 row marked “photographed” set aside too")]), ("With the Florida records we found, held alike", "12 events in 15 cycles, 5 in Cycles 22–24, 5 hits in 19 storms, unless the row says otherwise", [ (5, 4, 12, 5, 5, "all five records"), (4, 4, 12, 5, 5, "March 2023 set aside"), (3, 3, 12, 5, 5, "October 2024 and the records of 2000–2003, all counted"), (2, 2, 8, 1, 1, "October 2024 and the records of 2000–2003, all set aside: 8 events, 1 in Cycles 22–24, 1 hit (not registered)")]), ] rows_txt = [] s = ['
'] s.append('') for gname, gnote, rows in groups: s.append('

%s (%s)

' % (gname, gnote)) for k, hits, n_b, n_mod, h0, lab in rows: a = F.poisson_sf(k, n_b / 15.0) b = F.poisson_sf(k, n_mod / 3.0) c = F.fisher_one_sided(hits, 4, h0, 19) rows_txt.append((gname, k, a, b, c)) title = "%s: rate against Cycles 10–24, p = %s; rate against Cycles 22–24, p = %s; storm for storm at Kp 9− or more, p = %s" % ( lab[0].upper() + lab[1:], pfmt(a), pfmt(b), pfmt(c)) s.append('

%d %s

' '
' '
' '

%s %s %s

' % (" is-key" if k == 5 and n_b == 9 else "", title, k, lab, xs(a), xs(b), xs(c), pfmt(a), pfmt(b), pfmt(c))) ticks = [(0.0001, "0.0001"), (0.001, "0.001"), (0.01, "0.01"), (0.05, "0.05"), (1.0, "1")] s.append('') s.append("
") write(outdir, "chart_pvalues.html", "".join(s)) return rows_txt # ---------------------------------------------------------------- 2: every storm at Dst <= -200 nT, by era def chart_strips(src, outdir): rows = [] with open(os.path.join(src, "our_storms_24h.csv"), encoding="utf-8", newline="") as f: for r in csv.DictReader(x for x in f if not x.startswith("#")): if r["stratum"] == "Dst<=-200": rows.append(r) eras = [("1986-2019Nov", "1986 to November 2019"), ("C25", "Cycle 25, to September 2026")] W, H = 760, 372 x0, x1, d0, d1 = 64.0, 736.0, -150.0, -600.0 xo = lambda d: x0 + (d - d0) * (x1 - x0) / (d1 - d0) base = {"1986-2019Nov": 150.0, "C25": 290.0} R, STEP, NEAR = 5.0, 11.5, 7.6 # mark radius, stacking step (px), and how close two values are before they stack (nT) n_era = {e: sum(1 for r in rows if r["era"] == e) for e, _ in eras} n_rec = {e: sum(1 for r in rows if r["era"] == e and RECORDS.get(r["start_UT"][:10], ("",))[0] in ("eye", "cam", "add")) for e, _ in eras} aria = ("Two rows of marks on a scale of storm size, from %s150 to %s600 nanotesla of Dst. From 1986 to November 2019 there were %d storms at " "%s200 nanotesla or below; Florida records exist for five of them, at %s589, %s422, %s383 and twice at %s292, the last two missing from the " "note’s list. In Cycle 25 there were %d such storms, with Florida records for four, at %s406, %s333, %s236 and %s217; the two with none " "are at %s213 and %s212. March 2023, at %s163, is drawn apart: its record is set aside." % ( MINUS, MINUS, n_era["1986-2019Nov"], MINUS, MINUS, MINUS, MINUS, MINUS, n_era["C25"], MINUS, MINUS, MINUS, MINUS, MINUS, MINUS, MINUS)) s = ['' % (W, H, aria)] for d in (-200, -300, -400, -500, -600): s.append('' % (f1(xo(d)), f1(xo(d)), H - 46)) s.append('%s' % (f1(xo(d)), H - 26, num(d))) s.append('' % (f1(xo(-200)), f1(xo(-200)), H - 46)) s.append('the lists start at %s200' % (f1(xo(-200) + 4), MINUS)) s.append('' % (f1(x0), H - 46, f1(x1), H - 46)) s.append('stronger storms →' % (f1(x1), H - 8)) s.append('Lowest hourly Dst of the storm, nT' % (f1(x0), H - 8)) out_rows = [] for era, name in eras: yb = base[era] mine = sorted((r for r in rows if r["era"] == era), key=lambda r: -float(r["dst_min_nT"])) s.append('%s: %d storms, %d with a Florida record' % (f1(x0), f1(yb - 78 if era == "C25" else yb - 96), name, n_era[era], n_rec[era])) s.append('' % (f1(x0), f1(yb + R + 3), f1(x1), f1(yb + R + 3))) placed = [] for r in mine: d = float(r["dst_min_nT"]) lvl = 0 while any(abs(d - pd) < NEAR and pl == lvl for pd, pl in placed): lvl += 1 placed.append((d, lvl)) day = r["start_UT"][:10] kind, what = RECORDS.get(day, ("none", "%s: no Florida record found" % day)) x, y = xo(d), yb - lvl * STEP title = "%s; lowest Dst %s nT, highest Kp %s" % (what, num(d), F.kpname(float(r["kp_max"])).replace("-", MINUS)) if kind == "eye": mark = '' % (f1(x), f1(y), f1(R)) elif kind == "cam": mark = '' % (f1(x - R + 0.4), f1(y - R + 0.4), f1(2 * R - 0.8), f1(2 * R - 0.8)) elif kind == "add": mark = '' % (f1(x), f1(y), f1(R - 1.1)) elif kind == "inf": mark = '' % (f1(x - 3.5), f1(y - 3.5), f1(x), f1(y)) else: mark = '' % (f1(x), f1(y)) s.append('%s%s' % (title, mark)) out_rows.append((era, day, d, kind, F.kpname(float(r["kp_max"])), what)) if day in LABELS: text, where, anchor, dx = LABELS[day] ly = yb + R + 19 if where == "below" else y - R - 6 s.append('%s' % (f1(x + dx), f1(ly), anchor, text)) # March 2023, below the lists' threshold: one of the note's five; its record is set aside (Unsupported on the site) x, y = xo(-163.0), base["C25"] s.append('March 23–24, 2023: lowest Dst %s163 nT, highest Kp 8o, below the lists’ threshold; one of the note’s five, on one photograph ' 'that looks away from where the storm’s aurora could stand: set aside' '' % (MINUS, f1(x - R + 0.4), f1(y - R + 0.4), f1(2 * R - 0.8), f1(2 * R - 0.8), f1(x - R - 2), f1(y - R - 2), f1(x + R + 2), f1(y + R + 2), f1(x - R - 2), f1(y + R + 2), f1(x + R + 2), f1(y - R - 2))) s.append('Mar 2023' % (f1(x + 2), f1(y + R + 19))) s.append("") write(outdir, "chart_strips.svg.html", "".join(s)) words = {"eye": "reported seen at the time; on the note's list", "cam": "camera only; on the note's list", "add": "a Florida record that the note's list lacks", "inf": "Florida by inference, or a Gulf-coast record only", "none": "no record found"} lines = ["# Our analysis: every storm at Dst -200 nT or below in our rebuilt list (1986 to September 2026), with our reading of its Florida record.", "# Dst: WDC for Geomagnetism, Kyoto, final to 2020 and provisional from 2021; scientific, non-commercial use, with acknowledgement of the WDC", "# and the observatories that supply its data (doi:10.17593/14515-74000). Kp: GFZ, CC BY 4.0. The dates are the UT days on which each storm's", "# first hour at or below -200 nT falls.", "era,first_day_at_or_below_-200nT,lowest_dst_nT,highest_kp,record_kind,record"] for era, day, d, kind, kpn, what in out_rows: lines.append('%s,%s,%d,%s,"%s","%s"' % ("1986 to November 2019" if era == "1986-2019Nov" else "cycle 25", day, d, kpn, words[kind], what.replace("’", "'").replace("–", "-"))) lines.append('cycle 25,2023-03-24,-163,8o,set aside,"March 23-24, 2023: below the lists\' threshold; one photograph that looks away from where the storm\'s aurora could stand"') write(src, "storms_dst200_records.csv", "\n".join(lines)) return out_rows # ---------------------------------------------------------------- 3: Orlando's magnetic latitude, 1859-2026 def chart_latitude(dl, src, outdir): 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") lat, lon = 28.54, -81.38 # Orlando glat = M.geocentric(lat) def at(t): if t < 1900.0: c, model = gufm.at(t), "gufm1" else: c = M.igrf_at(igrf, t) c = {k: v for k, v in c.items() if k[1] <= (10 if t < 2000.0 else 13)} model = "IGRF-14" d = M.dipole(c) return model, M.cd_latitude(glat, lon, d["plat"], d["plon"]), M.apex_latitude(c, glat, lon) years = [1859.67] + [float(y) for y in range(1860, 2026, 5)] + [2026.0] marks = [1859.67, 1941.71, 1958.11, 1989.20, 2003.83, 2026.0] series = [(t,) + at(t) for t in sorted(set(years + marks))] with open(os.path.join(src, "florida-latitude-series.csv"), "w", encoding="utf-8", newline="\n") as f: f.write("# Our calculation: Orlando, Florida (28.54 N, 81.38 W): centred-dipole and apex latitude, degrees, from gufm1 (before 1900) and IGRF-14 (from 1900).\n") f.write("year,model,centred_dipole_latitude,apex_latitude\n") for t, model, cd, ap in series: f.write("%.2f,%s,%.2f,%.2f\n" % (t, model, cd, ap)) val = {round(t, 2): (cd, ap) for t, _, cd, ap in series} W, H = 760, 366 x0, x1, t0, t1 = 46.0, 716.0, 1855.0, 2030.0 yt, yb, vt, vb = 18.0, 320.0, 42.0, 37.0 xo = lambda t: x0 + (t - t0) * (x1 - x0) / (t1 - t0) yo = lambda v: yt + (vt - v) * (yb - yt) / (vt - vb) a, b, c = val[1859.67], val[1958.11], val[2026.0] pk = max(series, key=lambda r: r[3]) hi = max(cd for t, _, cd, _ in series if t <= 1960.0) aria = ("Line chart, 1859 to 2026, of Orlando’s magnetic latitude. Centred-dipole latitude holds between %.1f and %.1f degrees from 1859 to about " "1960, then falls to %.1f in 2026. Apex latitude, which includes the whole field, rises from %.1f in 1859 to %.1f in %d, then falls to %.1f in 2026." % (a[0], hi, c[0], a[1], pk[3], round(pk[0]), c[1])) s = ['' % (W, H, aria)] for v in (37, 38, 39, 40, 41, 42): s.append('%d°' % (f1(x0), f1(yo(v)), f1(x1), f1(yo(v)), f1(x0 - 8), f1(yo(v) + 4), v)) for t, lab in ((1859.67, "Sep 1859"), (1958.11, "Feb 1958")): s.append('%s' % (f1(xo(t)), f1(yt - 6), f1(xo(t)), f1(yb), f1(xo(t) + 5), f1(yt + 4), lab)) s.append('' % (f1(x0), f1(yb), f1(x1), f1(yb))) for t in (1875, 1900, 1925, 1950, 1975, 2000, 2025): s.append('%d' % (f1(xo(t)), f1(yb), f1(xo(t)), f1(yb + 6), f1(xo(t)), f1(yb + 22), t)) line = [r for r in series if r[0] in years] s.append('' % " ".join("%s,%s" % (f1(xo(t)), f1(yo(cd))) for t, _, cd, _ in line)) s.append('' % " ".join("%s,%s" % (f1(xo(t)), f1(yo(ap))) for t, _, _, ap in line)) for t, model, cd, ap in series: s.append('%s: centred dipole %.2f°, apex %.2f° (%s)' % (("%.2f" % t).rstrip("0").rstrip("."), cd, ap, model, f1(xo(t)), f1(yo(cd)), f1(xo(t)), f1(yo(ap)))) for t in (1859.67, 1958.11, 2026.0): cd, ap = val[t] s.append('' % (f1(xo(t)), f1(yo(cd)), f1(xo(t)), f1(yo(ap)))) s.append('%.1f°' % (f1(xo(1859.67) + 7), f1(yo(a[0]) - 8), a[0])) s.append('%.1f°' % (f1(xo(1859.67) + 7), f1(yo(a[1]) + 17), a[1])) s.append('%.1f°' % (f1(xo(1958.11) + 7), f1(yo(b[0]) + 17), b[0])) s.append('%.1f°' % (f1(xo(1958.11) + 7), f1(yo(b[1]) - 8), b[1])) s.append('%.1f°' % (f1(xo(2026.0) - 6), f1(yo(c[0]) + 16), c[0])) s.append('%.1f°' % (f1(xo(2026.0) + 2), f1(yo(c[1]) - 10), c[1])) s.append("") write(outdir, "chart_latitude.svg.html", "".join(s)) return series # ---------------------------------------------------------------- the table of section 8: changes to 2026 PLACES = [("Key West", 24.56, -81.78), ("Miami", 25.76, -80.19), ("Orlando", 28.54, -81.38), ("Mims", 28.67, -80.84), ("Chiefland", 29.47, -82.86), ("Jacksonville", 30.33, -81.66), ("Pensacola", 30.42, -87.22)] def latitude_changes(dl, src): """Change in centred-dipole and apex latitude from five dates to 2026.0, at seven Florida places (as geometry.py computes them).""" 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") def both(lat, lon, t): if t < 1900.0: c = gufm.at(t) else: c = M.igrf_at(igrf, t) c = {k: v for k, v in c.items() if k[1] <= (10 if t < 2000.0 else 13)} d = M.dipole(c) g = M.geocentric(lat) return M.cd_latitude(g, lon, d["plat"], d["plon"]), M.apex_latitude(c, g, lon) now = {name: both(la, lo, 2026.0) for name, la, lo in PLACES} lines = ["Change in Florida's magnetic latitude from each date to 2026.0, degrees (negative = lower, farther from the pole).", "Seven places: " + ", ".join(n for n, _, _ in PLACES) + ". gufm1 before 1900, IGRF-14 from 1900.", ""] for t, name in ((1859.67, "September 1859"), (1941.71, "September 1941"), (1958.11, "February 1958"), (1989.20, "March 1989"), (2003.83, "November 2003")): dcd, dap = [], [] for pname, la, lo in PLACES: cd, ap = both(la, lo, t) dcd.append(now[pname][0] - cd) dap.append(now[pname][1] - ap) lines.append("%-15s (%.2f): centred dipole %+.2f to %+.2f; apex %+.2f to %+.2f" % (name, t, min(dcd), max(dcd), min(dap), max(dap))) write(src, "latitude_changes.txt", "\n".join(lines)) return lines def main(): dl, src = sys.argv[1], sys.argv[2] outdir = os.path.join(src, "charts") os.makedirs(outdir, exist_ok=True) sys.stdout.reconfigure(encoding="utf-8", newline="\n") print("chart 1: the three tests (p-values)") for g, k, a, b, c in chart_pvalues(outdir): print(" %-58s k = %d: %s %s %s" % (g, k, pfmt(a), pfmt(b), pfmt(c))) print("chart 2: storms at Dst <= -200 nT") rows = chart_strips(src, outdir) for era in ("1986-2019Nov", "C25"): mine = [r for r in rows if r[0] == era] print(" %s: %d storms; %s" % (era, len(mine), ", ".join("%s %d" % (k, sum(1 for r in mine if r[3] == k)) for k in ("eye", "cam", "add", "inf", "none")))) print("chart 3: Orlando's magnetic latitude") for t, model, cd, ap in chart_latitude(dl, src, outdir): print(" %7.2f %-8s cd %.2f apex %.2f" % (t, model, cd, ap)) print("section 8's table:") for line in latitude_changes(dl, src): print(" " + line) print("wrote 3 charts to", outdir) if __name__ == "__main__": main()