"""EXPLORATORY (added after stations.py's run): a pooled companion to the station test, not pre-registered. Marshall's station-based zonal mean sea-level pressure at 65 S (six stations; BAS file l65.1957.2007.txt) against R1's own zonal-mean sea-level pressure on the 65 S row (slp.mon.mean.nc, 2.5 deg). Same for 40 S. (Corrected after reading Marshall 2003 in full: he compared R1 at the six sites, not R1's whole circle, and found that in R1 the sites average 3.7 hPa above the circle at 65 S and 1.6 hPa below it at 40 S, with no significant trend in that difference (p. 4138). So compare trends; the levels differ by design.) Usage: py -3.12 -I l65_check.py """ import json import os import sys import cftime import netCDF4 import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import ppt_lib as L # noqa: E402 def read_marshall(path): yy, mm, vv = [], [], [] for line in open(path, encoding="utf-8"): f = line.split() if f and f[0].isdigit() and len(f[0]) == 4: for m, tok in enumerate(f[1:], start=1): yy.append(int(f[0])) mm.append(m) vv.append(float(tok)) return np.array(yy), np.array(mm), np.array(vv) downloads, out = sys.argv[1], sys.argv[2] with netCDF4.Dataset(os.path.join(downloads, "psl-r1", "slp.mon.mean.nc")) as ds: ds.set_auto_mask(False) t = ds.variables["time"] dd = cftime.num2date(t[:], t.units, calendar=getattr(t, "calendar", "standard")) ry = np.array([d.year for d in dd]) rm = np.array([d.month for d in dd]) lat = ds.variables["lat"][:] slp = np.asarray(ds.variables["slp"][:], dtype=float) res = {} for band, fn in ((-65.0, "l65.1957.2007.txt"), (-40.0, "l40.1957.2007.txt")): j = int(np.argmin(np.abs(lat - band))) zr = slp[:, j, :].mean(axis=1) ya, ra = L.annual_means(ry, rm, zr) my, mm, mv = read_marshall(os.path.join(downloads, "bas-sam", fn)) yb, sb = L.annual_means(my, mm, mv) common = np.intersect1d(ya, yb) r = np.array([ra[list(ya).index(y)] for y in common]) s = np.array([sb[list(yb).index(y)] for y in common]) d = (r - r.mean()) - (s - s.mean()) key = f"{int(abs(band))}S" res[key] = {} for name, (a, b) in (("1957-2025", (1957, 2025)), ("1957-1978", (1957, 1978)), ("1979-2025", (1979, 2025))): sel = (common >= a) & (common <= b) res[key][name] = {"n": int(sel.sum()), "stations": L.trend(common[sel], s[sel]), "r1": L.trend(common[sel], r[sel]), "difference_r1_minus_stations": L.trend(common[sel], d[sel]), "mean_difference_hPa": float((r[sel] - s[sel]).mean()), "corr": float(np.corrcoef(r[sel], s[sel])[0, 1])} x = res[key][name] print(key, name, "n", x["n"], "stations", round(x["stations"]["slope"], 3), [round(x["stations"]["lo"], 3), round(x["stations"]["hi"], 3)], "R1", round(x["r1"]["slope"], 3), [round(x["r1"]["lo"], 3), round(x["r1"]["hi"], 3)], "R1-stations", round(x["difference_r1_minus_stations"]["slope"], 3), [round(x["difference_r1_minus_stations"]["lo"], 3), round(x["difference_r1_minus_stations"]["hi"], 3)], "mean offset", round(x["mean_difference_hPa"], 2), "r", round(x["corr"], 2)) # mean offset before and after 1979 pre, post = common <= 1978, common >= 1979 res[key]["offset_pre1979_minus_post1979_hPa"] = float((r - s)[pre].mean() - (r - s)[post].mean()) print(key, "R1 - stations, mean offset pre-1979 minus post-1979:", round(res[key]["offset_pre1979_minus_post1979_hPa"], 2), "hPa") with open(os.path.join(out, "l65_check.json"), "w", newline="\n") as fh: json.dump(res, fh, indent=1)