44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""Requalification: for each input label, the targets whose ranges.py ranges (k 5) intersect the label,
|
|||
|
|
in each mode (static, rolling ±3, ±6, ±12 measurements), with the largest |deviation| in noises.
|
||
|
|
Usage: python3 requalify.py <analysis folder>"""
|
||
|
|
import json, re, sys
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
D = sys.argv[1]
|
||
|
|
P = lambda s: datetime.strptime(s, "%Y-%m-%dT%H:%MZ")
|
||
|
|
LINE = 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+)\s+(\d+)")
|
||
|
|
|
||
|
|
|
||
|
|
def parse(path):
|
||
|
|
out, col = [], None
|
||
|
|
for l in open(path):
|
||
|
|
if ": ranges more than" in l:
|
||
|
|
col = l.split(":")[0]
|
||
|
|
continue
|
||
|
|
if l.startswith("Instants"):
|
||
|
|
col = None
|
||
|
|
m = LINE.match(l.strip()) if col else None
|
||
|
|
if m:
|
||
|
|
s, a, b, n, d, k, at, rej = m.groups()
|
||
|
|
out.append((col, s.strip(), P(a), P(b), float(k), P(at), int(n), int(rej)))
|
||
|
|
return out
|
||
|
|
|
||
|
|
|
||
|
|
modes = {m: parse(f"{D}/work/requal/ranges_{m}.txt") for m in ("static", "r3", "r6", "r12")}
|
||
|
|
for l in open(f"{D}/work/requalify_input.jsonl"):
|
||
|
|
lab = json.loads(l)
|
||
|
|
a, b = P(lab["start"]), P(lab["end"])
|
||
|
|
print(f"\n{lab['id']} {lab['start']} -> {lab['end']} {lab['family']}")
|
||
|
|
for m, rs in modes.items():
|
||
|
|
hits = {}
|
||
|
|
for col, s, ra, rb, k, at, n, rej in rs:
|
||
|
|
if "REF" in s:
|
||
|
|
continue
|
||
|
|
# the extreme must fall strictly inside the label (between its bounds, bounds excluded)
|
||
|
|
if a < at < b:
|
||
|
|
key = (s, col)
|
||
|
|
if key not in hits or abs(k) > abs(hits[key][0]):
|
||
|
|
hits[key] = (k, at, n)
|
||
|
|
top = sorted(hits.items(), key=lambda kv: -abs(kv[1][0]))[:6]
|
||
|
|
txt = ", ".join(f"{s.replace('PWD_', '').replace('_C09', '')} {c[-1]} {v[0]:+.1f}@{v[1]:%dT%H}({v[2]})" for (s, c), v in top)
|
||
|
|
print(f" {m:6} n={len(hits):2} {txt}")
|