"""Post hoc: readings of the thesis's By-extrema rule (p. 70-71). Needs numpy. usage: py -3.12 -I extrema_variants.py """ import datetime as dt, os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import numpy as np import common as C dates, gse, gsm = C.read_omni_daily(os.path.join(sys.argv[1], 'omni', 'omni_01_av.dat'), 2010, 2023) for name, ser in (('GSM', gsm), ('GSE', gse)): b = ser; n = len(b) for mode in ('tie', 'strict', 'absval', 'absval_strict'): mx, mn = [], [] for t in range(n): v = b[t] if np.isnan(v) or abs(v) < 3: continue seg = b[max(0, t-3):min(n, t+4)] others = np.delete(seg, t - max(0, t-3)) others = others[~np.isnan(others)] if mode == 'tie': ok = (v >= 3 and v >= others.max()) or (v <= -3 and v <= others.min()) elif mode == 'strict': ok = (v >= 3 and v > others.max()) or (v <= -3 and v < others.min()) elif mode == 'absval': ok = abs(v) >= np.abs(others).max() else: ok = abs(v) > np.abs(others).max() if ok: (mx if v > 0 else mn).append(t) g = np.diff(sorted(mx + mn)); vals, cnt = np.unique(g, return_counts=True) print(name, mode, 'max', len(mx), 'min', len(mn), 'gap mean %.2f se %.2f sd %.2f mode %d' % (g.mean(), g.std(ddof=1)/np.sqrt(len(g)), g.std(ddof=1), vals[np.argmax(cnt)])) print('thesis GSM: min 273 max 252, gap 9.7+/-0.3 sd 6.3 mode 9; GSE: min 291 max 264, gap 9.2+/-0.4 sd 5.6 mode 8') b = gse for incl in (True,): v = b[~np.isnan(b)] print('2010-2023 incl: <=-3 %.2f%% >=3 %.2f%%' % (100*np.mean(v <= -3), 100*np.mean(v >= 3))) d2, g2, _ = C.read_omni_daily(os.path.join(sys.argv[1], 'omni', 'omni_01_av.dat'), 2000, 2007) v = g2[~np.isnan(g2)] print('2000-2007 incl: <=-3 %.2f%% >=3 %.2f%%; strict <-3 %.2f%% >3 %.2f%%' % (100*np.mean(v <= -3), 100*np.mean(v >= 3), 100*np.mean(v < -3), 100*np.mean(v > 3)))