#!/usr/bin/env python """The date a 629-day phase points to, on the page as a test to watch and not as a forecast of any solar event. For a period T the mean phase of a list is phi = arg(sum exp(2 pi i t / T)), t in days since 1955-12-31. Maxima fall at t = T (k + phi / 360 deg). We list the maximum nearest 2027 for the sets, at the theoretical period and at the published peak of the 109 events. RULES.txt entry 19 fixes one test from these numbers: X10+GLE, T = 629.29 d, its mean phase, V of rule 12 with bursts from that list at W = 7, events from 2026-11-04. V = r sqrt(2 N) on average for N bursts with mean resultant length r, so N = ((z_a + z_b) / r)^2 / 2. Run: python -I 15_test_to_watch.py Writes ../out/test_to_watch.json """ import datetime as dt import json import math import os import sys import numpy as np from scipy.stats import norm sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import rr_core as rr # noqa: E402 days, kinds, levels = rr.load_family("N") masks = rr.set_masks(kinds, levels) W = 7 sets = {n: m for n, m in zip(rr.SET_NAMES, masks)} sets["GLE alone"] = kinds == 1 sets["S-list alone"] = (kinds == 0) & (levels >= 10) sets["X10+GLE, bursts counted once"] = rr.decluster_mask(days, masks[0], W) sets["X6+GLE, bursts counted once"] = rr.decluster_mask(days, masks[1], W) sets["X1+GLE, bursts counted once"] = rr.decluster_mask(days, masks[4], W) target = rr.day_index(dt.date(2027, 9, 1)) to_date = lambda t: rr.EPOCH + dt.timedelta(days=int(round(t))) rows = {} for T in (629.29, 633.02): rows[str(T)] = {} for name, m in sets.items(): R = rr.resultant(days[m], 1 / T) phi = float(np.degrees(np.angle(R)) % 360) k = round(target / T - phi / 360) t = T * (k + phi / 360) rows[str(T)][name] = dict(N=int(m.sum()), phase_deg=round(phi, 1), k=int(k), t=round(t, 1), date=str(to_date(t)), r=round(float(abs(R) / m.sum()), 3)) all_d = [v["t"] for T in rows for v in rows[T].values()] # the one test we fix, entry 19 T = 629.29 R = rr.resultant(days[masks[0]], 1 / T) phi = float(np.degrees(np.angle(R)) % 360) today = rr.day_index(dt.date(2026, 11, 4)) k_next = math.ceil(today / T - phi / 360) t_next = T * (k_next + phi / 360) z_a, z_b = float(norm.isf(0.01)), float(norm.isf(0.2)) fixed = dict( set="X10+GLE: every GLE and every flare above X10", T=T, phase_deg=round(phi, 1), statistic="V = Re(R exp(-i phi)) / sqrt(sum |R_c|^2 / 2), bursts joined at gaps up to 7 days, one-sided", events_from=str(rr.EPOCH + dt.timedelta(days=today)), next_maximum_k=int(k_next), next_maximum_t=round(t_next, 1), next_maximum_date=str(to_date(t_next)), half_cycle_window_days=round(T / 4, 1), window_opens=str(to_date(t_next - T / 4)), window_closes=str(to_date(t_next + T / 4)), threshold_V=round(z_a, 2), bursts_even_odds={"r=0.25": round((z_a / 0.25) ** 2 / 2), "r=0.075": round((z_a / 0.075) ** 2 / 2)}, bursts_80_percent={"r=0.25": round(((z_a + z_b) / 0.25) ** 2 / 2), "r=0.075": round(((z_a + z_b) / 0.075) ** 2 / 2)}, ) fixed["X10_GLE_bursts_in_record"] = int(rr.clusters(days[masks[0]], W).max()) + 1 fixed["years_in_record"] = round((int(days.max()) - int(days.min())) / 365.25, 1) out = dict( rows=rows, earliest=str(to_date(min(all_d))), latest=str(to_date(max(all_d))), fixed_test=fixed, note="Not a forecast of a solar event. The grid bin near 633.02 d is 633.2 d; the published peak of the 109 events is 633.02 d.", ) rr.save_json(os.path.join(rr.OUT, "test_to_watch.json"), out) print(json.dumps(out, indent=0))