Files
aimsight-labeling/auto/analyses/FLORIDA_2026-10-11T0945_2026-10-22T0315/scripts/night.py
T

34 lines
1.8 KiB
Python
Raw Normal View History

"""Thermal labels: max deviation of Sellette 4/5 corr_x, corr_y (px, mm) from the night level (median 00:00-05:00 UTC
of the label's day, or of the next day when that night is missing), in noises (median |diff|, whole range)."""
import sys, json, statistics as st
from datetime import timedelta
sys.path.insert(0, "tools/scripts")
import data
D = sys.argv[1]
S = data.load("data/FLORIDA/")
T0, T1 = data.parse_time("2026-10-11T09:45Z"), data.parse_time("2026-10-22T03:15Z")
tg = ["Sellette 4", "Sellette 5"]
noise = {}
for s in tg:
ms = data.filter_window(S[s], T0, T1)
for c in ("corr_x", "corr_y"):
v = [m[c] for m in ms if m[c] is not None]; noise[s, c] = st.median(abs(a - b) for a, b in zip(v, v[1:]))
for line in open(D + "/work/requalify_input.jsonl"):
L = json.loads(line)
if not L["family"].startswith("Thermal"): continue
a, b = data.parse_time(L["start"]), data.parse_time(L["end"])
out = []
for s in tg:
for c in ("corr_x", "corr_y"):
for day in (0, 1):
d0 = a.replace(hour=0, minute=0) + timedelta(days=day)
nv = [m for m in data.filter_window(S[s], d0, d0 + timedelta(hours=5)) if m[c] is not None]
if len(nv) > 5: break
l = st.median(m[c] for m in nv); lmm = st.median(m[c + "_mm"] for m in nv)
iv = [m for m in data.filter_window(S[s], a, b) if m[c] is not None]
ks = [((m[c] - l) / noise[s, c], m) for m in iv]
# robust: 3rd largest |k| (a sustained cycle, not a single spike)
absk = sorted(((abs(k), k, m) for k, m in ks), key=lambda x: x[0])
k1, k3 = absk[-1], absk[-3]
out.append(f"{s} {c[-1]} max {k1[1]:+.1f}n@{data.iso(k1[2]['t'])[11:16]} ({k1[2][c+'_mm']-lmm:+.1f}mm) 3rd {k3[1]:+.1f}n [night d+{day}]")
print(L["id"], L["start"][5:16], L["end"][5:16], "|", "; ".join(out))