"""For each label, the largest deviation (in noises) of a target on corr_x/corr_y among the ranges.py ranges strictly inside the label's bounds, for each ranges file given.""" import json, re, sys labels = [json.loads(l) for l in open(sys.argv[1])] files = sys.argv[2:] pat = re.compile(r'^(\S+)\s+(\S+Z)\s+(\S+Z)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+Z)\s+(\d+)') def load(f): out = []; col = None for line in open(f): if line.startswith('corr_x: ranges'): col = 'cx' elif line.startswith('corr_y: ranges'): col = 'cy' m = pat.match(line) if m and col: s, a, b, n, v, k, at, rej = m.groups() if s.startswith('PR') or s == 'CTR01': out.append((s, col, a, b, int(n), float(k), at)) return out R = {f: load(f) for f in files} for L in labels: print(L.get('id'), L['start'], L['end'], L['family']) for f in files: hits = [r for r in R[f] if r[6] > L['start'] and r[6] < L['end']] hits.sort(key=lambda r: -abs(r[5])) tag = f.split('ranges_')[-1].replace('.txt', '') top = ', '.join(f"{s} {c} {k:+.1f} @{at[5:16]} ({n})" for s, c, a, b, n, k, at in hits[:5]) print(f" {tag:10s} n={len(hits):3d} max={max([abs(r[5]) for r in hits], default=0):6.1f} {top}")