Files
aimsight-labeling/auto/analyses/NIEDERHORN_2026-10-01T0000_2026-10-11T0500/scripts/requalify.py
T

27 lines
1.4 KiB
Python
Raw Normal View History

"""For each label, the target ranges (k5) of ranges.py output that overlap its touched points."""
import json, re, sys
from datetime import datetime, timedelta
labels_f, *rfiles = sys.argv[1:]
P = lambda s: datetime.strptime(s, "%Y-%m-%dT%H:%MZ")
rx = re.compile(r"^(\S+?)\s*(\d{4}-\d\d-\d\dT\d\d:\d\dZ)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)")
for rf in rfiles:
col = None; R = []
for line in open(rf):
m = re.match(r"^(corr_[xy]): ranges", line)
if m: col = m.group(1); continue
if line.startswith("==") : col = None
m = rx.match(line)
if col and m:
s, a, b, n, v, k, at = m.groups()
if "REF" in s: continue
R.append((s, col, P(a), P(b), int(n), float(k), at))
print("#####", rf)
for l in map(json.loads, open(labels_f)):
a, b = P(l["start"]), P(l["end"])
# touched: strictly inside, plus start if label is 1h long (gap edge)
lo = a if b - a <= timedelta(hours=1) else a + timedelta(hours=1)
hi = b - timedelta(hours=1) if b - a > timedelta(hours=1) else a
hits = [r for r in R if r[2] <= hi and r[3] >= lo]
best = sorted(hits, key=lambda r: -abs(r[5]))[:6]
print(f"{l['id']:15s} {l['start']}→{l['end'][11:]} {l['family'][:12]:12s} n={len(hits):3d} " +
"; ".join(f"{s[-11:] if s.startswith('PWD') else s} {c[-1]} {k:+.1f}@{at[8:13]}" for s,c,_,_,_,k,at in best))