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:
maximeandClaude Opus 5.5 committed 2026-11-16 15:48:42 +01:00
1 parent c1719cbd1d
commit 6ed4c420e1
13 files changed
+308 -359

No files matched your search

+6 -36
View File
@@ -18,37 +18,11 @@ Usage: python3 tools/scripts/summary.py data/PS_DES_COUDRES/ [--column error_val
Gives values, not a verdict.
"""
import argparse
import re
import statistics
import sys
from datetime import timedelta
from data import filter_window, is_reference, iso, load, parse_time, rejected
COLUMNS = ("error_value", "corr_x", "corr_y", "relative_x", "relative_y", "x", "y", "sigma0", "reproj_err")
QUALITY = ("peak", "flux", "sharpness", "fwhm", "dominance", "snr") # image quality: recent cameras; read by quality.py
STATS = {"median": statistics.median, "min": min, "max": max}
def duration(text):
"""'15min', '1h', '6h', '1d' -> timedelta."""
m = re.fullmatch(r"(\d+)(min|h|d)", text)
if not m:
raise argparse.ArgumentTypeError(f"invalid step: {text!r} (e.g. 15min, 1h, 1d)")
n, unit = int(m.group(1)), m.group(2)
return {"min": timedelta(minutes=n), "h": timedelta(hours=n), "d": timedelta(days=n)}[unit]
ROUNDING = 1e-9 # below this, a difference between two measurements is the rounding of the station's computation, not noise
def own_noise(vs):
"""Median of the absolute differences between two consecutive values; 0 when it is below ROUNDING (values constant
up to rounding: the corr of the references when the compensation goes exactly through them, two references
retained), so that a deviation is not written as billions of noises; 0 also with fewer than two values."""
d = [abs(b - a) for a, b in zip(vs, vs[1:])]
b = statistics.median(d) if d else 0
return b if b >= ROUNDING else 0
from common import COLUMNS, QUALITY, STATS, duration, per_step, sensors
from data import filter_window, iso, parse_time, rejected
def values(ms, col):
@@ -70,20 +44,16 @@ def main():
a.add_argument("--end", type=parse_time)
o = a.parse_args()
by = load(o.folder)
if not by:
sys.exit(f'No "advanced" export in {o.folder} (see inventory.py).')
names = o.sensors.split(",") if o.sensors else sorted(by, key=lambda s: (not is_reference(by[s]), s))
by, names = sensors(o.folder, o.sensors)
unknown = [s for s in names if s not in by]
if unknown:
sys.exit(f"Missing sensors: {', '.join(unknown)}. Present: {', '.join(sorted(by))}.")
t0 = min(m["t"] for s in names for m in by[s]).replace(hour=0, minute=0, second=0, microsecond=0)
key = per_step(min(m["t"] for s in names for m in by[s]), o.step)
steps = {}
for s in names:
for m in filter_window(by[s], o.start, o.end):
step_start = t0 + ((m["t"] - t0) // o.step) * o.step
steps.setdefault(step_start, {}).setdefault(s, []).append(m)
steps.setdefault(key(m["t"]), {}).setdefault(s, []).append(m)
if not steps:
sys.exit("No measurement in the requested window.")
@@ -104,7 +74,7 @@ def main():
if o.mark:
print("*: at least one measurement of the step is rejected; o: at least one measurement of the step has inlier = 0")
header = f"{'start':17} " + " ".join(f"{s:>9}" for s in names)
wanted = {t0 + ((parse_time(x) - t0) // o.step) * o.step for x in o.instants.split(",")} if o.instants else None
wanted = {key(parse_time(x)) for x in o.instants.split(",")} if o.instants else None
for i, k in enumerate(k for k in sorted(steps) if wanted is None or k in wanted):
if i % 24 == 0:
print(header)