Removed (their benchmark contribution, each alone): the reference exception of Brief obstruction (none; Obstruction found +9 at LENZSPITZE), REJECT_FACTOR (Obstruction correct +2), FRAC and BREAK (Visibility found -3, Obstruction found +4), the bounds at the rejected targets (neutral), FEW (Visibility found -1), the TARGET_MIN exception at a slow cadence (none in total), MIN_DURATION of heat shimmer (Visibility found -1). RATIO_ERR merged into RATIO (same value). Target obscured: one episode per target. The event sentences of its varieties are now the episodes' texts. common.py: episode, runs, noise, level, cadence, targets. Benchmark Totals: Visibility found 47 -> 55 %, correct 77 -> 72 %; Obstruction found 26 -> 22 %, correct 28 -> 32 %; the other families unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""Helpers shared by the detectors."""
|
|
import statistics
|
|
from datetime import timedelta
|
|
|
|
from data import iso
|
|
|
|
|
|
def episode(start, end, kind, label, text, sensors, ignore, **extra):
|
|
return {"start": iso(start), "end": iso(end), "kind": kind, "label": label, "text": text, "ignore": ignore,
|
|
"sensors": sorted(sensors), **extra}
|
|
|
|
|
|
def runs(times, gap):
|
|
"""Sorted times -> [[t, ...]]: runs of times at most gap apart."""
|
|
out = []
|
|
for t in times:
|
|
if out and t - out[-1][-1] <= gap:
|
|
out[-1].append(t)
|
|
else:
|
|
out.append([t])
|
|
return out
|
|
|
|
|
|
def noise(v):
|
|
"""Median step of a series, from one value to the next."""
|
|
return statistics.median(abs(y - x) for x, y in zip(v, v[1:])) if len(v) > 1 else 0
|
|
|
|
|
|
def level(v):
|
|
"""-> (median, MAD) of the values."""
|
|
med = statistics.median(v)
|
|
return med, statistics.median(abs(x - med) for x in v) or 1e-9
|
|
|
|
|
|
def cadence(measurements):
|
|
"""Cycle of the measurements: the median gap between two instants, at least an hour divided by the median number of
|
|
instants per clock hour (a station measuring in bursts, three measurements a minute apart every 15 min: 15 min)."""
|
|
ts = sorted({m["t"].replace(second=0, microsecond=0) for ms in measurements.values() for m in ms})
|
|
per_hour = {}
|
|
for t in ts:
|
|
per_hour[t.replace(minute=0)] = per_hour.get(t.replace(minute=0), 0) + 1
|
|
gap = statistics.median(b - a for a, b in zip(ts, ts[1:])) if len(ts) > 1 else timedelta(hours=1)
|
|
return max(gap, timedelta(hours=1) / statistics.median(per_hour.values()))
|
|
|
|
|
|
def targets(n):
|
|
return "one target" if n == 1 else f"{n} targets"
|