improve: S1

metrics: --weather adds the weather/ columns (w_*) to the table, the r and the PNG

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 11:21:06 +01:00
1 parent 342728286f
commit e17202d596
2 files changed
+25 -4

No files matched your search

+1 -1
View File
@@ -114,7 +114,7 @@ def contents(folder, f, start=None, end=None):
others[os.path.relpath(p, folder).split(os.sep)[0]].append(p)
for title, paths in (('"advanced" export', f["advanced"]), ("Camera pose (camera/)", f["camera"]),
("Image quality (quality/)", others.pop("quality", [])),
("Weather (weather/, nearest MeteoSwiss station, hourly; tools/DATA.md, no tool plots it)",
("Weather (weather/, nearest MeteoSwiss station, hourly; tools/DATA.md; metrics.py --weather)",
others.pop("weather", []))):
if paths:
n, count, who = filled(paths, start, end)
+24 -3
View File
@@ -3,13 +3,15 @@ against the target median of corr_x, corr_y and the camera pose.
Usage: .venv/bin/python tools/scripts/metrics.py data/PS_DES_COUDRES/
[--names sensor_A0_deg_c,BusVoltage] [--step 1h] [--stat median|min|max] [--against temperature] [--smoothing 24h]
[--metrics-only] [--start ...] [--end ...] [--out FOLDER]
[--metrics-only] [--weather [precipitation_mm,temperature_c,...]] [--start ...] [--end ...] [--out FOLDER]
Columns: `temperature` (median of the sensor_*_deg_c components at each hour, as the detectors read it,
data.load_temperature), then each metric of --names (default: the *_deg_c and BusVoltage present), then,
unless --metrics-only, tgt_corr_x, tgt_corr_y (at each measurement, median over the targets of corr minus the target's
own level, its median over the window; accepted measurements only) and the raw camera pose (cam_pan,
cam_tilt, cam_rotation, cam_scale, cam_sigma0). An empty cell of a metrics/ CSV is skipped, not read as zero.
cam_tilt, cam_rotation, cam_scale, cam_sigma0); with --weather, the hourly MeteoSwiss weather of weather/
(data.load_weather; the hour starting at time_utc), one w_<column> column each (default WEATHER), and where it was
measured is printed first. An empty cell of a metrics/ CSV is skipped, not read as zero.
A text metric (BatteryState, link, last_sync…) is given as it is (the last one of the step).
Never an identifier: SIM_CCID and ip* are neither read nor listed.
Prints: the available metrics; the table, one line per step of --step (start of the step, UTC; --stat of the values of the
@@ -35,7 +37,10 @@ import matplotlib.dates as mdates # noqa: E402
import matplotlib.pyplot as plt # noqa: E402
from common import STATS, bound, cut, duration, group, targets # noqa: E402
from data import METRIC_RE, POSE, filter_window, iso, load, load_camera, load_temperature, parse_time # noqa: E402
from data import (METRIC_RE, POSE, WHERE, filter_window, iso, load, load_camera, load_temperature, # noqa: E402
load_weather, parse_time)
WEATHER = "precipitation_mm,temperature_c,humidity_pct,wind_speed_kmh,sunshine_min" # default of --weather
def is_identifier(name):
@@ -94,6 +99,8 @@ def main():
a.add_argument("--against", default="temperature", help="column on which r and the slope are computed")
a.add_argument("--smoothing", type=duration, help="centred moving average of --against, e.g. 24h")
a.add_argument("--metrics-only", action="store_true", help="without tgt_corr_x, tgt_corr_y or the pose")
a.add_argument("--weather", nargs="?", const=WEATHER, metavar="COLUMNS",
help=f"add the weather/ columns, comma-separated (without a value: {WEATHER})")
a.add_argument("--start", type=parse_time)
a.add_argument("--end", type=parse_time)
a.add_argument("--out", default=os.path.join("out", "diagnostic"), help="folder of the PNG")
@@ -121,6 +128,20 @@ def main():
sys.exit(f"--against {o.against}: not a column ({', '.join(series)}).")
series[o.against + "_smooth"] = smooth(series[o.against], o.smoothing)
metric_cols = list(series)
if o.weather:
hours = load_weather(o.folder)
if not hours:
print(f"No weather/ in {o.folder}.")
else:
known = [c for c in hours[0] if c not in WHERE and c != "t"]
if missing := [c for c in o.weather.split(",") if c not in known]:
sys.exit(f"Unknown weather columns: {', '.join(missing)}. Known: {', '.join(known)}.")
h = hours[-1]
print(f"Weather: {h.get('station_name')} ({h.get('place')}), {h.get('distance_km')} km, {h.get('height_m')} m; "
"hourly, the hour starting at the time given")
hours = filter_window(hours, o.start, o.end)
for c in o.weather.split(","):
series["w_" + c] = [{"t": p["t"], "v": p[c]} for p in hours if p[c] is not None]
if not o.metrics_only:
by_sensor = load(o.folder)
for c in ("corr_x", "corr_y"):