Files
aimsight-labeling/auto/analyses/WILDSTRUBEL_2026-10-06T1945_2026-10-20T0000/scripts/requal.py
T
maximeandClaude Opus 5.5 ddb17c2189 auto: labels requalified under the 5-noise rules (only what stands out from the noise): 32 analyses refined, the 6 paused periods verified, the long labels requalified with the fixes the period analysts found; 1153 -> 961 labels
- 32 analyses: each label kept, rewritten or removed by its analyst (section Requalification of the report; mm magnitudes where the targets have them)
- SNCF01 x3, WILDSTRUBEL 2026-09-01 -> 2026-10-06 x3: verified from their existing labels under the new rules
- long labels (no analysis): auto/analyses/long-labels/<STATION>/; NORDEND-169 and -195 run to 07/11, so NORDEND-283 and -284 (their continuation) are removed
- reading-rules.md, stations.md: the citations of removed or rewritten labels point to their successor, or to [expert]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 23:58:00 +01:00

54 lines
2.6 KiB
Python

"""Requalification: per label, per target, the largest deviation of corr_x / corr_y (and in mm) inside the label,
in the target's own batch noise (median |consecutive difference| over the measured batch 07/10 05:00 -> 09/10 12:30),
against two levels: the batch median, and (for the day labels) a reference level given per label.
Also the deviation of the hourly median (thermal / slow part) and the instants excluded (passages labelled apart)."""
import json, statistics, sys
from datetime import datetime, timezone
sys.path.insert(0, "tools/scripts")
from data import load, rejected, parse_time
TG = ["PA2_2", "PA3_2", "PA_9", "PB1_2", "PB2_2", "PB4", "PB_5"]
by = load("data/WILDSTRUBEL")
B0, B1 = parse_time("2026-10-07T05:00Z"), parse_time("2026-10-09T12:30Z")
def series(s, col, a, b):
return [(m["t"], m[col]) for m in by[s] if a <= m["t"] <= b and m.get(col) is not None and not rejected(m)]
def noise(vs):
d = [abs(y - x) for x, y in zip(vs, vs[1:])]
return statistics.median(d) if d else 0
BN = {(s, c): noise([v for _, v in series(s, c, B0, B1)]) for s in TG for c in ("corr_x", "corr_y")}
BL = {(s, c): statistics.median([v for _, v in series(s, c, B0, B1)]) for s in TG for c in ("corr_x", "corr_y")}
# label id -> (start, end, reference level window or None, instants excluded because labelled apart)
L = json.loads(sys.argv[1])
for lid, (a, b, ref, excl) in L.items():
a, b = parse_time(a), parse_time(b)
out = []
for s in TG:
for c in ("corr_x", "corr_y"):
n = BN[(s, c)]
lvl = BL[(s, c)]
if ref:
r = [v for _, v in series(s, c, parse_time(ref[0]), parse_time(ref[1]))]
lvl = statistics.median(r) if r else None
pts = [(t, v) for t, v in series(s, c, a, b) if t.strftime("%Y-%m-%dT%H:%MZ") not in excl]
if not pts or lvl is None:
continue
t, v = max(pts, key=lambda p: abs(p[1] - lvl))
# hourly medians: the slow part
hours = {}
for tt, vv in pts:
hours.setdefault(tt.replace(minute=0), []).append(vv)
hm = max((statistics.median(x) - lvl for x in hours.values()), key=abs)
mm = by[s][0].get("corr_x_mm")
out.append((abs(v - lvl) / n, s, c, v - lvl, t.strftime("%d %H:%M"), hm / n))
out.sort(reverse=True)
print(f"== {lid} {a:%d %H:%M} -> {b:%d %H:%M} level={'batch median' if not ref else ref} excluded={excl}")
for d, s, c, dv, t, hm in out[:5]:
print(f" {s:6} {c} max {dv:+.3f} px = {d:5.1f} noises at {t}; largest hourly median {hm:+5.1f} noises")