#!/usr/bin/env python3 """ADDED AFTER THE FIRST RUN: the note's "Sphere alternate (min +22-78 nT)" over different spans. Usage: py -3.12 -I sphere_range.py """ import csv import json import os import sys V = sys.argv[1] R = os.path.join(V, "results") def load(n): with open(os.path.join(R, "yearly_%s.csv" % n), encoding="utf-8") as f: return {round(float(r["t"])): r for r in csv.DictReader(f)} g, i = load("gufm1"), load("igrf14") s = load("gufm1_sphere") s.update(load("gufm1_sphere_1590_1799")) si = load("igrf14_sphere") d = {} for y in range(1590, 1900): d[y] = float(s[y]["min_F"]) - float(g[y]["min_F"]) for y in range(1900, 2031): d[y] = float(si[y]["min_F"]) - float(i[y]["min_F"]) out = {} for a, b in ((1590, 2030), (1800, 2030), (1590, 1799), (1800, 1899), (1900, 2030)): v = [d[y] for y in range(a, b + 1)] ymax = max(range(a, b + 1), key=lambda y: d[y]) out["%d-%d" % (a, b)] = {"min": min(v), "max": max(v), "year_of_max": ymax, "lat_of_min_at_max": float((s if ymax < 1900 else i)[ymax]["min_lat"]) if ymax < 1900 else float(i[ymax]["min_lat"])} json.dump(out, open(os.path.join(R, "sphere_range.json"), "w", newline="\n"), indent=1) print(json.dumps(out, indent=1))