Files
aimsight-labeling/auto/analyses/WILDSTRUBEL_2026-09-24T0230_2026-10-06T1945/scripts/clipplot.py
T

42 lines
1.9 KiB
Python
Raw Normal View History

"""corr_x, corr_y of chosen targets, one panel per target and column, y clipped to the 1st-99th percentile.
Usage: .venv/bin/python clipplot.py OUT.png START END SENSORS [--mm] [--labels F]
--labels: grey band per label (family colour), only those longer than 2 h.
"""
import sys, json, statistics
sys.path.insert(0, "tools/scripts")
import data
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
out, a, b, sens = sys.argv[1], data.parse_time(sys.argv[2]), data.parse_time(sys.argv[3]), sys.argv[4].split(",")
mm = "--mm" in sys.argv
by = data.load("data/WILDSTRUBEL")
cols = ("corr_x_mm", "corr_y_mm") if mm else ("corr_x", "corr_y")
fig, axs = plt.subplots(len(sens), 2, figsize=(18, 2.2 * len(sens)), sharex=True, squeeze=False)
labels = []
if "--labels" in sys.argv:
labels = [json.loads(l) for l in open(sys.argv[sys.argv.index("--labels") + 1])]
colors = {"Visibility": "tab:blue", "Obstruction": "tab:orange", "Thermal displacement": "tab:red",
"Displacement": "tab:green", "Target issue": "tab:purple", "No data": "grey"}
for i, s in enumerate(sens):
for j, c in enumerate(cols):
ax = axs[i][j]
ms = [m for m in by[s] if a <= m["t"] <= b and m[c] is not None]
if not ms:
continue
v = sorted(m[c] for m in ms)
lo, hi = v[int(0.01 * len(v))], v[int(0.99 * len(v)) - 1]
pad = 0.15 * (hi - lo)
ax.plot([m["t"] for m in ms], [m[c] for m in ms], ".-", ms=2, lw=0.5)
ax.set_ylim(lo - pad, hi + pad)
ax.set_ylabel(f"{s} {c}", fontsize=8)
ax.grid(alpha=0.3)
for L in labels:
la, lb = data.parse_time(L["start"]), data.parse_time(L["end"])
if (lb - la).total_seconds() > 7200 and lb > a and la < b:
ax.axvspan(max(la, a), min(lb, b), color=colors.get(L["family"], "k"), alpha=0.12)
fig.tight_layout()
fig.savefig(out, dpi=80)
print(out)