"""Hourly medians of corr_x_mm / corr_y_mm of the targets that carry the CLARIDEN Displacement labels, over October, with every Displacement label shaded and named, and the camera tilt and housing temperature.""" import sys, json, statistics as st from collections import defaultdict sys.path.insert(0, "tools/scripts") import data import matplotlib; matplotlib.use("Agg"); import matplotlib.pyplot as plt D = data.load("data/CLARIDEN") S, E = data.parse_time("2026-10-01T00:00Z"), data.parse_time("2026-11-01T00:00Z") series = [("D-302-B","corr_y_mm"),("D-301-C","corr_x_mm"),("D-303-B","corr_y_mm"),("D-303-C","corr_y_mm"), ("D-304-C","corr_y_mm"),("D-306-B","corr_y_mm"),("D-304-B","corr_y_mm"),("P-301-B","corr_y_mm"),("D-304-A","corr_y_mm")] def hourly(pairs): h = defaultdict(list) for t, v in pairs: if v is not None and S <= t <= E: h[t.replace(minute=0, second=0)].append(v) k = sorted(h); return k, [st.median(h[x]) for x in k] cam = data.load_camera("data/CLARIDEN"); tmp = data.load_temperature("data/CLARIDEN") fig, ax = plt.subplots(len(series)+2, 1, figsize=(18, 2.0*(len(series)+2)), sharex=True) labels = [json.loads(l) for l in open("labeling/auto/CLARIDEN.jsonl")] for i, (s, c) in enumerate(series): t, v = hourly((m["t"], m[c]) for m in D[s]); ax[i].plot(t, v, lw=.8); ax[i].set_ylabel(f"{s}\n{c[5]} mm", fontsize=8) t, v = hourly((p["t"], p.get("tilt")) for p in cam); ax[-2].plot(t, v, "k", lw=.8); ax[-2].set_ylabel("tilt") t, v = hourly(tmp); ax[-1].plot(t, v, "r", lw=.8); ax[-1].set_ylabel("housing °C") for L in labels: if L["family"] not in ("Displacement", "No data"): continue a, b = data.parse_time(L["start"]), data.parse_time(L["end"]) for x in ax: x.axvspan(a, b, color="orange" if L["family"] == "Displacement" else "grey", alpha=.2, lw=0) if L["family"] == "Displacement": ax[0].text(a, ax[0].get_ylim()[1], L["id"].split("-")[1], fontsize=7, va="top") for x in ax: x.grid(alpha=.3) plt.tight_layout(); out = sys.argv[1]; plt.savefig(out, dpi=80); print(out)