Files
aimsight-labeling/auto/revue-croisee/2026-11-04/thermal-displacement/outils/nuits.py
T
maximeandClaude Opus 5.5 14ad6ea3f9 Auto labels reviewed per station and cross-reviewed; all labeling knowledge in labeling/ (D-130)
- Every station's auto labels reviewed by an analyst (/review-auto-labels), then a
  cross-review per family across all stations (new skill /cross-review-labels),
  a finishing pass, and descriptions rewritten in words (no numeric values).
- The three never-labeled ranges (WILDSTRUBEL 07/09-01/10, NORDEND 16/08-01/10)
  labeled and reviewed: 991 auto labels on 11 stations, labeling/controle.py at 0 errors.
- Labeling knowledge gathered in labeling/: regles-d-etiquetage.md (new), familles.md
  (settled boundaries), connaissances/ (notes moved from docs/, links updated),
  the label map rebuilt from reviewed labels, events and cases; events tied to their
  stations (PS_DES_COUDRES is JUNGFRAU). The labeler and reviewers read only labeling/.
- labels-map reads auto labels and events; decision D-130; living plan points 73-75.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 08:21:57 +01:00

53 lines
3.1 KiB
Python

"""Entre deux étiquettes thermiques d'une station (écart de moins de 24 h), la caméra est-elle au repos ?
Pour chaque écart : marche de la pose (pan, tilt, rotation, scale ; médiane à l'heure) entre la fin de l'étiquette
et le début de la suivante, en part de l'amplitude de la pose sur les 24 h qui finissent à la fin de l'étiquette (des deux axes les plus amples du jour, celui qui bouge le plus hors étiquette).
Une part proche de 0 : nuit calme ; proche de 0,5 ou plus : la caméra bouge encore hors étiquette.
Usage, depuis la racine : python3 <ce fichier> STATION [STATION ...] (n'écrit rien)"""
import csv, glob, json, sys, statistics as st
from datetime import datetime, timedelta
def t(s): return datetime.fromisoformat(s.replace('Z', '+00:00').replace(' ', 'T'))
AX = ['pan', 'tilt', 'rotation', 'scale']
def pose(station):
h = {}
for p in sorted(glob.glob(f'data/{station}/camera/*.csv')):
for r in csv.DictReader(open(p)):
try: v = [float(r['median_' + a]) for a in AX]
except (ValueError, KeyError): continue
k = t(r['time_utc']).replace(minute=0, second=0)
h.setdefault(k, []).append(v)
return {k: [st.median(x[i] for x in l) for i in range(4)] for k, l in h.items()}
def proche(P, k):
k = k.replace(minute=0, second=0)
for d in (0, 1, -1, 2, -2):
if k + timedelta(hours=d) in P: return P[k + timedelta(hours=d)]
for station in sys.argv[1:]:
P = pose(station)
if not P: print(station, ': pas de pose'); continue
ks = sorted(P)
bruit = [st.median(abs(P[b][i] - P[a][i]) for a, b in zip(ks, ks[1:]) if b - a == timedelta(hours=1)) or 1e-9 for i in range(4)]
es = [(n, json.loads(l)) for n, l in enumerate(open(f'labeling/auto/{station}.jsonl'), 1) if l.strip()]
es = [(n, e) for n, e in es if e['categorie'] == 'Thermal displacement']
es.sort(key=lambda x: x[1]['debut'])
print(f'== {station} (bruit horaire pan/tilt/rot/scale : ' + ', '.join(f'{b:.2g}' for b in bruit) + ')')
parts = []
for (n1, e1), (n2, e2) in zip(es, es[1:]):
f, d = t(e1['fin']), t(e2['debut'])
if not timedelta(0) < d - f < timedelta(hours=24): continue
dans = [P[k] for k in ks if f - timedelta(hours=24) <= k <= f] # amplitude du jour qui finit
a, b = proche(P, f), proche(P, d)
if len(dans) < 3 or a is None or b is None: continue
amp = [(max(x[i] for x in dans) - min(x[i] for x in dans)) / bruit[i] for i in range(4)]
# les deux axes les plus amples du jour (le mouvement principal, pas la lente détente d'un axe secondaire)
ok = sorted(range(4), key=lambda j: -amp[j])[:2]
i = max(ok, key=lambda j: abs(b[j] - a[j]) / bruit[j] / amp[j])
marche = abs(b[i] - a[i]) / bruit[i]
part = marche / amp[i] if amp[i] else 0
parts.append(part)
print(f' #{n1} fin {e1["fin"][5:16]} -> #{n2} début {e2["debut"][5:16]} ({(d - f).total_seconds() / 3600:.1f} h) : '
f'{AX[i]} marche {marche:.0f} bruits, amplitude {amp[i]:.0f}, part {part:.2f}')
if parts: print(f' médiane des parts : {st.median(parts):.2f} sur {len(parts)} écarts')