"""make_charts.py -- small chart data files for the page, from out/*.json. python3 -I make_charts.py """ import csv import json import os import sys out, chart = sys.argv[1], sys.argv[2] dig = json.load(open(os.path.join(out, "digitize.json"), encoding="utf-8")) am = json.load(open(os.path.join(out, "amounts.json"), encoding="utf-8")) ig = json.load(open(os.path.join(out, "igrf_tilt.json"), encoding="utf-8")) CREDIT = dig["credit"] def sig(x, n=3): return float("%.*g" % (n, x)) def dump(name, obj): with open(os.path.join(chart, name), "w", encoding="utf-8", newline="\n") as f: json.dump(obj, f, indent=1, ensure_ascii=False) print(name, os.path.getsize(os.path.join(chart, name)), "bytes") D = {"D=1e-4": 1e-4, "D=1e-3": 1e-3, "D=1e-2": 1e-2, "D=0.1": 0.1, "D=1": 1.0, "D=10": 10.0} dump("fig4_moment.json", { "title": "O+ escape rate against dipole strength (tilt 0), as plotted in Wang et al. (2026) Fig. 4", "credit": CREDIT, "x": "dipole strength D (today's reference = 1)", "y": "O+ escape rate (ions per second)", "points": [{"D": D[r["nominal"]], "rate": sig(r["y_mean"]), "u_dex": sig(r["u_dex"], 2)} for r in dig["points"]["fig4"]], "text_values": [{"D": 1, "rate": 5.76e21, "quote": "5.76 x 10^21 at X = -30 R_E"}, {"D": 0.1, "rate": 1e24, "quote": "~10^24"}, {"D": 10, "rate": 1e19, "quote": "~10^19"}, {"D_max": 0.01, "rate_range": [1e25, 1e26], "quote": "~10^25-10^26"}], "measured_today_for_scale": {"Slapak et al. 2017 mean, 2016-2025 Kp (as on /ring-current-oxygen/)": sig(am["rates"]["measured: Slapak et al. 2017, 2016-2025 Kp mean (as on /ring-current-oxygen/)"]["ions_per_s"])}, }) k = [r for r in dig["points"]["fig6"] if r["series"] == "black"] b = [r for r in dig["points"]["fig6"] if r["series"] == "blue"] f5 = dig["points"]["fig5"] dump("fig5_fig6_tilt.json", { "title": "O+ escape rate against dipole tilt: today's dipole strength (Fig. 5; Fig. 6 black) and the paper's " "decaying-dipole path (Fig. 6 blue)", "credit": CREDIT, "x": "dipole tilt angle (degrees)", "y": "O+ escape rate (ions per second)", "fixed_D1_fig5": [{"tilt": round(r["x_A"] / 30) * 30, "rate": sig(r["y_mean"])} for r in f5], "fixed_D1_fig6_black": [{"tilt": round(r["x_A"] / 30) * 30, "rate": sig(r["y_mean"])} for r in k], "path_fig6_blue": [{"tilt": round(r["x_A"] / 30) * 30, "D": {0: 1.0, 30: 0.7, 60: 0.4, 90: 0.1}[round(r["x_A"] / 30) * 30], "rate": sig(r["y_mean"])} for r in b], "fig4_D0.1_tilt0_for_comparison": sig([r for r in dig["points"]["fig4"] if r["nominal"] == "D=0.1"][0]["y_mean"]), "today_gsm_tilt_range_deg": [0, sig(max(abs(ig["gsm_tilt"]["2025"]["psi_max_deg"]), abs(ig["gsm_tilt"]["2025"]["psi_min_deg"])), 3)], }) rows = [] keep = ["P_max digitized", "F4 digitized", "SAT 1e26", "NOW measured (Slapak mean)", "SCALED SAT 1e26 (extreme reading)", "for scale: Wei et al. 2014 (6.5e29)"] labels = {"P_max digitized": "Paper's reversal path, its peak (0.1D at 90 deg) held throughout", "F4 digitized": "A tenth of today's dipole, untilted, throughout (Fig. 4)", "SAT 1e26": "The model's saturated rate (top of its range) throughout: a ceiling no record supports", "NOW measured (Slapak mean)": "Measured escape today (Slapak et al. 2017, mean), for comparison", "SCALED SAT 1e26 (extreme reading)": "Extreme reading: measured escape today x the model's saturated rise", "for scale: Wei et al. 2014 (6.5e29)": "Wei et al. (2014)'s required rate, for scale"} for s in keep: for d in ("L2 2,000 yr (Laschamp low)", "V2 10,000 yr (Wei et al. 2014's duration)"): v = am["scenarios"][s][d] rows.append({"scenario": labels[s], "duration_yr": 2000 if d.startswith("L2") else 10000, "tonnes": sig(v["tonnes"], 2), "fraction_of_atmospheric_O2": sig(v["fraction_of_O2"], 2), "days_of_todays_O2_decline": sig(v["decline_days"], 2)}) dump("amounts.json", { "title": "Oxygen lost to space over an excursion or a reversal, at the paper's rates, against the air's oxygen and " "today's measured O2 decline (our analysis)", "credit": "Rates from Wang et al. (2026) Figs. 4 and 6 (CC BY 4.0), digitized; measured escape from Slapak et al. " "(2017); O2 inventory and decline from the Scripps O2 Program (CC BY 4.0) as on /ring-current-oxygen/; " "Wei et al. (2014). Arithmetic by Fact-Checked Science.", "o2_inventory_kg": sig(am["constants"]["O2_kg"], 4), "todays_decline_kg_per_yr": sig(am["constants"]["decline_kg_per_yr"], 3), "rows": rows}) weekly = {} for yr in ("2025", "1900"): with open(os.path.join(out, "tilt_daily_%s.csv" % yr), encoding="utf-8") as f: r = [x for x in csv.reader(ln for ln in f if not ln.startswith("#"))][1:] weekly[yr] = [{"date": x[0], "min": float(x[1]), "max": float(x[2])} for i, x in enumerate(r) if i % 7 == 0] dump("gsm_tilt_2025_1900.json", { "title": "The dipole's tilt in GSM, daily minimum and maximum (every 7th day), 2025 and 1900 (our analysis)", "credit": "IGRF-14 (IAGA V-MOD, via NOAA NCEI) dipole coefficients; Sun from the US Naval Observatory's approximate " "solar coordinates; computed by Fact-Checked Science.", "units": "degrees; positive when the northern dipole axis leans toward the Sun", "extremes": {yr: [sig(ig["gsm_tilt"][yr]["psi_min_deg"], 4), sig(ig["gsm_tilt"][yr]["psi_max_deg"], 4)] for yr in ("2025", "1900")}, "daily_range_mean_deg": {yr: sig(ig["gsm_tilt"][yr]["daily_range_mean_deg"], 3) for yr in ("2025", "1900")}, "series": weekly}) ep = ig["epochs"] dump("dipole_in_paper_terms.json", { "title": "Earth's dipole in the paper's units (D = 1 is its 3.11e-5 T reference) and its angle from the rotation axis", "credit": "gufm1 (Jackson, Jonkers & Walker 2000; GFZ pymagglobal copy, CC BY 4.0) for 1840; IGRF-14 for 1900-2026; " "computed by Fact-Checked Science.", "rows": [{"year": y, "model": m, "M_1e22_Am2": sig(ep[key]["M_1e22_Am2"], 4), "D": sig(ep[key]["D_paper"], 4), "axis_angle_deg": sig(ep[key]["angle_from_rotation_axis_deg"], 3)} for y, m, key in ((1840, "gufm1", "1840.0 (gufm1)"), (1900, "IGRF-14", "1900.0 (IGRF-14)"), (2025, "IGRF-14", "2025.0 (IGRF-14)"), (2026.88, "IGRF-14 + SV", "2026.88 (IGRF-14 + SV)"))], "year_D_equals_1": sig(ig["year_dipole_fell_to_paper_reference"], 5), "rough_reading_fig4_ratio_1840_to_2025": [sig(min(v for k2, v in ig["rough_reading_moment"]["ratios"]["1840->2025"].items() if k2.startswith("ratio")), 3), sig(max(v for k2, v in ig["rough_reading_moment"]["ratios"]["1840->2025"].items() if k2.startswith("ratio")), 3)], "rough_reading_note": "our power-law interpolation of Fig. 4; the paper has no run between D = 0.1 and 10 except D = 1"})