Files
aimsight-labeling/auto/analyses/JUNGFRAU_2026-10-21T1030_2026-11-01T0000/scripts/turn.py
T

31 lines
1.7 KiB
Python

"""Median corr_x, corr_y of the targets (own level removed), smoothed over 5 measurements, with the housing temperature,
the tilt and the pan, one line per measurement (every N): to read the turning points of the thermal cycles.
usage: python3 turn.py START END [every]"""
import sys, pickle, os, statistics
sys.path.insert(0, "tools/scripts")
import data
S, P = pickle.load(open(os.path.join(os.path.dirname(__file__), "..", "work", "cache.pkl"), "rb"))
T = {t.replace(minute=0, second=0, microsecond=0): v for t, v in data.load_temperature("data/JUNGFRAU")}
start, end = data.parse_time(sys.argv[1]), data.parse_time(sys.argv[2])
every = int(sys.argv[3]) if len(sys.argv) > 3 else 1
targets = [s for s in S if not s.startswith("REF") and s != "PM_G"]
lvl = {(s, c): statistics.median([m[c] for m in S[s] if m[c] is not None]) for s in targets for c in ("corr_x", "corr_y")}
times = sorted({m["t"] for s in targets for m in S[s]})
med = {}
for t in times:
for c in ("corr_x", "corr_y"):
v = [m[c] - lvl[(s, c)] for s in targets for m in [next((m for m in S[s] if m["t"] == t), None)] if m and m[c] is not None]
med[(t, c)] = statistics.median(v) if v else None
sel = [t for t in times if start <= t <= end]
for i, t in enumerate(sel):
if i % every:
continue
j = times.index(t)
w = [times[k] for k in range(max(0, j - 2), min(len(times), j + 3))]
sm = {c: statistics.median([med[(u, c)] for u in w if med[(u, c)] is not None]) for c in ("corr_x", "corr_y")}
p = P.get(t)
temp = T.get(t.replace(minute=0))
print(t.strftime("%d %H:%M"), f"cx {sm['corr_x']:+.3f} cy {sm['corr_y']:+.3f}",
f"T {temp:5.1f}" if temp else "T - ", f"tilt {p['tilt']:.4f} pan {p['pan']:.4f}" if p else "no pose")