#!/usr/bin/env python3 """How low, how widely and for how long did Earth's surface field fall at the Laschamp excursion? Our own evaluator of LSMOD.2 (Korte & Brown 2019, GFZ Data Services, CC BY 4.0), the preferred model of Korte et al. (2019). The file format and spline logic follow the site's earlier evaluator, verification/field-falters/code/report-C/lsmod2_dm.py; the authors' Fortran is not executed. RULES, fixed before the first run (2026-11-04): 1. Field: total intensity F from the internal Gauss coefficients at r = a = 6371.2 km, degree 10, on a sphere (no altitude, no oblateness). 2. Grid: 1-degree cell centres, weighted by cos(latitude). Time: every 10 years from 44.00 to 38.00 ka BP, the excursion's main span in Korte et al. (2019) section 4.4 and Table 2. 3. Per epoch: lowest F on the grid, refined on a 0.05-degree grid around the coarse minimum; area-weighted mean and median; area below 30 nT, 100 nT, 300 nT, 1 uT, 5 uT, 10 uT. 4. Per location: lowest F reached in the span, and the longest unbroken spell below 100 nT, 300 nT, 1 uT and 5 uT. Report the area that ever went below each level. 5. Validation: Korte et al. section 4.6 give a lowest surface value of 0.12 uT for their preferred model, and 3.7 ZAm2 as the model's lowest dipole moment (Table S5, as read for /field-falters/). If we do not reproduce those to within rounding, the numbers are not used. 6. A sanity check on the evaluator: a pure dipole must give |g10| at the equator, 2|g10| at a pole. 7. Reading the result: a model truncated at degree 10 and built from smoothed sediment records cannot resolve small-scale field, and a lowest value is where three components happen to pass near zero at a point. It is a rough guide to area and time, not a measurement at any place. Added after the first run, as description only (no new test): the summary of the main phase, the distribution over the surface at the lowest median, and the list of cells and decades below 30 nT. Outcome of rule 5: the dipole moment reproduces (3.67 ZAm2). Korte's 0.12 uT could not be matched to its digits: our lowest values per decade near 40.6 ka scatter from 29 to 910 nT, and Korte's epoch and grid are not stated. So point minima from this script are indicative only, and the page cites Korte for the point minimum. Added after a fresh review of the page (RULES_review_addendum.txt, R4), not before the first run: --fine also runs a yearly 1-degree grid and a 2-year 0.5-degree grid and writes lsmod2_sampling.json, because the two lowest rows of the area table depend on sampling. The first run's outputs do not change. Rule 5 was relaxed: Korte's 0.12 uT was not reproduced, yet the areas are used, because they do not rest on the point minimum; the page says so. Needs numpy; the script downloads LSMOD2.zip from GFZ Data Services (CC BY 4.0) unless you give it a local copy, checks its SHA-256, and reads the model file from inside it. The zip's Fortran is neither extracted nor run. --fine takes several minutes and over 1 GB of memory. Usage: py -3.12 -I lsmod2_surface.py [] [--fine] """ import hashlib import io import json import math import sys import urllib.request import zipfile from pathlib import Path import numpy as np A = 6371.2e3 LEVELS_NT = [30.0, 100.0, 300.0, 1000.0, 5000.0, 10000.0] SPELL_NT = [100.0, 300.0, 1000.0, 5000.0] SITES = { "Turin (the coil's laboratory, 45.02N 7.62E)": (45.0164, 7.6161), "Laschamp flows, central France (45.73N 2.95E)": (45.73, 2.95), "Louchadiere flow, central France (45.80N 2.92E)": (45.80, 2.92), "Skalamaelifell, Iceland (63.85N 22.40W)": (63.85, -22.40), "Auckland, New Zealand (36.9S 174.8E)": (-36.9, 174.8), } ZIP_URL = "https://datapub.gfz.de/download/10.5880.GFZ.2.3.2019.001/LSMOD2.zip" ZIP_SHA256 = "38d84bfa3ac23030b5551bebab98bcf67c25eae447d556bd5b0ab43cd2cd910c" def load_zip(path): if path: data = Path(path).read_bytes() else: req = urllib.request.Request(ZIP_URL, headers={"User-Agent": "factchecked-research/1.0"}) with urllib.request.urlopen(req, timeout=120) as resp: data = resp.read() digest = hashlib.sha256(data).hexdigest() if digest != ZIP_SHA256: print("Warning: LSMOD2.zip differs from the file these numbers were computed from:", digest) with zipfile.ZipFile(io.BytesIO(data)) as z: return z.read("LSMOD2/LSMOD.2") def read_model(raw): text = raw.decode("ascii", errors="replace") first, rest = text.split("\n", 1) toks = rest.split() lmax, nm, nspl = int(toks[0]), int(toks[1]), int(toks[2]) pos = 3 knots = np.array([float(x.replace("D", "E")) for x in toks[pos:pos + nspl + 4]]) pos += nspl + 4 n = lmax * (lmax + 2) vals = np.array([float(x.replace("D", "E")) for x in toks[pos:pos + n * nspl]]) if vals.size != n * nspl: raise ValueError("expected %d coefficients, got %d" % (n * nspl, vals.size)) gt = vals.reshape((nspl, n)) # column-major in Fortran: gt[j, k] is spline j, coefficient k return {"header": first.strip()[:230], "sha256": hashlib.sha256(raw).hexdigest(), "lmax": lmax, "nspl": nspl, "knots": knots, "gt": gt} def coeffs_at(model, age_ka): knots, nspl, gt = model["knots"], model["nspl"], model["gt"] t = 1950.0 - 1000.0 * age_ka if t < knots[3] or t > knots[nspl]: raise ValueError("time outside model range") nleft = 4 for nn in range(5, nspl + 2): if t <= knots[nn - 1]: nleft = nn - 1 break spl = [0.0] * 4 spl[0] = 1.0 dl = [0.0] * 4 dr = [0.0] * 4 for j in range(1, 4): dr[j - 1] = knots[nleft + j - 1] - t dl[j - 1] = t - knots[nleft + 1 - j - 1] saved = 0.0 for i in range(1, j + 1): term = spl[i - 1] / (dr[i - 1] + dl[j + 1 - i - 1]) spl[i - 1] = saved + dr[i - 1] * term saved = dl[j + 1 - i - 1] * term spl[j] = saved out = np.zeros(gt.shape[1]) for j in range(1, 5): out += spl[j - 1] * gt[j + nleft - 4 - 1, :] return out def legendre(lmax, theta): """Schmidt quasi-normalised P and dP/dtheta, arrays indexed [l][m], for an array of colatitudes.""" c, s = np.cos(theta), np.sin(theta) P = [[None] * (l + 1) for l in range(lmax + 1)] D = [[None] * (l + 1) for l in range(lmax + 1)] P[0][0] = np.ones_like(theta) D[0][0] = np.zeros_like(theta) for l in range(1, lmax + 1): if l == 1: P[1][1] = s.copy() D[1][1] = c.copy() else: k = math.sqrt((2 * l - 1) / (2 * l)) P[l][l] = k * s * P[l - 1][l - 1] D[l][l] = k * (c * P[l - 1][l - 1] + s * D[l - 1][l - 1]) for m in range(l): k1 = (2 * l - 1) / math.sqrt(l * l - m * m) k2 = math.sqrt((l - 1) ** 2 - m * m) / math.sqrt(l * l - m * m) if l > 1 else 0.0 pm2 = P[l - 2][m] if l >= 2 and m <= l - 2 else 0.0 dm2 = D[l - 2][m] if l >= 2 and m <= l - 2 else 0.0 P[l][m] = k1 * c * P[l - 1][m] - k2 * pm2 D[l][m] = k1 * (c * D[l - 1][m] - s * P[l - 1][m]) - k2 * dm2 return P, D def basis(lmax, lat, lon): """Matrices turning a coefficient vector into (Br, Bt, Bp) at r = a. lat and lon are 1-D arrays of equal length, in degrees. Returns three arrays of shape (npoints, ncoeff).""" theta = np.radians(90.0 - lat) phi = np.radians(lon) P, D = legendre(lmax, theta) n = lmax * (lmax + 2) br = np.zeros((lat.size, n)) bt = np.zeros((lat.size, n)) bp = np.zeros((lat.size, n)) s = np.sin(theta) s = np.where(np.abs(s) < 1e-9, 1e-9, s) for l in range(1, lmax + 1): for m in range(l + 1): cm, sm = np.cos(m * phi), np.sin(m * phi) if m == 0: k = l * l - 1 br[:, k] = (l + 1) * P[l][0] bt[:, k] = -D[l][0] else: kg = l * l + 2 * m - 2 kh = l * l + 2 * m - 1 br[:, kg] = (l + 1) * P[l][m] * cm br[:, kh] = (l + 1) * P[l][m] * sm bt[:, kg] = -D[l][m] * cm bt[:, kh] = -D[l][m] * sm bp[:, kg] = m * P[l][m] * sm / s bp[:, kh] = -m * P[l][m] * cm / s return br, bt, bp def total(br, bt, bp, g): return np.sqrt((br @ g) ** 2 + (bt @ g) ** 2 + (bp @ g) ** 2) def weighted_median(values, weights): order = np.argsort(values) cum = np.cumsum(weights[order]) return float(values[order][np.searchsorted(cum, 0.5 * cum[-1])]) def sampling_run(model, lmax, grid_deg, step_years): """Rule R4: area ever below each level, the largest share at one moment, and the longest unbroken spell at one place, at a finer sampling.""" lat = np.arange(-90 + grid_deg / 2, 90.0, grid_deg) lon = np.arange(grid_deg / 2, 360.0, grid_deg) la, lo = np.meshgrid(lat, lon, indexing="ij") la1, lo1 = la.ravel(), lo.ravel() w = np.cos(np.radians(la1)) w = w / w.sum() br, bt, bp = basis(lmax, la1, lo1) levels = [30.0, 100.0, 300.0, 1000.0, 5000.0, 10000.0] fmin = np.full(la1.size, np.inf) run = {lev: np.zeros(la1.size) for lev in levels} best = {lev: np.zeros(la1.size) for lev in levels} largest = {lev: 0.0 for lev in levels} for age_yr in np.arange(44000.0, 37999.0, -step_years): F = total(br, bt, bp, coeffs_at(model, float(age_yr) / 1000.0)) fmin = np.minimum(fmin, F) for lev in levels: below = F < lev run[lev] = np.where(below, run[lev] + step_years, 0.0) best[lev] = np.maximum(best[lev], run[lev]) largest[lev] = max(largest[lev], float(w[below].sum())) return {"grid_degrees": grid_deg, "step_years": step_years, "levels": {str(int(lev)): {"share_ever_below": float(w[fmin < lev].sum()), "cells_ever_below": int((fmin < lev).sum()), "largest_share_at_one_moment": largest[lev], "longest_spell_years": float(best[lev].max())} for lev in levels}, "lowest_F_anywhere_nT": float(fmin.min())} def main(): args = [a for a in sys.argv[1:] if a != "--fine"] fine = "--fine" in sys.argv[1:] outdir = Path(args[0]) model = read_model(load_zip(args[1] if len(args) > 1 else None)) outdir.mkdir(parents=True, exist_ok=True) lmax = model["lmax"] # Rule 6: the evaluator against a pure dipole. test = np.zeros(lmax * (lmax + 2)) test[0] = -30000.0 b = basis(lmax, np.array([0.0, 89.999]), np.array([0.0, 0.0])) f = total(*b, test) assert abs(f[0] - 30000.0) < 1e-6 and abs(f[1] - 60000.0) < 1e-1, f lat = np.arange(-89.5, 90.0, 1.0) lon = np.arange(0.5, 360.0, 1.0) la, lo = np.meshgrid(lat, lon, indexing="ij") la1, lo1 = la.ravel(), lo.ravel() w = np.cos(np.radians(la1)) w = w / w.sum() br, bt, bp = basis(lmax, la1, lo1) ages = np.round(np.arange(44.00, 37.995, -0.01), 2) rows = [] fmin_map = np.full(la1.size, np.inf) agemin_map = np.zeros(la1.size) run = {lev: np.zeros(la1.size) for lev in SPELL_NT} best = {lev: np.zeros(la1.size) for lev in SPELL_NT} dt = 10.0 cells_below_30 = [] for age in ages: g = coeffs_at(model, float(age)) F = total(br, bt, bp, g) i = int(np.argmin(F)) # refine the lowest point on a fine local grid flat = np.arange(max(-90, la1[i] - 1.5), min(90, la1[i] + 1.5) + 1e-9, 0.05) flon = np.arange(lo1[i] - 1.5, lo1[i] + 1.5 + 1e-9, 0.05) fa, fo = np.meshgrid(flat, flon, indexing="ij") bb = basis(lmax, fa.ravel(), fo.ravel()) ff = total(*bb, g) j = int(np.argmin(ff)) dm = A ** 3 * 1e7 * math.sqrt(g[0] ** 2 + g[1] ** 2 + g[2] ** 2) * 1e-9 / 1e21 # ZAm2 row = {"age_ka": float(age), "min_F_nT": float(ff[j]), "min_lat": float(fa.ravel()[j]), "min_lon": float((fo.ravel()[j] + 180) % 360 - 180), "mean_F_nT": float((w * F).sum()), "median_F_nT": weighted_median(F, w), "max_F_nT": float(F.max()), "DM_ZAm2": dm, "g10_nT": float(g[0])} for lev in LEVELS_NT: row["area_below_%d_nT" % lev] = float(w[F < lev].sum()) rows.append(row) cold = np.where(F < 30.0)[0] if cold.size: cells_below_30.append({"age_ka": float(age), "cells": int(cold.size), "area_fraction": float(w[cold].sum()), "lat": [float(la1[c]) for c in cold], "lon": [float((lo1[c] + 180) % 360 - 180) for c in cold], "F_nT": [round(float(F[c]), 1) for c in cold]}) better = F < fmin_map fmin_map[better] = F[better] agemin_map[better] = age for lev in SPELL_NT: below = F < lev run[lev] = np.where(below, run[lev] + dt, 0.0) best[lev] = np.maximum(best[lev], run[lev]) res = {"rules": "see the script's docstring", "model_header": model["header"], "model_sha256": model["sha256"], "grid": "1-degree cell centres, cos(lat) weights; 44.00-38.00 ka BP every 10 years"} res["lowest_DM"] = min(rows, key=lambda r: r["DM_ZAm2"]) res["lowest_point_anywhere"] = min(rows, key=lambda r: r["min_F_nT"]) res["lowest_median"] = min(rows, key=lambda r: r["median_F_nT"]) res["lowest_mean"] = min(rows, key=lambda r: r["mean_F_nT"]) res["largest_area_below"] = {} for lev in LEVELS_NT: k = "area_below_%d_nT" % lev top = max(rows, key=lambda r: r[k]) res["largest_area_below"][str(int(lev))] = {"fraction": top[k], "age_ka": top["age_ka"]} res["area_ever_below"] = {str(int(lev)): float(w[fmin_map < lev].sum()) for lev in LEVELS_NT} res["percentiles_of_each_places_lowest_F_nT"] = { str(p): float(np.sort(fmin_map)[np.searchsorted(np.cumsum(w[np.argsort(fmin_map)]), p / 100.0)]) for p in (1, 5, 10, 25, 50, 75, 90, 95, 99)} res["longest_unbroken_spell_years"] = {} for lev in SPELL_NT: i = int(np.argmax(best[lev])) res["longest_unbroken_spell_years"][str(int(lev))] = { "years": float(best[lev][i]), "lat": float(la1[i]), "lon": float((lo1[i] + 180) % 360 - 180), "area_weighted_median_years_among_places_that_got_there": ( weighted_median(best[lev][best[lev] > 0], w[best[lev] > 0]) if (best[lev] > 0).any() else 0.0)} res["sites"] = {} for name, (slat, slon) in SITES.items(): bb = basis(lmax, np.array([slat]), np.array([slon])) series = [(float(a), float(total(*bb, coeffs_at(model, float(a)))[0])) for a in ages] low = min(series, key=lambda x: x[1]) res["sites"][name] = {"lowest_F_nT": low[1], "at_age_ka": low[0], "F_at_44ka_nT": series[0][1], "years_below_5uT": sum(dt for _, v in series if v < 5000.0), "years_below_1uT": sum(dt for _, v in series if v < 1000.0)} res["every_250_years"] = [r for r in rows if abs(round(r["age_ka"] * 1000) % 250) < 1e-6] # Added after the first run, as a description only (no new test): the span Korte et al. call the # surface field's excursional state in this model (Table 2, model C: 41.9 to 40.1 ka). main = [r for r in rows if 40.1 <= r["age_ka"] <= 41.9] res["main_phase_41.9_40.1ka"] = { "decades": len(main), "median_of_each_decades_lowest_point_nT": float(np.median([r["min_F_nT"] for r in main])), "share_of_decades_lowest_point_below": {str(int(lev)): float(np.mean([r["min_F_nT"] < lev for r in main])) for lev in (30.0, 100.0, 300.0, 1000.0)}, } # Added after the first run, as a description only (no new test): every 1-degree cell that ever fell below the coil's # 30 nT, and every decade whose refined lowest point did. Point values are indicative only (rule 5). res["cells_below_30_nT_by_decade"] = cells_below_30 res["decades_whose_refined_lowest_point_is_below_30_nT"] = [{"age_ka": r["age_ka"], "min_F_nT": round(r["min_F_nT"], 1), "lat": round(r["min_lat"], 2), "lon": round(r["min_lon"], 2)} for r in rows if r["min_F_nT"] < 30.0] # The distribution over the surface at the moment of the lowest area-weighted median. g = coeffs_at(model, res["lowest_median"]["age_ka"]) F = total(br, bt, bp, g) order = np.argsort(F) cum = np.cumsum(w[order]) res["distribution_at_lowest_median_nT"] = {str(p): float(F[order][np.searchsorted(cum, p / 100.0)]) for p in (1, 5, 25, 50, 75, 95, 99)} with open(outdir / "lsmod2_decades.tsv", "w", encoding="utf-8", newline="\n") as fh: fh.write("age_ka\tmin_F_nT\tmedian_F_nT\tmean_F_nT\tDM_ZAm2\tarea_below_1uT\tarea_below_5uT\n") for r in rows: fh.write("%.2f\t%.0f\t%.0f\t%.0f\t%.2f\t%.5f\t%.5f\n" % (r["age_ka"], r["min_F_nT"], r["median_F_nT"], r["mean_F_nT"], r["DM_ZAm2"], r["area_below_1000_nT"], r["area_below_5000_nT"])) with open(outdir / "lsmod2_surface.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1) if fine: sampling = {"1_degree_1_year": sampling_run(model, lmax, 1.0, 1.0), "half_degree_2_years": sampling_run(model, lmax, 0.5, 2.0)} with open(outdir / "lsmod2_sampling.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(sampling, fh, indent=1) print("sampling", json.dumps(sampling)) print("model sha256", model["sha256"]) print("lowest dipole moment: %.2f ZAm2 at %.2f ka" % (res["lowest_DM"]["DM_ZAm2"], res["lowest_DM"]["age_ka"])) p = res["lowest_point_anywhere"] print("lowest point anywhere: %.0f nT at %.2f ka, %.1f lat %.1f lon" % (p["min_F_nT"], p["age_ka"], p["min_lat"], p["min_lon"])) q = res["lowest_median"] print("lowest area-weighted median: %.0f nT at %.2f ka (mean there %.0f nT, max %.0f nT)" % (q["median_F_nT"], q["age_ka"], q["mean_F_nT"], q["max_F_nT"])) print("largest area below:", json.dumps(res["largest_area_below"])) print("area ever below:", json.dumps(res["area_ever_below"])) print("each place's lowest F, area percentiles (nT):", json.dumps(res["percentiles_of_each_places_lowest_F_nT"])) print("longest spells:", json.dumps(res["longest_unbroken_spell_years"])) print("sites:", json.dumps(res["sites"], indent=1)) print("main phase:", json.dumps(res["main_phase_41.9_40.1ka"])) print("distribution at the lowest median:", json.dumps(res["distribution_at_lowest_median_nT"])) print("age, minF, medianF, meanF, DM, g10, %<1uT, %<5uT") for r in res["every_250_years"]: print("%.2f %7.0f %7.0f %7.0f %6.2f %8.0f %6.1f %6.1f" % (r["age_ka"], r["min_F_nT"], r["median_F_nT"], r["mean_F_nT"], r["DM_ZAm2"], r["g10_nT"], 100 * r["area_below_1000_nT"], 100 * r["area_below_5000_nT"])) if __name__ == "__main__": main()