27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
"""Per label: largest deviation (in noises) of a target's corr_x/corr_y, from a ranges.py output.
|
|||
|
|
usage: requal_measure.py <ranges.txt> <labels.jsonl> [--inclusive]"""
|
||
|
|
import json, sys, re
|
||
|
|
REFS = {'8002','8004','8011','8012','8013','8014','8017','8019','92H'}
|
||
|
|
txt, lab = sys.argv[1], sys.argv[2]
|
||
|
|
incl = '--inclusive' in sys.argv
|
||
|
|
rng = [] # (col, sensor, start, end, n, val, noises, at, rej)
|
||
|
|
col = None
|
||
|
|
for line in open(txt):
|
||
|
|
m = re.match(r'^(corr_x|corr_y): ranges', line)
|
||
|
|
if m: col = m.group(1); continue
|
||
|
|
if line.startswith('=='): col = None; continue
|
||
|
|
if col:
|
||
|
|
p = line.split()
|
||
|
|
if len(p) >= 8 and re.match(r'\d{4}-', p[1]):
|
||
|
|
rng.append((col, p[0], p[1], p[2], int(p[3]), p[4], float(p[5]), p[6], p[7]))
|
||
|
|
for l in open(lab):
|
||
|
|
d = json.loads(l); s, e = d['start'], d['end']
|
||
|
|
hits = []
|
||
|
|
for r in rng:
|
||
|
|
if r[1] in REFS: continue
|
||
|
|
ok = (r[2] <= e and r[3] >= s) if incl else (r[2] < e and r[3] > s)
|
||
|
|
if ok: hits.append(r)
|
||
|
|
hits.sort(key=lambda r: -abs(r[6]))
|
||
|
|
top = ', '.join(f"{r[1]} {r[0][-1]} {r[6]:+.1f}@{r[7][11:16]}" for r in hits[:5])
|
||
|
|
mx = abs(hits[0][6]) if hits else 0
|
||
|
|
print(f"{d.get('id','?'):14s} {s[5:]} {e[5:]} {d['family'][:12]:12s} max={mx:6.1f} n={len(hits):3d} | {top}")
|