Files
aimsight-labeling/auto/analyses/MICHIGAN_2026-10-03T0000_2026-10-12T1600/scripts/pertarget.py
T

19 lines
992 B
Python

"""Per sensor, deviation (in own noise) from the median of a calm window, at chosen instants; from a summary table."""
import sys, statistics as st
f, (a, b), inst = sys.argv[1], sys.argv[2].split('/'), sys.argv[3].split(',')
rows, hdr = [], None
for line in open(f):
p = line.split()
if p and p[0] == 'start': hdr = p[1:]; continue
if hdr and p and p[0].startswith('2026-'): rows.append((p[0][:16], p[1:]))
def val(s):
try: return float(s.rstrip('*o'))
except ValueError: return None
print('sensor ' + ' '.join(f"{t[5:]:>12s}" for t in inst))
for i, s in enumerate(hdr):
ser = [val(v[i]) for t, v in rows if val(v[i]) is not None]
noise = st.median(abs(y - x) for x, y in zip(ser, ser[1:])) or 1e-9
lev = st.median(val(v[i]) for t, v in rows if a <= t <= b and val(v[i]) is not None)
d = dict((t, val(v[i])) for t, v in rows)
print(f"{s:11s}" + ' '.join(f"{((d[t] - lev) / noise) if d.get(t) is not None else float('nan'):+12.1f}" for t in inst))