Files
aimsight-labeling/auto/analyses/NORDEND_2026-08-23T0515_2026-09-04T0615/scripts/thermal_days.py
T

34 lines
1.9 KiB
Python

"""For each thermal label: per target, the hourly-median corr deviation from the night level (01-04 UTC of the label's
end day ... uses the night before the label start: the 3 h before start) at its extreme within the label; prints the
4 largest drops of corr_x and the largest moves of corr_y, and the pose excursions."""
import sys, json, statistics
sys.path.insert(0, "tools/scripts"); import data
from datetime import timedelta
labs = [json.loads(l) for l in open(sys.argv[1]) if '"Thermal displacement"' in l]
by = data.load("data/NORDEND"); cam = data.load_camera("data/NORDEND")
for ms in by.values():
for m in ms: m["t"] = m["t"].replace(second=0, microsecond=0)
tg = [s for s in by if not data.is_reference(by[s]) and s not in ("PR04", "CTR01")]
for l in labs:
S, E = data.parse_time(l["start"]), data.parse_time(l["end"])
out = {}
for c in ("corr_x", "corr_y"):
res = []
for s in tg:
night = [m[c] for m in by[s] if S - timedelta(hours=3) <= m["t"] <= S and m[c] is not None]
if not night: continue
lv = statistics.median(night)
hours = {}
for m in by[s]:
if S <= m["t"] <= E and m[c] is not None: hours.setdefault(m["t"].replace(minute=0), []).append(m[c])
hm = [(h, statistics.median(v) - lv) for h, v in hours.items() if len(v) >= 3]
if not hm: continue
h, d = max(hm, key=lambda x: abs(x[1]))
res.append((d, s, h))
res.sort(key=lambda x: -abs(x[0]))
out[c] = " ".join(f"{s}{d:+.3f}@{h:%d%H}" for d, s, h in res[:6])
pn = [p for p in cam if S <= p["t"] <= E and p["pan"] is not None]
rng = lambda k: max(p[k] for p in pn) - min(p[k] for p in pn)
print(l.get("id"), l["start"], l["end"], f"pan {rng('pan')*1000:.0f} tilt {rng('tilt')*1000:.0f} sc {rng('scale')*1e5:.0f}")
print(" x:", out["corr_x"]); print(" y:", out["corr_y"])