"""Deviation of each target, in its own noise (ranges.py full-range noise), from a reference level (median of chosen instants), over the instants of a label. Reads the per-instant tables work/corr_x.txt, work/corr_y.txt written by table.py.""" import re, statistics, sys D = sys.argv[1] ref = sys.argv[2].split(',') # reference instants 'MM-DD HH:MM' span = sys.argv[3].split('/') # 'MM-DD HH:MM/MM-DD HH:MM' noise = {} col = None for line in open(f"{D}/work/requal/full.txt"): if line.startswith('== corr_x'): col = 'corr_x' elif line.startswith('== corr_y'): col = 'corr_y' m = re.match(r'^(\S+)\s+52\s+\S+\s+(\S+)\s', line) if col and m and not m.group(1).startswith('REF'): noise[(col, m.group(1))] = float(m.group(2)) for c in ('corr_x', 'corr_y'): rows = [l.rstrip('\n') for l in open(f"{D}/work/{c}.txt")] head = rows[0].split()[1:13] data = {} for r in rows[1:]: p = r.split() if len(p) < 14: continue t = p[0] + ' ' + p[1] try: data[t] = [float(v) for v in p[2:14]] except ValueError: pass times = sorted(data) sel = [t for t in times if span[0] <= t <= span[1]] print(f"== {c} reference {ref}") print('time ' + ' '.join(f"{h:>7}" for h in head)) lev = [statistics.median(data[t][i] for t in ref if t in data) for i in range(12)] for t in sel: print(t + ' ' + ' '.join(f"{(data[t][i]-lev[i])/noise[(c, head[i])]:7.1f}" for i in range(12)))