#!/usr/bin/env python """Later addition, RULES.txt entry 15: chosen after seeing the results, a sensitivity check that decides nothing. If a truly stable lock at 145.99 d existed, how much would the highest peak between 130 and 190 d scatter from cycle to cycle? A lock of strength r is injected into all X1+GLE bursts with B''s jitter; the highest peak in X1+ flares is read in cycles 21 to 25 by each flare's original cycle, as in 07_split.py. python -I 20_scatter.py [--catalogues 1000] Writes ../out/scatter_by_cycle.json """ import argparse 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 import rr_place # noqa: E402 ap = argparse.ArgumentParser() ap.add_argument("--catalogues", type=int, default=1000) a = ap.parse_args() days, kinds, levels = rr.load_family("N") W = 7 cid = rr.clusters(days, W) first_idx = np.concatenate(([0], np.where(np.diff(cid) > 0)[0] + 1)) anchor = days[first_idx] last_idx = np.concatenate((first_idx[1:] - 1, [days.size - 1])) span = (days[last_idx] - days[first_idx]).astype(np.int64) last_day = int(days.max()) starts = np.array([rr.day_index(s) for _, s in rr.CYCLE_STARTS]) ev_cycle = np.searchsorted(starts, anchor[cid], side="right") - 1 fl = kinds == 0 k0, k1 = int(rr.NFFT / 190), int(rr.NFFT / 130) P = 145.99 def peaks(d): out = [] for c in range(2, 7): # cycles 21 to 25 z = rr.z_grid(d[fl & (ev_cycle == c)]) out.append(rr.NFFT / (k0 + int(np.argmax(z[k0 : k1 + 1])))) return np.array(out) obs = peaks(days) res = dict( note="Later addition, RULES.txt entry 15. Chosen after seeing the results: a sensitivity check.", observed_peaks=np.round(obs, 1).tolist(), observed_range=round(float(obs.max() - obs.min()), 1), observed_sd=round(float(obs.std(ddof=1)), 1), catalogues=a.catalogues, rows=[], ) rng = np.random.default_rng(20261112) for r in (0.0, 0.1, 0.2, 0.3, 0.4, 0.5): tab = np.zeros((a.catalogues, 5)) for i in range(a.catalogues): phase = rng.uniform(0, 2 * np.pi) sd = int(rng.integers(1, 2 ** 31 - 1)) sh, _ = rr_place.place_jitter(1, anchor.astype(np.int64), span, W, 0, last_day, sd, float(r), P, float(phase), 365) tab[i] = peaks(days + sh[0][cid]) rg = tab.max(axis=1) - tab.min(axis=1) sdv = tab.std(axis=1, ddof=1) row = dict(r=r, median_range=round(float(np.median(rg)), 1), share_range_at_least_observed=round(float((rg >= res["observed_range"]).mean()), 3), share_sd_at_least_observed=round(float((sdv >= res["observed_sd"]).mean()), 3)) res["rows"].append(row) print(row, flush=True) print(res["observed_peaks"], res["observed_range"], res["observed_sd"]) rr.save_json(os.path.join(rr.OUT, "scatter_by_cycle.json"), res)