# Hosted copy (Fact-Checked Science, /amundsen-low-solar-cycle/): reads its inputs from the folder given as the # first argument, filled by fetch_inputs.py, and writes its outputs to /out/. Run it with Python 3.10+, # numpy and scipy, from the folder that holds this script, asl_lib.py, surr_lib.py and the RULES files. """06_shared_facts.py — descriptive numbers shared with page 2 and for context (RULES_shared.txt). Fact-Checked Science, 2026-11-15. Usage: py -3.12 -I 06_shared_facts.py""" import os, sys, json, hashlib here = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, here) import numpy as np from scipy import stats import asl_lib as A root = os.path.abspath(sys.argv[1]) if len(sys.argv) > 1 else os.getcwd() dl = root lines, res = [], {} def say(*a): s = " ".join(str(x) for x in a); print(s); lines.append(s) P_V3 = os.path.join(dl, "asli_calculation_latest.csv") P_V2 = os.path.join(dl, "ASL-index-Version2-Monthly-ERA-Interim_Hosking2016.txt") P_SN = os.path.join(dl, "SN_m_tot_V2.0.csv") for p in [os.path.join(here, "RULES_shared.txt"), P_V3, P_V2, P_SN]: say("input", os.path.basename(p), hashlib.sha256(open(p, "rb").read()).hexdigest()) v3, _ = A.load_v3(P_V3); v2 = A.load_v2(P_V2); sn, _ = A.load_silso(P_SN) def ols(t, y): r = stats.linregress(t, y) return r.slope, r.stderr, r for (y0, y1) in ((1959, 2025), (1979, 2025)): s = v3.restrict(A.ym(f"{y0}-01"), A.ym(f"{y1}-12")) ann = s.v.reshape(-1, 12).mean(axis=1) yrs = np.arange(y0, y1 + 1, dtype=float) b, se, r = ols(yrs, ann) resid = ann - (r.intercept + b * yrs) r1 = np.corrcoef(resid[:-1], resid[1:])[0, 1] n = len(ann); neff = n * (1 - r1) / (1 + r1) se_adj = se * np.sqrt((n - 2) / max(neff - 2, 1)) tcrit = stats.t.ppf(0.975, max(neff - 2, 1)) say(f"\n[D1 {y0}-{y1}] (a) annual means: {10*b:+.3f} hPa/decade (OLS SE {10*se:.3f}); lag-1 r of residuals {r1:+.2f}, n_eff {neff:.1f}; 95% interval with n_eff: {10*(b - tcrit*se_adj):+.3f} to {10*(b + tcrit*se_adj):+.3f}") tm = np.arange(len(s.v)) / 120.0 bm, sem, _ = ols(tm, s.v) clim = s.v.reshape(-1, 12).mean(axis=0) anom = s.v - np.tile(clim, len(s.v) // 12) ba, sea, _ = ols(tm, anom) say(f" (b) monthly values: {bm:+.3f} hPa/decade (SE {sem:.3f}); (c) monthly anomalies: {ba:+.3f} hPa/decade (SE {sea:.3f})") res[f"D1_{y0}_{y1}"] = dict(annual=10*b, annual_se=10*se, r1=r1, neff=neff, annual_ci=[10*(b - tcrit*se_adj), 10*(b + tcrit*se_adj)], monthly=bm, anomalies=ba) # D2 s = v3.restrict(A.ym("1979-01"), A.ym("2026-07")) nfull = (len(s.v) // 12) * 12 clim = s.v[:nfull].reshape(-1, 12).mean(axis=0) anom = s.v - np.array([clim[(s.start + i) % 12] for i in range(len(s.v))]) am = A.Monthly(s.start, anom) c12, c60 = A.cma(am, 12).v, A.cma(am, 60).v say(f"\n[D2] SD of monthly anomalies {np.nanstd(anom):.2f} hPa; of 12-month means {np.nanstd(c12):.2f}; of 60-month means {np.nanstd(c60):.2f}; range of 60-month means {np.nanmax(c60)-np.nanmin(c60):.2f} hPa") oos = json.load(open(os.path.join(root, "out", "03_oos.json"), encoding="utf-8")) b = oos["T1"]["fit"]["b"] sc = A.cma(sn.restrict(A.ym("1979-01"), A.ym("2026-10")), 60).v say(f" SSN 5-year CMA range 1979-2026: {np.nanmin(sc):.1f} to {np.nanmax(sc):.1f}; times the 1979-2016 slope {b:.4f} hPa per unit = {b*(np.nanmax(sc)-np.nanmin(sc)):.2f} hPa") res["D2"] = dict(sd_monthly=float(np.nanstd(anom)), sd_12=float(np.nanstd(c12)), sd_60=float(np.nanstd(c60)), range_60=float(np.nanmax(c60)-np.nanmin(c60)), ssn_cma_min=float(np.nanmin(sc)), ssn_cma_max=float(np.nanmax(sc)), slope=b, implied_range=float(b*(np.nanmax(sc)-np.nanmin(sc)))) # D3 a2 = v2.restrict(A.ym("1979-01"), A.ym("2018-03")).v; a3 = v3.restrict(A.ym("1979-01"), A.ym("2018-03")).v d = a3 - a2 bd, sed, _ = ols(np.arange(len(d)) / 120.0, d) say(f"\n[D3] v3 - v2, 1979-01..2018-03: mean {d.mean():+.3f} hPa, SD {d.std():.3f}, trend {bd:+.3f} hPa/decade (SE {sed:.3f})") res["D3"] = dict(mean=float(d.mean()), sd=float(d.std()), trend=bd) open(os.path.join(root, "out", "06_shared_facts.txt"), "w", encoding="utf-8", newline="\n").write("\n".join(lines) + "\n") json.dump(res, open(os.path.join(root, "out", "06_shared_facts.json"), "w", encoding="utf-8", newline="\n"), indent=1, default=float)