"""tilt_sensitivity.py -- ADDED after the pre-registered run of igrf_tilt.py (logged as an addition, not a rule). Brackets the rough reading B of RULES_igrf_tilt.txt: Fig. 5 has no run between 0 and 30 degrees, so the time-averaged rate depends on the curve's unknown shape there. Two extremes: (step-up) any tilt above 0 has the 30-degree rate; (step-late) the 0-degree rate holds up to 30 degrees. Above 30 degrees, log-linear as before. python3 -I tilt_sensitivity.py (re-samples psi with igrf_tilt.py's functions, which it loads from the same folder) """ import json import math import os import sys igrf_p, gufm_p, dig_p, rules_p, out_dir = sys.argv[1:6] here = os.path.dirname(os.path.abspath(__file__)) sys.argv = ["igrf_tilt.py", igrf_p, gufm_p, dig_p, rules_p, out_dir] src = open(os.path.join(here, "igrf_tilt.py"), encoding="utf-8").read().replace("\nmain()\n", "\n") mod = {"__name__": "igrf_tilt_mod"} exec(compile(src, "igrf_tilt.py", "exec"), mod) f5 = mod["f5"] r0, r30 = f5[0][1], f5[1][1] def step_up(a): a = abs(a) return r0 if a == 0 else (r30 if a <= 30 else mod["rate_tilt"](a)) def step_late(a): a = abs(a) return r0 if a <= 30 else mod["rate_tilt"](a) res = {} for year in (2025, 1900): s = mod["year_samples"](year, mod["igrf_deg1"]) res[str(year)] = { "loglinear": sum(mod["rate_tilt"](p[1]) for p in s) / len(s), "step_up": sum(step_up(p[1]) for p in s) / len(s), "step_late": sum(step_late(p[1]) for p in s) / len(s)} ratios = {k: res["1900"][k] / res["2025"][k] for k in res["2025"]} out = {"means": res, "ratio_1900_over_2025": ratios} with open(os.path.join(out_dir, "tilt_sensitivity.json"), "w", encoding="utf-8", newline="\n") as f: json.dump(out, f, indent=1) print(json.dumps(out, indent=1))