"""Per hour of given days: median over accepted targets of |corr step| from the previous measurement, in own noises, and the number of targets whose step exceeds 4 noises. usage: steps.py HOURS(e.g. 9-16) DAY1,DAY2...""" import sys, statistics as st sys.path.insert(0, 'tools/scripts') import data h1, h2 = map(int, sys.argv[1].split('-')) days = sys.argv[2].split(',') M = data.load('data/NIEDERHORN') tg = {s: ms for s, ms in M.items() if not data.is_reference(ms) and sum(m['corr_x'] is not None for m in ms) > 500} noise = {} ser = {} for s, ms in tg.items(): for c in ('corr_x', 'corr_y'): v = {m['t'].replace(second=0, microsecond=0): m[c] for m in ms} vv = [x for x in v.values() if x is not None] noise[s, c] = st.median(abs(vv[i + 1] - vv[i]) for i in range(len(vv) - 1)) ser[s, c] = v from datetime import timedelta for d in days: for h in range(h1, h2 + 1): t = data.parse_time(f'2026-10-{d}T{h:02d}:00') p = t - timedelta(hours=1) st_ = [] big = [] for (s, c), v in ser.items(): if v.get(t) is not None and v.get(p) is not None: z = (v[t] - v[p]) / noise[s, c] st_.append(abs(z)) if abs(z) > 4: big.append(f"{s.replace('PWD_','').replace('_C09','')}{c[-1]}{z:+.0f}") print(f'{d}T{h:02d}', f'med|step| {st.median(st_):.1f}' if st_ else '-', len(big), ' '.join(big[:12]))