Files
Support-Agent/labeling/auto/revue-croisee/2026-11-04/finition/divers/outils/perspective.py
T
maximeandClaude Opus 5.5 35b5ed4d74 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

78 lines
5.4 KiB
Python

"""NEBRASKA : la montée propre de POUH20 et COLH21 vient-elle du mouvement de la caméra ?
Pour chaque cible, à chaque mesure, sa position brute est prédite depuis BASE par une transformation ajustée sur les
11 AUTRES cibles (laissée de côté) : similitude (comme ensemble.py --rigide, ici par moindres carrés) ou homographie
(la transformation d'une caméra qui tourne). Imprime, par jour à HEURE, le résidu dy (px x1000) des deux modèles,
puis, par cible, la corrélation r de son résidu de similitude avec le tilt de la caméra sur tout le lot.
Usage, depuis la racine : .venv/bin/python <ce fichier> [BASE] [HEURE] [CIBLES] (n'écrit rien)"""
import csv, glob, sys
import numpy as np
D = 'data/NEBRASKA'
BASE = sys.argv[1] if len(sys.argv) > 1 else '2026-10-03T00:00'
H = sys.argv[2] if len(sys.argv) > 2 else 'T00:00'
VOIR = (sys.argv[3] if len(sys.argv) > 3 else 'POUH20,COLH21,POUH21,COLJ23,COLJ24,COLH20').split(',')
pos, tilt = {}, {}
for f in sorted(glob.glob(f'{D}/displacement/*.csv')):
for r in csv.DictReader(open(f)):
if r['pattern_type'] == 'target':
pos.setdefault(r['time_utc'][:16].replace(' ', 'T'), {})[r['sensor_name']] = (float(r['x']), float(r['y']))
for f in sorted(glob.glob(f'{D}/camera/*.csv')):
for r in csv.DictReader(open(f)):
tilt[r['time_utc'][:16].replace(' ', 'T')] = float(r['median_tilt'])
cib = sorted(pos[BASE]); P0 = np.array([pos[BASE][c] for c in cib])
def sim(s, d): # u = a x - b y + tx, v = b x + a y + ty
A = np.vstack([np.c_[s[:, 0], -s[:, 1], np.ones(len(s)), np.zeros(len(s))], np.c_[s[:, 1], s[:, 0], np.zeros(len(s)), np.ones(len(s))]])
a, b, tx, ty = np.linalg.lstsq(A, np.r_[d[:, 0], d[:, 1]], rcond=None)[0]
return lambda p: np.array([a * p[0] - b * p[1] + tx, b * p[0] + a * p[1] + ty])
def homo(s, d):
m = s.mean(0); s = s - m; d2 = d - m; A = []
for (x, y), (u, v) in zip(s, d2):
A += [[x, y, 1, 0, 0, 0, -u * x, -u * y, -u], [0, 0, 0, x, y, 1, -v * x, -v * y, -v]]
h = np.linalg.svd(np.array(A))[2][-1].reshape(3, 3)
def f(p):
q = h @ np.r_[p - m, 1]; return q[:2] / q[2] + m
return f
res = {}
for k in sorted(pos):
if k < BASE or set(pos[k]) != set(cib): continue
P = np.array([pos[k][c] for c in cib])
for i, c in enumerate(cib):
o = [j for j in range(len(cib)) if j != i]
rs = P[i] - sim(P0[o], P[o])(P0[i]); rh = P[i] - homo(P0[o], P[o])(P0[i])
res.setdefault(c, []).append((k, rs, rh))
print('résidu dy, px x1000 : similitude / homographie (cible laissée de côté)')
print('instant ' + ''.join(f'{c:>14}' for c in VOIR) + ' tilt')
for n, (k, _, _) in enumerate(res[cib[0]]):
if k.endswith(H):
print(k, ''.join(f'{res[c][n][1][1]*1000:7.0f}/{res[c][n][2][1]*1000:<6.0f}' for c in VOIR), f'{tilt.get(k, float("nan")):.4f}')
print('\nmédiane par jour, homographie dy (px x1000) ; reste = résidu moins pente x (tilt - tilt de BASE), pente ajustée sur le lot')
t0 = tilt[BASE]
for c in VOIR + ['COLJ19']:
t = np.array([tilt.get(k, np.nan) for k, _, _ in res[c]]); ok = ~np.isnan(t); h = np.array([r[2][1] for r in res[c]])
pente = np.polyfit(t[ok] - t0, h[ok], 1); res[c + '_reste'] = h - np.polyval(pente, t - t0)
print(f'{c:8} pente {pente[0]:.1f} px/deg ; écart-type du reste {np.nanstd(res[c + "_reste"])*1000:.0f}')
jours = sorted({k[:10] for k, _, _ in res[cib[0]]})
print('jour ' + ''.join(f'{c:>16}' for c in VOIR + ['COLJ19']) + ' tilt (homographie / reste)')
for j in jours:
idx = [n for n, (k, _, _) in enumerate(res[cib[0]]) if k[:10] == j]
print(j, ''.join(f"{np.median([res[c][n][2][1] for n in idx])*1000:8.0f}/{np.nanmedian(res[c + '_reste'][idx])*1000:<7.0f}" for c in VOIR + ['COLJ19']),
f"{np.nanmedian([tilt.get(res[cib[0]][n][0], np.nan) for n in idx]):.4f}")
print('\npar cible, sur toutes les mesures : r(résidu dy similitude, tilt), r(dx, tilt), écart-type du résidu homographie dx, dy (px x1000)')
for c in cib:
t = np.array([tilt.get(k, np.nan) for k, _, _ in res[c]]); ok = ~np.isnan(t)
dy = np.array([r[1][1] for r in res[c]]); dx = np.array([r[1][0] for r in res[c]]); h = np.array([r[2] for r in res[c]])
print(f'{c:8} r_dy {np.corrcoef(dy[ok], t[ok])[0,1]:+.2f} r_dx {np.corrcoef(dx[ok], t[ok])[0,1]:+.2f} '
f'sim dy fin {dy[-1]*1000:5.0f} homo dx sd {h[:,0].std()*1000:4.0f} dy sd {h[:,1].std()*1000:4.0f} homo dy fin {h[-1,1]*1000:5.0f}')
print('\nhomographie dx, dy (px x1000), médiane du jour, toutes les cibles')
print('jour ' + ''.join(f'{c:>12}' for c in cib))
for j in ['2026-10-07', '2026-10-12', '2026-10-15', '2026-10-19', '2026-10-24', '2026-10-30']:
idx = [n for n, (k, _, _) in enumerate(res[cib[0]]) if k[:10] == j]
print(j, ''.join(f"{np.median([res[c][n][2][0] for n in idx])*1000:6.0f},{np.median([res[c][n][2][1] for n in idx])*1000:<5.0f}" for c in cib))
print('\nà tilt égal : médiane du résidu homographie dy (px x1000) par tranche de tilt, avant et après le 16/10 12:00 (nombre de mesures)')
for c in ['POUH20', 'COLH21', 'POUH21']:
l = []
for a in np.arange(0.020, 0.048, 0.003):
av = [r[2][1] for r in res[c] if a <= tilt.get(r[0], -1) < a + 0.003 and r[0] < '2026-10-16T12']
ap = [r[2][1] for r in res[c] if a <= tilt.get(r[0], -1) < a + 0.003 and r[0] >= '2026-10-16T12']
l.append(f'[{a:.3f}) ' + (f'{np.median(av)*1000:4.0f}({len(av)})' if av else ' - ') + ' / ' + (f'{np.median(ap)*1000:4.0f}({len(ap)})' if ap else ' - '))
print(f'{c:7}', ' ; '.join(l))