#!/usr/bin/env python3 """Analysis (b), part 2, for march-2023-storm: what did the dipole do through 2023? Fact-Checked Science, "Our analysis". Standard library only. Follows RULES_dipole.txt (pre-registered). Run: python3 -I -X utf8 dipole_pace.py RULES_dipole.txt CHAOS_SPLINE_FILE IGRF_FILE OUT_FOLDER CHAOS_SPLINE_FILE CHAOS-8.7_spline-coefficients.dat (Kloss et al., DTU Space, CC BY 4.0) IGRF_FILE igrf14coeffs.txt (IAGA V-MOD) Needs chaos_reader.py beside it: the site's checked B-spline and IGRF readers, copied unchanged from https://factchecked.science/field-loss-projections/field_loss.py. (The first run, on 11 November 2026 at 16:22 UTC, imported them from that file directly; the numbers are the same to the last digit.) Writes OUT_FOLDER/dipole_pace.json and dipole_pace.log (with SHA-256 of the rules and inputs), and OUT_FOLDER/dipole-yearly-pace.csv, the yearly figures behind the page's chart. """ import datetime as dt import hashlib import json import math import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import chaos_reader as FL # our own module, same folder UTC = dt.timezone.utc A_KM = 6371.2 T0 = 2023.0 + 81.5 / 365.0 # 23 March 2023, 12 UT def sha(path): with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() def percentile(sorted_vals, q): k = (len(sorted_vals) - 1) * q / 100.0 f, c = math.floor(k), math.ceil(k) if f == c: return sorted_vals[int(k)] return sorted_vals[f] + (sorted_vals[c] - sorted_vals[f]) * (k - f) def main(): rules, chaos_path, igrf_path, outdir = sys.argv[1:5] log = [] def say(*a): s = " ".join(str(x) for x in a) print(s) log.append(s) say("dipole_pace.py run at", dt.datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ")) say("rules ", sha(rules), os.path.basename(rules)) say("CHAOS ", sha(chaos_path), os.path.basename(chaos_path)) say("IGRF ", sha(igrf_path), os.path.basename(igrf_path)) say("reader ", sha(os.path.join(os.path.dirname(os.path.abspath(__file__)), "chaos_reader.py")), "chaos_reader.py") ch = FL.Chaos(chaos_path, "CHAOS-8.7") igrf = FL.read_igrf(igrf_path) say(f"CHAOS span: {ch.t_first:.4f} to {ch.t_last:.4f}; knots {ch.nspl + ch.p + 1}, order {ch.p + 1}") interior = sorted(set(round(k, 4) for k in ch.knots if ch.t_first < k < ch.t_last)) steps = sorted(set(round(b - a, 3) for a, b in zip(interior, interior[1:]))) say("interior knot spacing (years):", steps[:6], "...", "n interior knots", len(interior)) def d1(t, deriv=0): """g10, g11, h11 (or their time derivatives) from CHAOS.""" g, h = ch.gh(t, deriv, 1) return g[1][0], g[1][1], h[1][1] def m_of(t): a, b, c = d1(t) return math.sqrt(a * a + b * b + c * c) def g10(t): return d1(t)[0] def pole(t): """Geomagnetic (dipole-axis) north pole: latitude, longitude in degrees (geocentric).""" a, b, c = d1(t) m = math.sqrt(a * a + b * b + c * c) # the axis points along -(g11, h11, g10) for the north geomagnetic pole x, y, z = -b / m, -c / m, -a / m return math.degrees(math.asin(z)), math.degrees(math.atan2(y, x)) def arc_km(p, q): la1, lo1, la2, lo2 = map(math.radians, (p[0], p[1], q[0], q[1])) s = math.sin(la1) * math.sin(la2) + math.cos(la1) * math.cos(la2) * math.cos(lo2 - lo1) return A_KM * math.acos(max(-1.0, min(1.0, s))) out = {"what": "The dipole through 2023 in CHAOS-8.7 (factchecked.science, Our analysis; RULES_dipole.txt)", "model_span": [round(ch.t_first, 4), round(ch.t_last, 4)], "t0": round(T0, 4), "t0_is": "23 March 2023, 12 UT (2023 + 81.5/365); a window 't0 to t0+1' runs from 23 March 2023 to 23 March 2024"} # values at t0 a, b, c = d1(T0) out["at_t0"] = {"g10": round(a, 2), "g11": round(b, 2), "h11": round(c, 2), "m": round(m_of(T0), 2), "pole_lat": round(pole(T0)[0], 3), "pole_lon": round(pole(T0)[1], 3)} say("\nAT t0 =", round(T0, 4), json.dumps(out["at_t0"])) # P1 yearly changes last_full = int(math.floor(ch.t_last)) p1 = [] for y in range(2015, last_full): p1.append({"from": y, "to": y + 1, "d_abs_g10": round(abs(g10(y + 1.0)) - abs(g10(float(y))), 2), "d_m": round(m_of(y + 1.0) - m_of(float(y)), 2)}) out["P1_calendar_years"] = p1 say("\nP1 change per calendar year, 1 January to 1 January (|g10|, m), nT:") for r in p1: say(f" {r['from']}-{r['to']}: {r['d_abs_g10']:7.2f} {r['d_m']:7.2f}") p1b = [] for k in (-2, -1, 0, 1, 2): lo, hi = T0 + k, T0 + k + 1 if hi <= ch.t_last: p1b.append({"from": round(lo, 3), "to": round(hi, 3), "from_date": f"23 March {2023 + k}", "to_date": f"23 March {2024 + k}", "d_abs_g10": round(abs(g10(hi)) - abs(g10(lo)), 2), "d_m": round(m_of(hi) - m_of(lo), 2)}) out["P1_years_centred_on_storm"] = p1b say("P1 years counted from the storm (23 March to 23 March):") for r in p1b: say(f" {r['from_date']} to {r['to_date']}: {r['d_abs_g10']:7.2f} {r['d_m']:7.2f}") # P2, P3 change of pace and placebo def pace_change(f, t, L): return (f(t + L) - f(t)) / L - (f(t) - f(t - L)) / L def absg(t): return abs(g10(t)) out["P2_P3"] = {} say("\nP2/P3 change of pace a(t) = [f(t+L)-f(t)]/L - [f(t)-f(t-L)]/L, nT a year (negative: weakening faster after)") for L in (2.0, 1.0, 3.0): if T0 + L > ch.t_last: say(f" L = {L}: t0 + L is beyond the model's span ({ch.t_last:.3f}); skipped") out["P2_P3"][f"L{L:g}"] = {"skipped": "t0 + L beyond the model's span"} continue res = {} for name, f in (("m", m_of), ("abs_g10", absg)): a0 = pace_change(f, T0, L) before = (f(T0) - f(T0 - L)) / L after = (f(T0 + L) - f(T0)) / L plac, t = [], 2001.0 while t + L <= ch.t_last + 1e-9: if t - L >= ch.t_first: plac.append((round(t, 2), pace_change(f, t, L))) t += 0.25 vals = sorted(v for tt, v in plac) p025, p975 = percentile(vals, 2.5), percentile(vals, 97.5) below = sum(1 for v in vals if v < a0) most_neg = min(plac, key=lambda x: x[1]) most_pos = max(plac, key=lambda x: x[1]) res[name] = {"pace_before": round(before, 3), "pace_after": round(after, 3), "a_t0": round(a0, 3), "n_placebo": len(vals), "placebo_from": plac[0][0], "placebo_to": plac[-1][0], "p2.5": round(p025, 3), "median": round(percentile(vals, 50), 3), "p97.5": round(p975, 3), "min": [most_neg[0], round(most_neg[1], 3)], "max": [most_pos[0], round(most_pos[1], 3)], "t0_percentile": round(100.0 * below / len(vals), 1), "inside_central_95": p025 <= a0 <= p975, "result": "inside the central 95%: no unusual change of pace" if p025 <= a0 <= p975 else ("BELOW the 2.5th percentile: weakening faster after than before, by more than usual" if a0 < p025 else "above the 97.5th percentile: weakening slower after than before, by more than usual")} say(f" L = {L:g} y, {name}: before {before:.3f}, after {after:.3f}, a(t0) = {a0:.3f}; placebo n={len(vals)} " f"({plac[0][0]}-{plac[-1][0]}), 2.5% {p025:.3f}, median {percentile(vals, 50):.3f}, 97.5% {p975:.3f}, " f"min {most_neg[1]:.3f} at {most_neg[0]}, max {most_pos[1]:.3f} at {most_pos[0]}; t0 at {100.0 * below / len(vals):.1f}th pct -> " f"{res[name]['result']}") out["P2_P3"][f"L{L:g}"] = res # P4 instantaneous rates p4 = [] for t in (2018.0, 2019.0, 2020.0, 2021.0, 2022.0, 2022.5, 2023.0, T0, 2023.5, 2024.0, 2024.5, 2025.0, 2025.5, 2026.0, 2026.5): if t > ch.t_last: continue a, b, c = d1(t) da, db, dc = d1(t, 1) m = math.sqrt(a * a + b * b + c * c) dm = (a * da + b * db + c * dc) / m p4.append({"t": round(t, 4), "dg10_dt": round(da, 3), "d_abs_g10_dt": round(-da if a < 0 else da, 3), "dm_dt": round(dm, 3)}) out["P4_rates"] = p4 # IGRF-14 forecast epochs, main_c, sv = igrf g10sv = sv[("g", 1, 0)] g, h = FL.igrf_at(igrf, 2025.0) gg, hh = FL.igrf_at(igrf, 2030.0) m25 = math.sqrt(g[1][0] ** 2 + g[1][1] ** 2 + h[1][1] ** 2) m30 = math.sqrt(gg[1][0] ** 2 + gg[1][1] ** 2 + hh[1][1] ** 2) out["IGRF14_forecast_2025_2030"] = {"dg10_dt": g10sv, "d_abs_g10_dt": round(-g10sv, 3), "dm_dt": round((m30 - m25) / 5.0, 3)} say("\nP4 instantaneous rates (nT a year): t, d|g10|/dt, dm/dt") for r in p4: say(f" {r['t']:9.4f} {r['d_abs_g10_dt']:8.3f} {r['dm_dt']:8.3f}") say(" IGRF-14 forecast 2025-2030:", json.dumps(out["IGRF14_forecast_2025_2030"])) # P5 dipole-axis pole p5 = [] for t in (2019.0, 2020.0, 2021.0, 2022.0, 2023.0, T0, 2024.0, 2025.0, 2026.0): if t <= ch.t_last: la, lo = pole(t) p5.append({"t": round(t, 4), "lat": round(la, 4), "lon": round(lo, 4)}) out["P5_pole"] = p5 say("\nP5 geomagnetic (dipole-axis) north pole:") for r in p5: say(f" {r['t']:9.4f} {r['lat']:.4f} N {r['lon']:.4f} E") def speed(t, L): return arc_km(pole(t), pole(t + L)) / L res = {} for L in (2.0, 1.0, 3.0): if T0 + L > ch.t_last: continue before, after = speed(T0 - L, L), speed(T0, L) a0 = after - before plac, t = [], 2001.0 while t + L <= ch.t_last + 1e-9: if t - L >= ch.t_first: plac.append((round(t, 2), speed(t, L) - speed(t - L, L))) t += 0.25 vals = sorted(v for tt, v in plac) p025, p975 = percentile(vals, 2.5), percentile(vals, 97.5) below = sum(1 for v in vals if v < a0) res[f"L{L:g}"] = {"km_per_year_before": round(before, 3), "km_per_year_after": round(after, 3), "change": round(a0, 3), "n_placebo": len(vals), "p2.5": round(p025, 3), "median": round(percentile(vals, 50), 3), "p97.5": round(p975, 3), "t0_percentile": round(100.0 * below / len(vals), 1), "inside_central_95": p025 <= a0 <= p975} say(f" pole speed, L = {L:g} y: before {before:.3f} km/y, after {after:.3f}; change {a0:.3f}; placebo 2.5% {p025:.3f}, " f"median {percentile(vals, 50):.3f}, 97.5% {p975:.3f}; t0 at {100.0 * below / len(vals):.1f}th pct; " f"inside central 95%: {p025 <= a0 <= p975}") out["P5_pole_speed"] = res # Context for the page's chart (no test): every calendar year of the model, and IGRF-14's five-year paces. first_year = int(math.ceil(ch.t_first)) ctx = [{"from": y, "to": y + 1, "d_abs_g10": round(abs(g10(y + 1.0)) - abs(g10(float(y))), 2)} for y in range(first_year, last_full)] v = main_c[("g", 1, 0)] five = [{"from": int(epochs[i]), "to": int(epochs[i + 1]), "d_abs_g10_per_year": round((abs(v[i + 1]) - abs(v[i])) / (epochs[i + 1] - epochs[i]), 2)} for i in range(len(epochs) - 1) if epochs[i] >= 1960] def mean_years(a, b): xs = [r["d_abs_g10"] for r in ctx if a <= r["from"] < b] return round(sum(xs) / len(xs), 2) out["context_no_test"] = { "calendar_years_d_abs_g10": ctx, "IGRF14_five_year_paces": five, "mean_2000_2009": mean_years(2000, 2010), "mean_2007_2014": mean_years(2007, 2015), "mean_2023_2025": mean_years(2023, 2026), "fastest_year": min(ctx, key=lambda r: r["d_abs_g10"]), "slowest_year": max(ctx, key=lambda r: r["d_abs_g10"]), "share_of_g10_lost_23Mar2023_to_23Mar2024_percent": round(100.0 * (abs(g10(T0)) - abs(g10(T0 + 1))) / abs(g10(T0)), 4)} say("\nCONTEXT (no test): change of |g10| per calendar year, 1 January to 1 January, nT") say(" " + "; ".join(f"{r['from']}: {r['d_abs_g10']:.1f}" for r in ctx)) say(" means: 2000-2009", out["context_no_test"]["mean_2000_2009"], "; 2007-2014", out["context_no_test"]["mean_2007_2014"], "; 2023-2025", out["context_no_test"]["mean_2023_2025"]) say(" IGRF-14 five-year paces (nT a year): " + "; ".join(f"{r['from']}-{r['to']}: {r['d_abs_g10_per_year']:.1f}" for r in five)) # Added after the fresh review (RULES_dipole.txt, addendum): the two-year change of pace for the quarters whose windows end # before the storm's window begins, and where in the whole series the change is most negative. A description, not a test. L = 2.0 ser, t = [], 2001.0 while t + L <= ch.t_last + 1e-9: if t - L >= ch.t_first: ser.append((round(t, 2), pace_change(absg, t, L))) t += 0.25 early = [(tt, v) for tt, v in ser if tt + L <= T0 - L + 1e-9] a0 = pace_change(absg, T0, L) ev = sorted(v for tt, v in early) most = min(ser, key=lambda x: x[1]) out["context_no_test"]["pace_change_outside_the_episode"] = { "what": "a(t) for |g10| with L = 2 years, at quarters whose four-year windows end before the storm's window begins", "quarters": [early[0][0], early[-1][0]], "n": len(early), "most_negative": [min(early, key=lambda x: x[1])[0], round(ev[0], 2)], "p2.5": round(percentile(ev, 2.5), 2), "a_t0": round(a0, 2), "quarters_more_negative_than_t0": sum(1 for v in ev if v < a0), "most_negative_in_whole_series": [most[0], round(most[1], 2)], "quarters_of_2022": {f"{tt:g}": round(v, 2) for tt, v in ser if 2022.0 <= tt < 2023.0}} # Added after the second check (RULES_dipole.txt, note): the rate of |g10| sampled daily, mid-2023 to the end of the data t_data_end = 2026 + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) / 365.0 daily = [] t = 2023.5 while t <= t_data_end + 1e-9: g, h = ch.gh(t, 1, 1) daily.append((t, -g[1][0] if g10(t) > 0 else g[1][0])) t += 1.0 / 365.25 lo = min(daily, key=lambda x: x[1]) hi = max(daily, key=lambda x: x[1]) out["context_no_test"]["weakening_rate_daily_since_mid_2023"] = { "what": "the rate at which |g10| fell, nT a year, sampled daily from 2023.5 to the end of the model's data (31 August 2026)", "least": [round(lo[0], 3), round(lo[1], 2)], "greatest": [round(hi[0], 3), round(hi[1], 2)]} say(f" weakening rate sampled daily since mid-2023: least {lo[1]:.2f} nT a year at {lo[0]:.3f}, greatest {hi[1]:.2f} at {hi[0]:.3f}") c = out["context_no_test"]["pace_change_outside_the_episode"] say(f" change of pace outside the episode: {c['n']} quarters, {c['quarters'][0]} to {c['quarters'][1]}; most negative {c['most_negative'][1]} at {c['most_negative'][0]}; " f"2.5th percentile {c['p2.5']}; the storm's {c['a_t0']}; in the whole series most negative {c['most_negative_in_whole_series'][1]} at " f"{c['most_negative_in_whole_series'][0]}; quarters of 2022: {c['quarters_of_2022']}") rows = ["# The axial dipole's change per calendar year (1 January to 1 January) in CHAOS-8.7, nT; negative = weaker.", "# Fact-Checked Science, our analysis of CHAOS-8.7 (Kloss et al., DTU Space, CC BY 4.0, doi:10.5281/zenodo.22959079).", "# The model's data end in August 2026: the last row is partly extrapolated.", "year_from,year_to,change_of_abs_g10_nT"] rows += [f"{r['from']},{r['to']},{r['d_abs_g10']:.2f}" for r in ctx] with open(os.path.join(outdir, "dipole-yearly-pace.csv"), "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(rows) + "\n") with open(os.path.join(outdir, "dipole_pace.json"), "w", encoding="utf-8", newline="\n") as f: json.dump(out, f, indent=1, ensure_ascii=False) f.write("\n") with open(os.path.join(outdir, "dipole_pace.log"), "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(log) + "\n") if __name__ == "__main__": main()