#!/usr/bin/env python3 """Our analysis: "the most intense in recent decades", index by index. Usage: python3 -I intensity_ranks.py GFZ_TXT WEAK_ICME_NUMBERS_JSON OUT_TXT Reuses /may-2024-weak-icme/'s numbers for Dst and SYM-H (may2024-numbers.json), and counts Kp 9 days and the highest daily Ap in GFZ's file. Standard library only. """ import datetime as dt import json import sys sys.stdout.reconfigure(encoding="utf-8", errors="replace") gfz_path, weak_path, out_path = sys.argv[1:4] days = [] for line in open(gfz_path, encoding="utf-8"): if line.startswith("#"): continue p = line.split() d = dt.date(int(p[0]), int(p[1]), int(p[2])) kp = [float(x) for x in p[7:15]] days.append((d, max(kp), int(p[23]), int(p[-1]))) lines = [] def say(s=""): lines.append(s) print(s) may = dt.date(2024, 5, 11) say("GFZ daily Ap, the 12 highest days since 1932:") for d, kpm, ap, flag in sorted(days, key=lambda x: -x[2])[:12]: say(f" {d} Ap {ap} max Kp {kpm:.2f} definitive flag {flag}") say("") say("Days with Kp = 9o (9.000) since 1932, the last 12, then the count:") k9 = [d for d, kpm, ap, f in days if kpm >= 8.999] for d in k9[-12:]: say(f" {d}") say(f" count {len(k9)}") k9m = [d for d, kpm, ap, f in days if kpm >= 8.66] say("Days with Kp at or above 9- (8.667), the last 8:") for d in k9m[-8:]: say(f" {d}") before = [x for x in days if x[0] < may] higher = [x for x in before if x[2] >= 271] say("") say(f"Last day before 11 May 2024 with Ap >= 271: {higher[-1][0]} (Ap {higher[-1][2]}); gap {may.year - higher[-1][0].year} calendar years") after = [x for x in days if x[0] > may and x[2] >= 150] say(f"Days after 11 May 2024 with Ap >= 150: {[(str(x[0]), x[2]) for x in after]}") say("") w = json.load(open(weak_path, encoding="utf-8")) say("From /may-2024-weak-icme/'s numbers:") say(f" Dst: May 2024 {w['dst']['may_2024_min']} nT; rank since 1957 {w['dst']['rank_since_1957']}; since 1981 {w['dst']['rank_since_1981']}") for s in w["dst"]["deeper_or_equal_storms"]: say(f" {s['time']} {s['dst']}") symh = sorted(w["symh_since_1981"], key=lambda r: r["symh_min"])[:6] say(" SYM-H since 1981, deepest six:") for r in symh: say(f" {r['symh_min_time']} {r['symh_min']:.0f} nT (Dst {r['dst_min']})") def years(a, b): return (b - a).days / 365.25 t = dt.date(2024, 5, 11) say("") say(f"Years from the last deeper storm: on Dst, 20 Nov 2003 to 11 May 2024 = {years(dt.date(2003, 11, 20), t):.1f}; on SYM-H, 14 Mar 1989 to 11 May 2024 = {years(dt.date(1989, 3, 14), t):.1f}") with open(out_path, "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(lines) + "\n")