Scripts: shared helpers in common.py, no tool imports another; CLI and outputs unchanged
data.py stays the reader (METRIC_RE now also captures the file date, same matches); common.py holds columns, steps, noise, sensor list, runs, file names. Duplicated run grouping, pose gaps, step bucketing, --table/--outside parsing removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1719cbd1d
commit
6ed4c420e1
13 files changed
+308
-359
No files matched your search
+21
-44
@@ -20,14 +20,11 @@ import collections
|
||||
import csv
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import statistics
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from data import filter_window, find_files, image_time, is_reference, iso, load, load_camera, parse_time, rejected
|
||||
from summary import QUALITY
|
||||
|
||||
METRIC_RE = re.compile(r"^(.+?)_(\d{4})_(\d{2})_(\d{2})_\d{2}_\d{2}") # NIEDERHORN_BusCurrent_2026_09_22_00_00 to ….csv
|
||||
from common import QUALITY, group, without_pose
|
||||
from data import METRIC_RE, filter_window, find_files, image_time, is_reference, iso, load, load_camera, parse_time, rejected
|
||||
|
||||
|
||||
def span(a, b, n):
|
||||
@@ -158,17 +155,17 @@ def images(paths, start=None, end=None):
|
||||
return
|
||||
# Runs of images at a regular gap (rounded to 5 min, which absorbs the few seconds of delay of a shot):
|
||||
# one line per change of gap, without losing any of the times covered.
|
||||
runs = [] # [first, last, gap in min, number of gaps]
|
||||
for a, b in zip(times, times[1:]):
|
||||
e = round((b - a).total_seconds() / 300) * 5
|
||||
if runs and runs[-1][2] == e:
|
||||
runs[-1][1], runs[-1][3] = b, runs[-1][3] + 1
|
||||
else:
|
||||
runs.append([a, b, e, 1])
|
||||
pairs = [(a, b, round((b - a).total_seconds() / 300) * 5) for a, b in zip(times, times[1:])]
|
||||
what = "over the window" if start or end else "between the first and the last"
|
||||
print(f" gap between two images {what}, per run of equal gaps (within 5 min):")
|
||||
for a, b, e, n in runs:
|
||||
print(f" {iso(a)} → {iso(b)}: " + (f"{n + 1} images, every {e} min" if n > 1 else f"one gap of {e} min"))
|
||||
for g in group(pairs, lambda p, q: p[2] == q[2]):
|
||||
n, e = len(g), g[0][2]
|
||||
print(f" {iso(g[0][0])} → {iso(g[-1][1])}: " + (f"{n + 1} images, every {e} min" if n > 1 else f"one gap of {e} min"))
|
||||
|
||||
|
||||
def missing(instants, cadence):
|
||||
"""Gaps between two present instants: [(before, after, number of absent steps)]."""
|
||||
return [(a, b, n) for a, b in zip(instants, instants[1:]) if (n := round((b - a) / cadence) - 1) > 0]
|
||||
|
||||
|
||||
def measurements(by):
|
||||
@@ -179,8 +176,7 @@ def measurements(by):
|
||||
cadence = statistics.median(b - a for a, b in zip(instants, instants[1:]))
|
||||
print(f"\nMeasurement period: {iso(instants[0])} → {iso(instants[-1])}, {len(instants)} instants")
|
||||
print(f"Cadence (median step): {cadence.total_seconds() / 60:.0f} min")
|
||||
gaps = [(a, b, round((b - a) / cadence) - 1) for a, b in zip(instants, instants[1:])]
|
||||
gaps = [x for x in gaps if x[2] > 0]
|
||||
gaps = missing(instants, cadence)
|
||||
print(f"Missing measurements (instants absent from the cadence): {sum(n for *_, n in gaps)}")
|
||||
for a, b, n in gaps:
|
||||
print(f" between {iso(a)} and {iso(b)}: {n}")
|
||||
@@ -207,19 +203,11 @@ def camera(folder, by, start=None, end=None):
|
||||
if not poses:
|
||||
print(f"\nCamera pose {what}: none")
|
||||
return
|
||||
with_pose = {p["t"].replace(second=0, microsecond=0) for p in poses}
|
||||
print(f"\nCamera pose {what}: {len(poses)} registrations, {iso(poses[0]['t'])} → {iso(poses[-1]['t'])}")
|
||||
runs = [] # [start, end, count, rank] of the consecutive measurement instants without a pose
|
||||
for i, t in enumerate(instants):
|
||||
if t.replace(second=0, microsecond=0) in with_pose:
|
||||
continue
|
||||
if runs and runs[-1][3] == i - 1:
|
||||
runs[-1][1], runs[-1][2], runs[-1][3] = t, runs[-1][2] + 1, i
|
||||
else:
|
||||
runs.append([t, t, 1, i])
|
||||
runs = without_pose(instants, poses)
|
||||
print(f"Measurement instants without a pose (no registration): {sum(x[2] for x in runs)} of {len(instants)}")
|
||||
if start or end:
|
||||
for a, b, n, _ in runs:
|
||||
for a, b, n in runs:
|
||||
print(f" {span(a, b, n)}")
|
||||
|
||||
|
||||
@@ -232,8 +220,7 @@ def window(by, start, end):
|
||||
print(f"\nWindow {iso(inside[0])} → {iso(inside[-1])}: {len(inside)} instants present")
|
||||
names = sorted(by, key=lambda s: (not is_reference(by[s]), s))
|
||||
print(f"Steps absent for all sensors, between two present instants (cadence of {cadence.total_seconds() / 60:.0f} min):")
|
||||
gaps = [(a, b, round((b - a) / cadence) - 1) for a, b in zip(inside, inside[1:])]
|
||||
gaps = [x for x in gaps if x[2] > 0]
|
||||
gaps = missing(inside, cadence)
|
||||
for a, b, n in gaps:
|
||||
print(f" between {iso(a)} and {iso(b)}: {n}")
|
||||
if not gaps:
|
||||
@@ -248,14 +235,8 @@ def window(by, start, end):
|
||||
print("Rejected measurements in the window, per sensor (start → end of each run of consecutive steps, count):")
|
||||
for s in names:
|
||||
rej = [t for t in sorted(series[s]) if rejected(series[s][t])]
|
||||
runs = []
|
||||
for t in rej:
|
||||
if runs and t - runs[-1][1] <= cadence * 1.5:
|
||||
runs[-1][1], runs[-1][2] = t, runs[-1][2] + 1
|
||||
else:
|
||||
runs.append([t, t, 1])
|
||||
if rej:
|
||||
print(f" {s} ({len(rej)}): " + "; ".join(span(a, b, n) for a, b, n in runs))
|
||||
print(f" {s} ({len(rej)}): " + "; ".join(span(g[0], g[-1], len(g)) for g in group(rej, lambda a, b: b - a <= cadence * 1.5)))
|
||||
if not any(rejected(m) for d in series.values() for m in d.values()):
|
||||
print(" (none)")
|
||||
refs = [s for s in names if is_reference(by[s])]
|
||||
@@ -276,14 +257,10 @@ def window(by, start, end):
|
||||
+ ", ".join(f"{k}: {count[k]}" for k in sorted(count, reverse=True)))
|
||||
print("Instants where references are not retained (runs of consecutive steps with the same references out; "
|
||||
f"r = rejected, empty = {col} empty, otherwise the inlier value):")
|
||||
runs = []
|
||||
for i, (t, h) in enumerate(out):
|
||||
if h and runs and runs[-1][3] == h and runs[-1][4] == i - 1:
|
||||
runs[-1][1], runs[-1][2], runs[-1][4] = t, runs[-1][2] + 1, i
|
||||
elif h:
|
||||
runs.append([t, t, 1, h, i])
|
||||
for a, b, n, h, _ in runs:
|
||||
print(f" {span(a, b, n)}: {len(refs) - len(h)} retained; out: "
|
||||
runs = group([(i, t, h) for i, (t, h) in enumerate(out) if h], lambda a, b: b[0] == a[0] + 1 and b[2] == a[2])
|
||||
for g in runs:
|
||||
h = g[0][2]
|
||||
print(f" {span(g[0][1], g[-1][1], len(g))}: {len(refs) - len(h)} retained; out: "
|
||||
+ ", ".join(f"{s} ({q})" for s, q in h))
|
||||
if not runs:
|
||||
print(" (none)")
|
||||
|
||||
Reference in new issue
Block a user