"""Per instant, median over the targets of (corr - level of a calm window) / noise, from the summary table.""" import sys, statistics as st f, a, b = sys.argv[1], *sys.argv[2].split('/') rows, hdr = [], None for line in open(f): p = line.split() if p and p[0] == 'start': hdr = p[1:]; continue if hdr and p and p[0].startswith('2026-'): rows.append((p[0], p[1:])) def val(s): try: return float(s.rstrip('*o')) except ValueError: return None tg = [i for i, s in enumerate(hdr) if not s.startswith('REF4') and s not in ('REFG43N', 'REFPOU22')] lev, noi = {}, {} for i in tg: s = [val(v[i]) for t, v in rows] noi[i] = st.median(abs(y - x) for x, y in zip(s, s[1:])) lev[i] = st.median(val(v[i]) for t, v in rows if a <= t[:16] + 'Z' <= b) for t, v in rows: d = [(val(v[i]) - lev[i]) / noi[i] for i in tg] print(t[:16], f"median {st.median(d):+5.1f} n>+2: {sum(x > 2 for x in d):2d} n<-2: {sum(x < -2 for x in d):2d}")