#!/usr/bin/env python """Merge the event lists into the data sets of the re-run. No periods are tested here. Families (see RULES.txt): R the paper's own recipe: rudimirz list (peak date), SWPC flares after that file ends, S-list, GLEs N NOAA's fuller record: NCEI reports and SWPC reports, S-list, GLEs (the primary family) L as N, with GOES-R flares multiplied by 0.7 to put them on the old scale before thresholding Writes ../out/sets_.npz and ../out/sets_.csv. Run: python -I 02_build_sets.py """ import datetime as dt import os import sys import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import rr_core as rr # noqa: E402 CUTOFF = dt.date(2026, 7, 4) gle = [(int(r["gle"]), dt.date.fromisoformat(r["date"]), int(r["day_since_1955_12_31"])) for r in rr.read_csv(os.path.join(rr.OUT, "events_gle.csv"))] sfl = [(dt.date.fromisoformat(r["date"]), int(r["day_since_1955_12_31"])) for r in rr.read_csv(os.path.join(rr.OUT, "events_sflares.csv"))] noaa = [] for r in rr.read_csv(os.path.join(rr.OUT, "events_noaa_x.csv")): noaa.append( dict( date=dt.date.fromisoformat(r["date"]), mag=float(r["reported_class_X"]), g16=r["instrument"] in ("G16", "G17", "G18", "G19"), ) ) families = [("N", noaa, None), ("L", noaa, 0.7)] rud_path = os.path.join(rr.OUT, "events_rudimirz_x.csv") if os.path.exists(rud_path): # not hosted with the page: 01_build_event_lists.py makes it from rudimirz's own file rud = [dict(date=dt.date.fromisoformat(r["date"]), mag=float(r["class_X"]), g16=False) for r in rr.read_csv(rud_path)] rud = rud + [r for r in noaa if r["date"] > dt.date(2026, 5, 3)] families.insert(0, ("R", rud, None)) else: print("events_rudimirz_x.csv not found: family R skipped") for fam, flares, scale in families: days, kinds, levels, added = rr.master_events(flares, sfl, gle, CUTOFF, scale=scale) masks = rr.set_masks(kinds, levels) print(fam, "events", days.size, "first day", days.min(), "last day", days.max(), rr.EPOCH + dt.timedelta(days=int(days.max()))) print(" S-flares added (no catalogue flare of X5+ within a day):", added) print(" sets:", {n: int(m.sum()) for n, m in zip(rr.SET_NAMES, masks)}, " flares only:", {n: int(m.sum()) - 72 for n, m in zip(rr.SET_NAMES, masks)}) for w in (1, 3, 7, 14, 27): print(f" declustered W={w}:", [int(rr.decluster_mask(days, m, w).sum()) for m in masks]) # same-day GLE-flare pairs counted twice gd = set(days[kinds == 1].tolist()) print(" flares in X10+GLE on a GLE day:", int(sum(d in gd for d in days[(kinds == 0) & (levels >= 10)])), " in X1+GLE:", int(sum(d in gd for d in days[(kinds == 0)]))) np.savez(os.path.join(rr.OUT, f"sets_{fam}.npz"), days=days, kinds=kinds, levels=levels) with open(os.path.join(rr.OUT, f"sets_{fam}.csv"), "w", newline="\n", encoding="utf-8") as f: f.write("day_since_1955_12_31,date,kind,level\n") for d, k, l in zip(days, kinds, levels): f.write(f"{d},{rr.EPOCH + dt.timedelta(days=int(d))},{'GLE' if k == 1 else 'flare'},{l if k == 0 else ''}\n")