#!/usr/bin/env python3 """Was Earth's dipole steady before 1840? Open field models set against Gubbins, Jones & Finlay (2006). Fact-Checked Science, November 2026, for the paper check "dipole-before-1840" ("Our analysis"). Standard library only. It reproduces, without numpy, the pre-registered analyses we first ran with numpy (model_rates.py and reverse_flux.py, hosted beside it, with their rules files). Run it python3 -I -B dipole_before_1840.py [folder] The folder (default: the script's own) holds, or will receive, the inputs below. A missing file is downloaded under the plain client name "factchecked-research/1.0"; every file is then checked against the SHA-256 of the copy we used on November 9, 2026 (a different hash means the maker changed the file, so numbers may differ). It prints a summary and writes dipole-numbers.json into the folder. It takes about half a minute. Inputs (about 7 MB) gufm1.txt gufm1 (Jackson, Jonkers & Walker 2000), 1590-1990, from geomag.colorado.edu pymagglobal_ model files bundled with GFZ's pymagglobal package, each CC BY 4.0, from GFZ's public GitLab (project 1055, folder pymagglobal/dat): gufm1, CALS10k.2, ARCH10k.1, HFM.OL1.A1, pfm9k.1a and arhimag1k CALS10k2.zip GFZ's own copy of CALS10k.2 (with Fortran code, which is not run), a check DM_CALS10k_2.zip GFZ's dipole-moment series for CALS10k.2, a check COV-OBS.x2-int COV-OBS.x2 (Huder et al. 2020), 1840-2020, B-splines, from DTU Space COV-OBS.x2-int.shc the same model tabulated, a check igrf14coeffs.txt IGRF-14, for the axial dipole in 2025 coeff_SHA.DIF.14k.dat optional: SHA.DIF.14k (Pavon-Carrasco et al. 2014). It is distributed only inside a RAR archive (https://earthref.org/ERDA/download:1897/), which the standard library can't open; extract this one file with any archive tool and put it in the folder to include the model. What it computes A. Checks: the two gufm1 copies and the two CALS10k.2 copies agree; our CALS10k.2 dipole moment matches GFZ's series; COV-OBS.x2's splines match its table; g10 in 1990 against DGRF 1990 (-29775 nT). B. The axial dipole |g10| and the dipole moment M = (4 pi a^3/mu0) sqrt(g10^2 + g11^2 + h11^2) every year, and their weakening rates (least-squares slopes, and endpoint rates) over 1590-1840 and 1840-1990 in gufm1, COV-OBS.x2, CALS10k.2, ARCH10k.1, HFM.OL1.A1, pfm9k.1a (to 1900), arhimag1k and, if supplied, SHA.DIF.14k (at its own 50-year epochs); decade-by-decade rates; gufm1's pre-1840 slope; the 1840-1860 pause. The dipole-moment rates are per cent of each model's own 1840 value per century (SHA.DIF.14k: its 1800 value), as the rules say; our first numpy run divided the pre-1840 rate by the 1590 value instead. C. What the 1590 field and the loss since then depend on: gufm1's prescribed fall against Gubbins et al.'s 2.28 nT/yr from 1840, set against IGRF-14's g10 in 2025. D. Where the fall came from: g10 = (3/(8 pi)) (c/a)^3 * integral of Br cos(theta) dOmega at the core surface, split into normal and reversed flux in each geographic hemisphere (1-degree grid, degree 14 and 8), for gufm1 (1590-1990) and COV-OBS.x2 (1840-2020) every 10 years; also the paper's pre-1840 split with gufm1 rescaled to 2.28 nT/yr (exploratory, not pre-registered). E. Directions in gufm1: declination at London and Cape Town, the geomagnetic (dipole) pole and the north dip pole every 10 years, and the dip pole's path length and mean speed over 1590-1840 and 1840-1990. F. The chart's series: |g10| every 5 years in each model, with Gubbins et al.'s line. G. Added after a fresh review, not pre-registered: the pre-1840 slope pinned at each model's 1840 value, as the paper fits it; COV-OBS.x2's end-to-end dipole-moment rate over 1840-2020; the reversed-flux shares over 1880-2010 (COV-OBS.x2) and 1880-1990 (gufm1), for southern and for all reversed flux; a "footprint" share, the change in the southern cells that are reversed at the end of each window; and the power of degrees 9-14 at the core surface in COV-OBS.x2, which shows poorly constrained small scales near its 1840 start. Conventions: Schmidt semi-normalised coefficients in nT at a = 6371.2 km; cubic (order-4) B-splines on each file's knots; the core radius c = 3485.0 km; X north, Y east, Z down; a spherical Earth of radius a for directions; great-circle distances on R = 6371.0 km. Rates are positive when |g10| or M weakens. """ import hashlib import io import json import math import os import sys import urllib.request import zipfile UA = "factchecked-research/1.0" GL = "https://git.gfz-potsdam.de/api/v4/projects/1055/repository/blobs/%s/raw" COV = "https://www.spacecenter.dk/files/magnetic-models/COV-OBSx2/" GFZ = "https://www.gfz.de/fileadmin/gfz/sec23/data/Models/CALSxK/" INPUTS = { # name: (url or None, SHA-256 of our copy, optional) "gufm1.txt": ("https://geomag.colorado.edu/images/GUFM/gufm1.txt", "135716e3962947dcb41e107f36d8bb3d4633902602107ee8c4ef583fcd6670b1", False), "pymagglobal_gufm1": (GL % "ff898addfea89c06f99096b3e343382ba45286ad", "81b7d25a754011de1fe2453999ed20242fb88ac6c2f8c8750b63537df80ac9fe", False), "pymagglobal_CALS10k.2": (GL % "78980f5183e6ac280d26a03da78a1b2094b8e506", "2696265282f68a7cbc05436b11fa79523c629d3611edc4cad157e95c02475608", False), "pymagglobal_ARCH10k.1": (GL % "7a02dab902c6cacc2c6c94f7ea5cd57456ccbaa6", "c4ad7ffae15fbea56eb532ac052b5f661824f480a1d6b85535ab1c03765aa6c3", False), "pymagglobal_HFM.OL1.A1": (GL % "982ed179c9b1ffe2889c779c7e179eb40ebb2755", "147735be4a96d995a00e83ace4f81ca7dc68edab72a6fbaebe7cbd6e8778aa7b", False), "pymagglobal_pfm9k.1a": (GL % "a2a10a0f9bb6de002e079eeb3870dab3faec587b", "c6181bba5e711ad904ed4792482fb26b62400b0defaf91d329350550a800f242", False), "pymagglobal_arhimag1k": (GL % "461d36568d7bdbefe13c31bc6510cde7336eef03", "f975b7ee4d1da92d4c2798e298eec052feb5a7e9e9d0b550a921cbb0ea68eee3", False), "CALS10k2.zip": (GFZ + "CALS10k2.zip", "7621ab617a5efaf4c7aba5ec2a9541915d5a7aed09c3d6a662f0f6fcd56acb68", False), "DM_CALS10k_2.zip": (GFZ + "DM_CALS10k_2.zip", "68b4adc1d59ed09ff16ce75d364d2b49dca7ba7220d949467d28456217586474", False), "COV-OBS.x2-int": (COV + "COV-OBS.x2-int", "6c588becf4e3896b07be80c3f24697d299432120a7f4ab1139a914395f9d2a17", False), "COV-OBS.x2-int.shc": (COV + "COV-OBS.x2-int.shc", "4846045efc0d84735140bb44c8ace8ef1dff84d9c8bd388474e562d307782394", False), "igrf14coeffs.txt": ("https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt", "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c", False), "coeff_SHA.DIF.14k.dat": (None, "7f52e37015b2144f56cc56762f8f8c03642adb269a0286dcc70852c7c2bf5e9c", True), } A_KM, C_KM, R_KM = 6371.2, 3485.0, 6371.0 NT_TO_M22 = 1e7 * (A_KM * 1e3) ** 3 * 1e-9 / 1e22 # |g| in nT -> dipole moment in 1e22 A m^2 GUBBINS_RATE, GUBBINS_SD = 2.28, 2.72 # nT/yr, Gubbins, Jones & Finlay (2006), p. 901 DGRF1990_G10 = -29775.0 # ------------------------------------------------------------------ inputs def get(folder, name): url, sha, optional = INPUTS[name] path = os.path.join(folder, name) if not os.path.exists(path): if url is None: print(" (%s not supplied: skipped)" % name) return None print("downloading", url) req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=180) as r: data = r.read() with open(path, "wb") as f: f.write(data) with open(path, "rb") as f: data = f.read() digest = hashlib.sha256(data).hexdigest() if digest != sha: print("Note: %s differs from the copy we used (SHA-256 %s...); results may differ." % (name, sha[:16])) return data def numbers(text): out = [] for tok in text.replace("D", "E").replace("d", "e").split(): try: out.append(float(tok)) except ValueError: pass return out class SplineModel: """Gauss coefficients as cubic B-splines: coefs[j] holds g10, g11, h11, g20, ... for spline j.""" def __init__(self, name, lmax, nspl, knots, coefs, order=4): n = lmax * (lmax + 2) if len(knots) != nspl + order or len(coefs) != nspl * n: raise ValueError("%s: unexpected file layout" % name) self.name, self.lmax, self.nspl, self.k = name, lmax, nspl, order self.U = list(knots) self.C = [coefs[j * n:(j + 1) * n] for j in range(nspl)] def basis(self, t): U, k, nspl = self.U, self.k, self.nspl if not (U[k - 1] - 1e-9 <= t <= U[nspl] + 1e-9): raise ValueError("%s: %s outside the model" % (self.name, t)) B = [0.0] * (len(U) - 1) if t >= U[nspl]: B[nspl - 1] = 1.0 else: lo, hi = 0, len(U) - 1 # last i with U[i] <= t while hi - lo > 1: mid = (lo + hi) // 2 if U[mid] <= t: lo = mid else: hi = mid B[lo] = 1.0 for kk in range(2, k + 1): Bn = [0.0] * (len(U) - kk) for i in range(len(U) - kk): v = 0.0 d1, d2 = U[i + kk - 1] - U[i], U[i + kk] - U[i + 1] if d1 > 0 and B[i]: v += (t - U[i]) / d1 * B[i] if d2 > 0 and B[i + 1]: v += (U[i + kk] - t) / d2 * B[i + 1] Bn[i] = v B = Bn return B[:nspl] def coeffs(self, t, ncoef=None): b = self.basis(float(t)) n = len(self.C[0]) if ncoef is None else ncoef out = [0.0] * n for j, w in enumerate(b): if w: row = self.C[j] for q in range(n): out[q] += w * row[q] return out def deg1(self, t): return tuple(self.coeffs(t, 3)) def read_korte(text, name): """gufm1/CALSxk layout (pymagglobal's README): line 1 start and end years; then lmax, an unused number, nspl, the nspl+4 knots and the coefficients. arhimag1k adds a second block (standard deviations), not used.""" lines = text.split("\n") v = numbers("\n".join(lines[1:])) lmax, nspl = int(v[0]), int(v[2]) knots = v[3:3 + nspl + 4] coefs = v[3 + nspl + 4:] n = lmax * (lmax + 2) if len(coefs) == 2 * nspl * n: coefs = coefs[:nspl * n] return SplineModel(name, lmax, nspl, knots, coefs) def read_gufm1_colorado(text): lines = text.split("\n") v = numbers("\n".join(lines[1:])) lmax, nspl = int(v[0]), int(v[1]) return SplineModel("gufm1", lmax, nspl, v[2:2 + nspl + 4], v[2 + nspl + 4:]) def read_covobs(text): lines = text.split("\n") head = lines[1].split() lmax, nspl, order = int(head[0]), int(head[1]), int(head[2]) return SplineModel("COV-OBS.x2", lmax, nspl, [float(x) for x in head[3:]], numbers("\n".join(lines[2:])), order) def read_covobs_shc(text): rows = [ln for ln in text.split("\n") if ln.strip() and not ln.startswith("#")] ntimes = int(rows[0].split()[2]) times = [float(x) for x in rows[1].split()] assert len(times) == ntimes tab = {} for ln in rows[2:]: p = ln.split() if int(p[0]) == 1: tab[(1, int(p[1]))] = [float(x) for x in p[2:]] return times, tab def read_shadif(text): out = {} for ln in text.split("\n"): p = ln.split() if len(p) >= 5 and int(float(p[1])) == 1: t, m, g, h = float(p[0]), int(float(p[2])), float(p[3]) * 1000.0, float(p[4]) * 1000.0 out.setdefault(t, {})[m] = (g, h) return {t: (d[0][0], d[1][0], d[1][1]) for t, d in out.items()} def read_igrf_g10(text, epoch="2025.0"): cols = None for ln in text.split("\n"): p = ln.split() if p[:3] == ["g/h", "n", "m"]: cols = p elif cols and p[:3] == ["g", "1", "0"]: return float(p[cols.index(epoch)]) raise ValueError("IGRF g10 not found") # ------------------------------------------------------------------ helpers def dipole(g10, g11, h11): return abs(g10), math.sqrt(g10 * g10 + g11 * g11 + h11 * h11) * NT_TO_M22 def ols_slope(t, y): tm, ym = sum(t) / len(t), sum(y) / len(y) return sum((a - tm) * (b - ym) for a, b in zip(t, y)) / sum((a - tm) ** 2 for a in t) def rates(rows, w0, w1, m_base): """Weakening rates over [w0, w1]; dipole-moment rates in per cent of m_base (the model's 1840 value) a century.""" sel = [r for r in rows if w0 - 1e-9 <= r[0] <= w1 + 1e-9] if len(sel) < 3: return None t, A, M = [r[0] for r in sel], [r[4] for r in sel], [r[5] for r in sel] first, last = sel[0], sel[-1] return {"window": [first[0], last[0]], "n_epochs": len(sel), "absg10_weakening_nT_per_yr_OLS": round(-ols_slope(t, A), 3), "absg10_weakening_nT_per_yr_endpoints": round((first[4] - last[4]) / (last[0] - first[0]), 3), "M_weakening_pct_per_century_OLS": round(-100 * ols_slope(t, M) / m_base * 100, 3), "M_weakening_pct_per_century_endpoints": round(100 * (first[5] - last[5]) / (last[0] - first[0]) / m_base * 100, 3), "M_base_1e22Am2": round(m_base, 5)} def pinned(rows, t0=1590, t1=1840): """Weakening rate of |g10| over [t0, t1] from a line forced through the model's own value at t1 (nT/yr).""" sel = [r for r in rows if t0 <= r[0] <= t1] a1 = {r[0]: r[4] for r in sel}[t1] num = sum((r[0] - t1) * (r[4] - a1) for r in sel) den = sum((r[0] - t1) ** 2 for r in sel) return round(-num / den, 3) def power_band(flat, lmax, n0, n1): """Lowes-Mauersberger power of degrees n0..n1 at the core surface (nT^2).""" g, h = unflatten(flat, lmax) return sum((n + 1) * (A_KM / C_KM) ** (2 * n + 4) * sum(g[n][m] ** 2 + h[n][m] ** 2 for m in range(n + 1)) for n in range(n0, n1 + 1)) def series(ev, years): rows = [] for t in years: g10, g11, h11 = ev(t) A, M = dipole(g10, g11, h11) rows.append((t, g10, g11, h11, A, M)) return rows def schmidt(theta, nmax, deriv=False): """Schmidt semi-normalised P[n][m](cos theta) and, if asked, dP/dtheta.""" c, s = math.cos(theta), math.sin(theta) P = [[0.0] * (nmax + 1) for _ in range(nmax + 1)] dP = [[0.0] * (nmax + 1) for _ in range(nmax + 1)] P[0][0] = 1.0 for n in range(1, nmax + 1): for m in range(0, n + 1): if n == m: f = math.sqrt((2 * n - 1) / (2 * n)) if n > 1 else 1.0 P[n][m] = f * s * P[n - 1][m - 1] dP[n][m] = f * (c * P[n - 1][m - 1] + s * dP[n - 1][m - 1]) else: k1 = (2 * n - 1) / math.sqrt(n * n - m * m) k2 = math.sqrt(((n - 1) ** 2 - m * m) / (n * n - m * m)) if n > 1 else 0.0 P[n][m] = k1 * c * P[n - 1][m] - (k2 * P[n - 2][m] if n > 1 else 0.0) dP[n][m] = k1 * (c * dP[n - 1][m] - s * P[n - 1][m]) - (k2 * dP[n - 2][m] if n > 1 else 0.0) return (P, dP) if deriv else P def unflatten(flat, lmax): g = [[0.0] * (lmax + 1) for _ in range(lmax + 1)] h = [[0.0] * (lmax + 1) for _ in range(lmax + 1)] k = 0 for n in range(1, lmax + 1): g[n][0] = flat[k] k += 1 for m in range(1, n + 1): g[n][m], h[n][m] = flat[k], flat[k + 1] k += 2 return g, h def xyz(g, h, lmax, lat, lon): theta, phi = math.radians(90.0 - lat), math.radians(lon) P, dP = schmidt(theta, lmax, True) s = math.sin(theta) X = Y = Z = 0.0 for n in range(1, lmax + 1): for m in range(0, n + 1): cm, sm = math.cos(m * phi), math.sin(m * phi) gh = g[n][m] * cm + h[n][m] * sm X += gh * dP[n][m] if s > 1e-12: Y += m * (g[n][m] * sm - h[n][m] * cm) * P[n][m] / s Z -= (n + 1) * gh * P[n][m] return X, Y, Z def dip_pole(g, h, lmax): best = None for i in range(30): # coarse search, 60-89 N, every 4 degrees of longitude lat = 60.0 + i for j in range(90): lon = -180.0 + 4.0 * j X, Y, _ = xyz(g, h, lmax, lat, lon) H = math.hypot(X, Y) if best is None or H < best[0]: best = (H, lat, lon) la, lo = best[1], best[2] for _ in range(60): # Newton steps on (X, Y) = 0 X, Y, _ = xyz(g, h, lmax, la, lo) if math.hypot(X, Y) < 1e-7: break e = 1e-5 X1, Y1, _ = xyz(g, h, lmax, la + e, lo) X2, Y2, _ = xyz(g, h, lmax, la, lo + e) a11, a21, a12, a22 = (X1 - X) / e, (Y1 - Y) / e, (X2 - X) / e, (Y2 - Y) / e det = a11 * a22 - a12 * a21 dla = (-X * a22 + Y * a12) / det dlo = (-Y * a11 + X * a21) / det la, lo = la + dla, lo + dlo X, Y, _ = xyz(g, h, lmax, la, lo) return la, ((lo + 180.0) % 360.0) - 180.0, math.hypot(X, Y) def gc_km(lat1, lon1, lat2, lon2): p1, p2, dl = math.radians(lat1), math.radians(lat2), math.radians(lon2 - lon1) c = math.sin(p1) * math.sin(p2) + math.cos(p1) * math.cos(p2) * math.cos(dl) return R_KM * math.acos(max(-1.0, min(1.0, c))) def geomag_pole(g10, g11, h11): m = math.sqrt(g10 * g10 + g11 * g11 + h11 * h11) return 90.0 - math.degrees(math.acos(-g10 / m)), math.degrees(math.atan2(-h11, -g11)) class CMBGrid: """1-degree grid at the core surface: Legendre values per latitude, cos/sin tables per longitude.""" def __init__(self, nmax=14): self.th = [math.radians(0.5 + i) for i in range(180)] self.ph = [math.radians(0.5 + j) for j in range(360)] self.P = [schmidt(t, nmax) for t in self.th] self.cos = [[math.cos(m * p) for p in self.ph] for m in range(nmax + 1)] self.sin = [[math.sin(m * p) for p in self.ph] for m in range(nmax + 1)] d = math.radians(1.0) k = 3.0 / (8.0 * math.pi) * (C_KM / A_KM) ** 3 self.w = [k * math.cos(t) * math.sin(t) * d * d for t in self.th] # weight for Br in each cell self.area = [math.sin(t) * d * d for t in self.th] def brgrid(self, flat, lmax, L): """Br at the core surface on the grid, truncated at degree L: rows of 360 values, one per latitude.""" g, h = unflatten(flat, lmax) fac = [0.0] + [(n + 1) * (A_KM / C_KM) ** (n + 2) for n in range(1, lmax + 1)] out = [] for i in range(len(self.th)): P = self.P[i] Am = [sum(fac[n] * g[n][m] * P[n][m] for n in range(max(1, m), L + 1)) for m in range(L + 1)] Bm = [sum(fac[n] * h[n][m] * P[n][m] for n in range(max(1, m), L + 1)) for m in range(L + 1)] row = [] for j in range(360): br = 0.0 for m in range(L + 1): br += Am[m] * self.cos[m][j] + Bm[m] * self.sin[m][j] row.append(br) out.append(row) return out def footprint(self, b0, b1): """Change in the g10 contribution of the southern cells that are reversed (Br < 0) in b1, from b0 to b1.""" tot = 0.0 for i, t in enumerate(self.th): if t > math.pi / 2: w = self.w[i] for x0, x1 in zip(b0[i], b1[i]): if x1 < 0: tot += w * (x1 - x0) return tot def decompose(self, flat, lmax, L): grid = self.brgrid(flat, lmax, L) parts = {"N-normal": 0.0, "N-reversed": 0.0, "S-normal": 0.0, "S-reversed": 0.0} rev_area = s_area = 0.0 for i, t in enumerate(self.th): north = t < math.pi / 2 w, a = self.w[i], self.area[i] for br in grid[i]: v = br * w if north: parts["N-normal" if br < 0 else "N-reversed"] += v else: parts["S-normal" if br > 0 else "S-reversed"] += v s_area += a if br < 0: rev_area += a parts["sum"] = sum(parts.values()) parts["S-reversed area share of S hemisphere"] = rev_area / s_area return parts # ------------------------------------------------------------------ main def main(): folder = sys.argv[1] if len(sys.argv) > 1 else os.path.dirname(os.path.abspath(__file__)) os.makedirs(folder, exist_ok=True) raw = {name: get(folder, name) for name in INPUTS} txt = {k: v.decode("latin-1") for k, v in raw.items() if v is not None and not k.endswith(".zip")} zcals = zipfile.ZipFile(io.BytesIO(raw["CALS10k2.zip"])).read("CALS10k.2").decode("latin-1") zdm = zipfile.ZipFile(io.BytesIO(raw["DM_CALS10k_2.zip"])).read("DM_CALS10k_2.txt").decode("latin-1") guf = read_gufm1_colorado(txt["gufm1.txt"]) guf2 = read_korte(txt["pymagglobal_gufm1"], "gufm1 (pymagglobal)") cals = read_korte(txt["pymagglobal_CALS10k.2"], "CALS10k.2") cals_gfz = read_korte(zcals, "CALS10k.2 (GFZ)") arch = read_korte(txt["pymagglobal_ARCH10k.1"], "ARCH10k.1") hfm = read_korte(txt["pymagglobal_HFM.OL1.A1"], "HFM.OL1.A1") pfm = read_korte(txt["pymagglobal_pfm9k.1a"], "pfm9k.1a") arhi = read_korte(txt["pymagglobal_arhimag1k"], "arhimag1k") cov = read_covobs(txt["COV-OBS.x2-int"]) res = {"script": "dipole_before_1840.py", "inputs_sha256": {k: v[1] for k, v in INPUTS.items()}, "checks": {}, "models": {}, "readings": {}, "since_1590": {}, "reverse_flux": {}, "directions": {}, "chart": {}} # A. checks yrs = range(1590, 1991) d1 = max(max(abs(a - b) for a, b in zip(guf.deg1(t), guf2.deg1(t))) for t in yrs) d2 = max(max(abs(a - b) for a, b in zip(cals.deg1(t), cals_gfz.deg1(t))) for t in yrs) dm = {int(float(p[0])): float(p[1]) for p in (ln.split() for ln in zdm.split("\n")) if len(p) >= 2} d3 = max(abs(dipole(*cals.deg1(t))[1] - dm[t]) for t in yrs) times, tab = read_covobs_shc(txt["COV-OBS.x2-int.shc"]) d4 = 0.0 for i, t in enumerate(times): if 1840.0 <= t <= 2020.0: g10, g11, h11 = cov.deg1(t) d4 = max(d4, abs(g10 - tab[(1, 0)][i]), abs(g11 - tab[(1, 1)][i]), abs(h11 - tab[(1, -1)][i])) g90 = {"gufm1": guf.deg1(1990)[0], "COV-OBS.x2": cov.deg1(1990)[0]} res["checks"] = { "gufm1 copies, max difference in degree 1 (nT)": d1, "CALS10k.2 copies, max difference in degree 1 (nT)": d2, "CALS10k.2 dipole moment vs GFZ's series, max |difference| (1e22 A m^2)": round(d3, 5), "COV-OBS.x2 splines vs its table, max difference in degree 1 (nT)": round(d4, 4), "g10 in 1990 (nT)": {k: round(v, 1) for k, v in g90.items()}, "all pass": (d1 < 1e-6 and d2 < 1e-6 and d3 < 0.006 and d4 < 0.5 and all(abs(v - DGRF1990_G10) < 30 for v in g90.values())), } print("checks:", json.dumps(res["checks"])) # B. rates specs = [("gufm1", guf, 1590, 1990), ("COV-OBS.x2", cov, 1840, 1990), ("CALS10k.2", cals, 1590, 1990), ("ARCH10k.1", arch, 1590, 1990), ("HFM.OL1.A1", hfm, 1590, 1990), ("pfm9k.1a", pfm, 1590, 1900), ("arhimag1k", arhi, 1590, 1990)] all_rows = {} for name, mdl, a, b in specs: rows = series(mdl.deg1, range(a, b + 1)) all_rows[name] = rows absg = {r[0]: r[4] for r in rows} m1840 = {r[0]: r[5] for r in rows}[1840] dec = {} for y in range(a, b - 9, 10): dec[str(y)] = round((absg[y] - absg[y + 10]) / 10.0, 2) res["models"][name] = { "1590-1840": rates(rows, 1590, 1840, m1840), "1840-1990" if b >= 1990 else "1840-1900": rates(rows, 1840, min(b, 1990), m1840), "1840-1900": rates(rows, 1840, 1900, m1840), "pinned at 1840, 1590-1840 (nT/yr; added after review)": pinned(rows) if a <= 1590 else None, "absg10_nT": {str(y): round(absg[y], 1) for y in (1590, 1700, 1800, 1840, 1900, 1990) if y in absg}, "M_1e22Am2": {str(r[0]): round(r[5], 4) for r in rows if r[0] in (1590, 1700, 1800, 1840, 1900, 1990)}, "weakening_by_decade_nT_per_yr": dec, } if name == "COV-OBS.x2": res["models"][name]["1840-1860"] = rates(rows, 1840, 1860, m1840) res["models"][name]["1840-2020"] = rates(series(cov.deg1, range(1840, 2021)), 1840, 2020, m1840) if raw["coeff_SHA.DIF.14k.dat"] is not None: sha = read_shadif(txt["coeff_SHA.DIF.14k.dat"]) ts = sorted(t for t in sha if 1590 <= t <= 1900) rows = [(t,) + sha[t] + dipole(*sha[t]) for t in ts] sha_m = {r[0]: r[5] for r in rows} res["models"]["SHA.DIF.14k"] = {"epochs": ts, "1600-1800": rates(rows, 1590, 1840, sha_m[1800.0]), "M base": "its 1800 value (it has no 1840 epoch)", "absg10_nT": {str(int(r[0])): round(r[4], 1) for r in rows}, "M_1e22Am2": {str(int(r[0])): round(r[5], 4) for r in rows}} g = [guf.deg1(t)[0] for t in range(1590, 1861)] decade = [(g[i + 10] - g[i]) / 10.0 for i in range(0, 250, 10)] bend = next((1591 + i for i in range(len(g) - 2) if abs(g[i + 2] - 2 * g[i + 1] + g[i]) >= 0.01), None) res["readings"]["gufm1 before 1840"] = { "mean g10 slope 1590-1840 (nT/yr)": round((g[250] - g[0]) / 250.0, 3), "decade slopes min, max (nT/yr)": [round(min(decade), 2), round(max(decade), 2)], "1840s, 1850s (nT/yr)": [round((g[260] - g[250]) / 10.0, 2), round((g[270] - g[260]) / 10.0, 2)], "first year with a yearly second difference >= 0.01 nT/yr^2": bend} cls = {} for name, d in res["models"].items(): r = d.get("1590-1840") or d.get("1600-1800") if r: v = r["absg10_weakening_nT_per_yr_OLS"] cls[name] = [v, "within Gubbins et al.'s 1-sigma range" if -0.44 <= v <= 5.0 else "between 5 and 10" if 5.0 < v < 10.0 else "10 or more (registered as near gufm1's 15)" if v >= 10.0 else "growing"] res["readings"]["1590-1840 classes"] = cls # C. the 1590 field and the loss since g1840 = guf.deg1(1840)[0] g2025 = read_igrf_g10(txt["igrf14coeffs.txt"]) a1590_guf = abs(guf.deg1(1590)[0]) a1590_gub = abs(g1840) + GUBBINS_RATE * 250 a1840_cov = abs(cov.deg1(1840)[0]) res["since_1590"] = { "|g10| 1840, gufm1 (nT)": round(abs(g1840), 1), "|g10| 1840, COV-OBS.x2 (nT)": round(a1840_cov, 1), "|g10| 1590, gufm1 (nT)": round(a1590_guf, 1), "|g10| 1590 at 2.28 nT/yr from gufm1's 1840 value (nT)": round(a1590_gub, 1), "1590 above 1840, gufm1 / Gubbins (%)": [round(100 * (a1590_guf / abs(g1840) - 1), 2), round(100 * (a1590_gub / abs(g1840) - 1), 2)], "IGRF-14 g10 2025.0 (nT)": g2025, "loss 1590-2025, gufm1 / Gubbins (%)": [round(100 * (1 - abs(g2025) / a1590_guf), 2), round(100 * (1 - abs(g2025) / a1590_gub), 2)], "loss 1840-2025, COV-OBS.x2 1840 to IGRF-14 2025 (%)": round(100 * (1 - abs(g2025) / a1840_cov), 2)} # D. reverse flux at the core surface print("core-surface decomposition (a minute or two) ...") grid = CMBGrid(14) rf = {} for name, mdl, years in (("gufm1", guf, range(1590, 1991, 10)), ("COV-OBS.x2", cov, range(1840, 2021, 10))): rf[name] = {} for L in (14, 8): ep = {} for t in years: flat = mdl.coeffs(t) p = grid.decompose(flat, mdl.lmax, L) p["g10_model"] = flat[0] ep[t] = p def split(a, b): hn = lambda t: ep[t]["N-normal"] + ep[t]["N-reversed"] hs = lambda t: ep[t]["S-normal"] + ep[t]["S-reversed"] return [round((hn(b) - hn(a)) / (b - a), 2), round((hs(b) - hs(a)) / (b - a), 2), round((ep[b]["g10_model"] - ep[a]["g10_model"]) / (b - a), 2)] dg = ep[1990]["g10_model"] - ep[1840]["g10_model"] out = {"worst |sum - g10| / |g10|": max(abs(p["sum"] - p["g10_model"]) / abs(p["g10_model"]) for p in ep.values()), "(gN, gS, g10) 1840-1980, nT/yr": split(1840, 1980), "share of the 1840-1990 fall": {k: round((ep[1990][k] - ep[1840][k]) / dg, 3) for k in ("N-normal", "N-reversed", "S-normal", "S-reversed")}, "epochs": {str(t): {k: round(v, 4 if "share" in k else 1) for k, v in p.items()} for t, p in ep.items()}} if name == "gufm1": early = max(ep[t]["S-reversed"] for t in ep if t <= 1830) out["max S-reversed 1590-1830 / its 1990 value"] = round(early / ep[1990]["S-reversed"], 3) lam = (ep[1840]["g10_model"] - GUBBINS_RATE * 250) / ep[1590]["g10_model"] hn = lambda t, s=1.0: s * (ep[t]["N-normal"] + ep[t]["N-reversed"]) hs = lambda t, s=1.0: s * (ep[t]["S-normal"] + ep[t]["S-reversed"]) out["exploratory: (gN, gS, g10) 1590-1840 with gufm1 rescaled to 2.28 nT/yr"] = [ round((hn(1840) - hn(1590, lam)) / 250, 2), round((hs(1840) - hs(1590, lam)) / 250, 2), round((hn(1840) + hs(1840) - lam * (hn(1590) + hs(1590))) / 250, 2)] end2 = 2010 if name == "COV-OBS.x2" else 1990 dg2 = ep[end2]["g10_model"] - ep[1880]["g10_model"] share = lambda keys, a, b, d: round(sum(ep[b][k] - ep[a][k] for k in keys) / d, 3) out["R-a (registered): S-reversed carries at least half of the 1840-1990 fall"] = \ out["share of the 1840-1990 fall"]["S-reversed"] >= 0.5 out["added after review: shares of the fall, S-reversed and all reversed"] = { "1840-1990": [share(["S-reversed"], 1840, 1990, dg), share(["S-reversed", "N-reversed"], 1840, 1990, dg)], "1880-%d" % end2: [share(["S-reversed"], 1880, end2, dg2), share(["S-reversed", "N-reversed"], 1880, end2, dg2)]} fp = {} for a, b in ((1840, 1990), (1880, end2)): b0 = grid.brgrid(mdl.coeffs(a), mdl.lmax, L) b1 = grid.brgrid(mdl.coeffs(b), mdl.lmax, L) fp["%d-%d" % (a, b)] = round(grid.footprint(b0, b1) / (ep[b]["g10_model"] - ep[a]["g10_model"]), 3) out["added after review: footprint share (southern cells reversed at the window's end)"] = fp rf[name]["L%d" % L] = out print(" %s to degree %d: (gN, gS, g10) 1840-1980 = %s" % (name, L, out["(gN, gS, g10) 1840-1980, nT/yr"])) rf["COV-OBS.x2"]["added after review: power of degrees 9-14 at the core surface (1e9 nT^2)"] = { str(t): round(power_band(cov.coeffs(t), cov.lmax, 9, 14) / 1e9, 1) for t in (1840, 1860, 1880, 1900, 1950, 2000)} rf["gufm1"]["added after review: power of degrees 9-14 at the core surface (1e9 nT^2)"] = { str(t): round(power_band(guf.coeffs(t), guf.lmax, 9, 14) / 1e9, 1) for t in (1840, 1880, 1900, 1950)} res["reverse_flux"] = rf # E. directions in gufm1 sites = {"London": (51.5, -0.12), "Cape Town": (-33.9, 18.4)} dec, poles, gm = {k: {} for k in sites}, {}, {} print("directions in gufm1 ...") for t in range(1590, 1991, 10): flat = guf.coeffs(t) gg, hh = unflatten(flat, guf.lmax) for k, (la, lo) in sites.items(): X, Y, _ = xyz(gg, hh, guf.lmax, la, lo) dec[k][str(t)] = round(math.degrees(math.atan2(Y, X)), 2) poles[t] = dip_pole(gg, hh, guf.lmax) gm[t] = geomag_pole(flat[0], flat[1], flat[2]) def path(a, b): ts = list(range(a, b + 1, 10)) dist = sum(gc_km(poles[x][0], poles[x][1], poles[y][0], poles[y][1]) for x, y in zip(ts, ts[1:])) return {"path_km": round(dist, 1), "mean_km_per_yr": round(dist / (b - a), 2), "net_km": round(gc_km(poles[a][0], poles[a][1], poles[b][0], poles[b][1]), 1)} res["directions"] = { "declination_deg": dec, "declination range 1590-1840": {k: [min(v for t, v in dec[k].items() if int(t) <= 1840), max(v for t, v in dec[k].items() if int(t) <= 1840)] for k in sites}, "declination range 1840-1990": {k: [min(v for t, v in dec[k].items() if int(t) >= 1840), max(v for t, v in dec[k].items() if int(t) >= 1840)] for k in sites}, "geomagnetic pole lat, lon": {str(t): [round(v[0], 3), round(v[1], 3)] for t, v in gm.items()}, "dip pole lat, lon, |H| (nT)": {str(t): [round(v[0], 3), round(v[1], 3), round(v[2], 6)] for t, v in poles.items()}, "dip pole path, 10-year steps": {"1590-1840": path(1590, 1840), "1840-1990": path(1840, 1990)}} # F. the chart's series res["chart"] = {name: {str(r[0]): round(r[4], 1) for r in rows if r[0] % 5 == 0} for name, rows in all_rows.items()} res["chart"]["Gubbins et al. line"] = {"1590": round(a1590_gub, 1), "1840": round(abs(g1840), 1), "1590 low, high (1 SD)": [round(abs(g1840) + (GUBBINS_RATE - GUBBINS_SD) * 250, 1), round(abs(g1840) + (GUBBINS_RATE + GUBBINS_SD) * 250, 1)]} out = os.path.join(folder, "dipole-numbers.json") with open(out, "w", encoding="utf-8", newline="\n") as f: json.dump(res, f, indent=1, ensure_ascii=False) f.write("\n") print("\nWeakening of |g10|, nT/yr (least squares), 1590-1840 | 1840-1990:") for name, d in res["models"].items(): r1 = d.get("1590-1840") or d.get("1600-1800") r2 = d.get("1840-1990") or d.get("1840-1900") print(" %-12s %8s | %s" % (name, r1 and r1["absg10_weakening_nT_per_yr_OLS"], r2 and r2["absg10_weakening_nT_per_yr_OLS"])) print("wrote", out) if __name__ == "__main__": main()