#!/usr/bin/env python3 """Rough timing of the May 2024 solar proton event from GOES-16 SGPS level-2 5-minute averages (NOAA NCEI, public domain). Usage: python3 -I goes_protons.py DOWNLOADS_FOLDER [OUT_JSON] (needs numpy and netCDF4) Context only (RULES_storm_facts.txt, D11, which planned OMNI's GOES fluxes; OMNI carries none for May 2024, so this replaces it). We integrate the differential channels above 10 and 100 MeV, assuming flat spectra within each channel, add the >500 MeV integral channel, and average the two sensor units. This is NOT NOAA's operational integral-flux product and its values are not NOAA's; only the times are used on the page. """ import datetime as dt import glob import json import os import sys import netCDF4 import numpy as np ROOT = sys.argv[1] base = dt.datetime(2000, 1, 1, 12) T, F10, F100, F500 = [], [], [], [] for f in sorted(glob.glob(os.path.join(ROOT, "goes", "sci_sgps-l2-avg5m_g16_d2024051*_v3-0-2.nc"))): ds = netCDF4.Dataset(f) t = ds["time"][:]; flux = ds["AvgDiffProtonFlux"][:]; lo = ds["DiffProtonLowerEnergy"][:]; hi = ds["DiffProtonUpperEnergy"][:] i500 = ds["AvgIntProtonFlux"][:] for k in range(len(t)): v10, v100 = [], [] for u in range(2): s10 = s100 = 0.0 ok = not np.ma.is_masked(i500[k, u]) for c in range(13): fl = flux[k, u, c] if np.ma.is_masked(fl) or not np.isfinite(fl): ok = False; break L, H = float(lo[u, c]), float(hi[u, c]) if H > max(L, 1e4): s10 += float(fl) * (H - max(L, 1e4)) if H > max(L, 1e5): s100 += float(fl) * (H - max(L, 1e5)) if ok: v10.append(s10 + float(i500[k, u])); v100.append(s100 + float(i500[k, u])) T.append(base + dt.timedelta(seconds=float(t[k]))) F10.append(np.mean(v10) if v10 else np.nan); F100.append(np.mean(v100) if v100 else np.nan) F500.append(float(np.ma.mean(i500[k]))) F10, F100, F500 = map(np.array, (F10, F100, F500)) res = { "first_5min_ge_10_rough_gt10MeV": str(next(T[k] for k in range(len(T)) if F10[k] >= 10)), "max_rough_gt10MeV": [round(float(np.nanmax(F10)), 1), str(T[int(np.nanargmax(F10))])], "max_rough_gt100MeV": [round(float(np.nanmax(F100)), 2), str(T[int(np.nanargmax(F100))])], "max_gt500MeV_P11": [round(float(np.nanmax(F500)), 3), str(T[int(np.nanargmax(F500))])], "hourly_11May_00_06": [(T[k].strftime("%d %H:%M"), round(float(F100[k]), 2), round(float(F500[k]), 3)) for k in range(len(T)) if T[k].day == 11 and T[k].hour <= 6 and T[k].minute == 0], "note": "rough integrals; times only", } print(json.dumps(res, indent=1)) if len(sys.argv) > 2: with open(sys.argv[2], "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1)