This commit is contained in:
maxime committed 2026-11-18 10:51:31 +01:00
1 parent 8e4ebca342
commit 58b630f2d5
112 files changed
+3172 -295

No files matched your search

@@ -0,0 +1,41 @@
"""Size of each Displacement label of CLARIDEN: per target, deviation of the 1 h rolling median of corr (px, mm)
from the level of the 6 h before the label, extreme within the label, net change at its end, in mm and in noises;
plus the month spread of each target (P5-P95 of its 1 h median) for scale."""
import sys, json, statistics as st
from datetime import timedelta
sys.path.insert(0, "tools/scripts")
import data
D = data.load("data/CLARIDEN")
S, E = data.parse_time("2026-09-25T00:00Z"), data.parse_time("2026-11-05T00:00Z")
tg = {s: [m for m in ms if S <= m["t"] <= E] for s, ms in D.items() if not data.is_reference(ms) and s not in ("P-300-B", "PR-283")}
def roll(ms, c):
out = []
for i, m in enumerate(ms):
w = [x[c] for x in ms[max(0, i-3):i+3] if x[c] is not None]
if m[c] is not None and len(w) >= 3: out.append((m["t"], st.median(w)))
return out
noise, R, spread = {}, {}, {}
for s, ms in tg.items():
for c in ("corr_x_mm", "corr_y_mm"):
v = [m[c] for m in ms if m[c] is not None]
if len(v) < 100: continue
noise[s, c] = st.median(abs(a-b) for a, b in zip(v, v[1:])) or 1e-9
R[s, c] = roll(ms, c)
h = sorted(x for _, x in R[s, c]); spread[s, c] = h[int(.95*len(h))] - h[int(.05*len(h))]
labels = [json.loads(l) for l in open("labeling/auto/CLARIDEN.jsonl")]
for L in labels:
if L["family"] != "Displacement": continue
a, b = data.parse_time(L["start"]), data.parse_time(L["end"])
rows = []
for (s, c), r in R.items():
pre = [x for t, x in r if a - timedelta(hours=6) <= t <= a]
ins = [(t, x) for t, x in r if a <= t <= b]
if len(pre) < 6 or len(ins) < 2: continue
lv = st.median(pre)
t0, ex = max(ins, key=lambda p: abs(p[1]-lv))
net = ins[-1][1] - lv
rows.append((abs(ex-lv)/noise[s, c], s, c[5], ex-lv, (ex-lv)/noise[s, c], net, spread[s, c]))
rows.sort(reverse=True)
print(f"{L['id']} {L['start']}->{L['end']} ({(b-a).total_seconds()/3600:.1f} h)")
for r in rows[:4]:
print(f" {r[1]:8s} {r[2]} ext {r[3]:+.3f} mm ({r[4]:+.1f} n) net {r[5]:+.3f} mm month spread {r[6]:.3f} mm")
@@ -0,0 +1,30 @@
"""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)
@@ -0,0 +1,25 @@
"""Native-step extreme of the short CLARIDEN Displacement labels: per target, the largest deviation of corr_x_mm /
corr_y_mm within the label from the median of the 6 h before, in mm and in the target's own noise (median step)."""
import sys, json, statistics as st
from datetime import timedelta
sys.path.insert(0, "tools/scripts")
import data
D = data.load("data/CLARIDEN")
ids = sys.argv[1].split(",")
for l in open("labeling/auto/CLARIDEN.jsonl"):
L = json.loads(l)
if L["id"] not in ids: continue
a, b = data.parse_time(L["start"]), data.parse_time(L["end"]); rows = []
for s, ms in D.items():
if data.is_reference(ms) or s in ("P-300-B", "PR-283"): continue
for c in ("corr_x_mm", "corr_y_mm"):
v = [m[c] for m in ms if m[c] is not None and a - timedelta(days=2) <= m["t"] <= b + timedelta(days=2)]
if len(v) < 50: continue
n = st.median(abs(x - y) for x, y in zip(v, v[1:])) or 1e-9
pre = [m[c] for m in ms if m[c] is not None and a - timedelta(hours=6) <= m["t"] < a]
ins = [m[c] for m in ms if m[c] is not None and a < m["t"] < b]
if len(pre) < 6 or not ins: continue
lv = st.median(pre); d = max(ins, key=lambda x: abs(x - lv)) - lv
rows.append((abs(d) / n, s, c[5], d))
rows.sort(reverse=True)
print(L["id"], L["start"], "->", L["end"], "; ".join(f"{s} {c} {d:+.2f} mm ({k:.1f} n)" for k, s, c, d in rows[:3]))