84 lines
3.9 KiB
Python
84 lines
3.9 KiB
Python
"""Per day and per target: what the daytime curves keep, outside the brief moments.
|
|||
|
|
|
||
|
|
For each day D (04:00-16:00 UTC), each target, each column:
|
||
|
|
- night level: median of accepted measurements from D-1 17:00 to D 04:00 (evening + night before),
|
||
|
|
- 'clean' instants: those where the compensation keeps all its references except R3 (5 or 6 retained), that no
|
||
|
|
label of --exclude covers (brief labels: passages, reference losses), accepted;
|
||
|
|
- wave: max |median-of-5 smoothed (clean) - night level| in noises, and its instant;
|
||
|
|
- agit: max |v - median of 4 clean neighbours each side| in noises (the fast part), and the count of clean points > 5;
|
||
|
|
- night agit, same on the night measurements, for comparison.
|
||
|
|
Usage: python3 days_dev.py EXCLUDE.jsonl [--maxdur 90]
|
||
|
|
"""
|
||
|
|
import json, sys, statistics
|
||
|
|
from datetime import timedelta
|
||
|
|
sys.path.insert(0, "tools/scripts")
|
||
|
|
import data
|
||
|
|
|
||
|
|
S, E = data.parse_time("2026-09-23T17:00Z"), data.parse_time("2026-10-06T19:45Z")
|
||
|
|
by = data.load("data/WILDSTRUBEL")
|
||
|
|
refs = [s for s, ms in by.items() if data.is_reference(ms)]
|
||
|
|
tg = [s for s, ms in by.items() if not data.is_reference(ms)]
|
||
|
|
maxdur = int(sys.argv[sys.argv.index("--maxdur") + 1]) if "--maxdur" in sys.argv else 90
|
||
|
|
excl = []
|
||
|
|
for l in open(sys.argv[1]):
|
||
|
|
L = json.loads(l)
|
||
|
|
a, b = data.parse_time(L["start"]), data.parse_time(L["end"])
|
||
|
|
if (b - a) <= timedelta(minutes=maxdur) or L.get("_force"):
|
||
|
|
excl.append((a, b))
|
||
|
|
# instants with refs other than R3 out
|
||
|
|
bad = set()
|
||
|
|
reft = {}
|
||
|
|
for r in refs:
|
||
|
|
for m in by[r]:
|
||
|
|
if S <= m["t"] <= E and r != "R3" and (data.rejected(m) or m.get("inlier") in (0, None)):
|
||
|
|
bad.add(m["t"])
|
||
|
|
def covered(t):
|
||
|
|
return any(a < t < b for a, b in excl)
|
||
|
|
noise = {}
|
||
|
|
W0, W1 = data.parse_time("2026-09-24T02:30Z"), E
|
||
|
|
for s in tg:
|
||
|
|
for c in ("corr_x", "corr_y"):
|
||
|
|
v = [m[c] for m in by[s] if W0 <= m["t"] <= W1 and m[c] is not None]
|
||
|
|
noise[s, c] = statistics.median(abs(b - a) for a, b in zip(v, v[1:]))
|
||
|
|
|
||
|
|
def agit(ser, nz):
|
||
|
|
out = []
|
||
|
|
for i, (t, v) in enumerate(ser):
|
||
|
|
nb = [x for _, x in ser[max(0, i - 4):i] + ser[i + 1:i + 5]]
|
||
|
|
if len(nb) >= 4:
|
||
|
|
out.append((abs(v - statistics.median(nb)) / nz, t))
|
||
|
|
return out
|
||
|
|
|
||
|
|
day = data.parse_time("2026-09-24T00:00Z")
|
||
|
|
while day < data.parse_time("2026-10-07T00:00Z"):
|
||
|
|
print(f"=== {day:%m-%d}")
|
||
|
|
for s in tg:
|
||
|
|
for c in ("corr_x", "corr_y"):
|
||
|
|
nz = noise[s, c]
|
||
|
|
ms = [m for m in by[s] if m[c] is not None]
|
||
|
|
night = [m[c] for m in ms if day - timedelta(hours=7) <= m["t"] < day + timedelta(hours=4)]
|
||
|
|
dser = [(m["t"], m[c]) for m in ms if day + timedelta(hours=4) <= m["t"] < day + timedelta(hours=16)
|
||
|
|
and m["t"] not in bad and not covered(m["t"])]
|
||
|
|
nser = [(m["t"], m[c]) for m in ms if day - timedelta(hours=7) <= m["t"] < day + timedelta(hours=4)
|
||
|
|
and m["t"] not in bad and not covered(m["t"])]
|
||
|
|
if len(night) < 3 or len(dser) < 5:
|
||
|
|
lvl = None
|
||
|
|
else:
|
||
|
|
lvl = statistics.median(night)
|
||
|
|
wave = ""
|
||
|
|
if lvl is not None:
|
||
|
|
sm = []
|
||
|
|
for i in range(len(dser)):
|
||
|
|
w = [v for _, v in dser[max(0, i - 2):i + 3]]
|
||
|
|
sm.append((statistics.median(w) - lvl, dser[i][0]))
|
||
|
|
mx = max(sm, key=lambda x: abs(x[0]))
|
||
|
|
over = [t for d, t in sm if abs(d) / nz > 5]
|
||
|
|
wave = f"wave {mx[0]/nz:+6.1f} @{mx[1]:%H:%M}" + (f" >5: {over[0]:%H:%M}-{over[-1]:%H:%M} ({len(over)})" if over else "")
|
||
|
|
ag = agit(dser, nz)
|
||
|
|
na = agit(nser, nz)
|
||
|
|
agd = max(ag, default=(0, None))
|
||
|
|
n5 = sum(1 for a, _ in ag if a > 5)
|
||
|
|
agn = max(na, default=(0, None))
|
||
|
|
print(f" {s:6s}{c[-1]} {wave:42s} agit day max {agd[0]:5.1f}"
|
||
|
|
f"{'@'+format(agd[1],'%H:%M') if agd[1] else '':7s} n>5 {n5:2d}/{len(ag):2d} night max {agn[0]:4.1f} ({len(na)})")
|
||
|
|
day += timedelta(days=1)
|