sessions of 2026-11-18 (the optimization campaign; three runs without summary, interrupted and rerun)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8a81c53cd9
commit
0cfbd1b7bc
363 files changed
+30822
No files matched your search
@@ -0,0 +1,9 @@
|
||||
# Runs the benchmark of each variant folder given (in parallel, at most 6 at once), from the optimizer root, then compare.py against <reference benchmark>. Args: <reference benchmark> <variant folder>...
|
||||
ref=$1; shift
|
||||
cd /home/maxime/aimsight-optimizer || exit 1
|
||||
for v in "$@"; do
|
||||
while [ "$(jobs -r | wc -l)" -ge 6 ]; do sleep 2; done
|
||||
python3 "$v/bench/regression.py" --labels labeling/auto --data data > "$v.bench.txt" 2>&1 &
|
||||
done
|
||||
wait
|
||||
for v in "$@"; do echo "== $(basename $v)"; grep -c skipped "$v.bench.txt"; python3 detectors/bench/compare.py "$ref" "$v.bench.txt"; done
|
||||
@@ -0,0 +1,26 @@
|
||||
# Prints, per target and axis, the daily levels used by displacement.drift (in units of the median daily amplitude), the whole-window test and the pieces kept. Args: <detectors dir> <station folder> <from> <to> [sensor,...]
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts"), str(det.parents[0] / "aimsight-tools" / "scripts"), str(Path.cwd() / "tools" / "scripts")]
|
||||
import displacement as D
|
||||
from data import load, is_reference
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
start, end = day(sys.argv[3]), day(sys.argv[4])
|
||||
only = sys.argv[5].split(",") if len(sys.argv) > 5 else None
|
||||
ms = load(sys.argv[2])
|
||||
for s, v in sorted(ms.items()):
|
||||
if is_reference(v) or (only and s not in only):
|
||||
continue
|
||||
k = [m for m in v if start - timedelta(days=3) <= m["t"] < end]
|
||||
for col in ("corr_x", "corr_y"):
|
||||
ds, lv, ampl, _ = D._days(k, col)
|
||||
if len(ds) < 2:
|
||||
continue
|
||||
w = D._whole(ds, lv, ampl, None)
|
||||
p = D._pieces(ds, lv, ampl, None)
|
||||
if not (w or p) and not only:
|
||||
continue
|
||||
print(f"{s} {col} ampl={ampl:.4f} whole={w} pieces={[(round(d/ampl,2), str(ds[i]), str(ds[j])) for d,i,j in p]}")
|
||||
print(" ", " ".join(f"{d.day:02d}:{(x-lv[0])/ampl:+.1f}" for d, x in zip(ds, lv)))
|
||||
@@ -0,0 +1,23 @@
|
||||
# Per labelled station (benchmark range): the Slow drift episodes of displacement.drift (with 3 days of history) and the Displacement labels, to compare. Args: <detectors dir> <labels folder> <data folder> [STATION,...]
|
||||
import sys, json
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "bench"), str(det / "scripts")]
|
||||
import score, regression, displacement as D
|
||||
from data import load, parse_time
|
||||
only = sys.argv[4].split(",") if len(sys.argv) > 4 else None
|
||||
for path in sorted(Path(sys.argv[2]).glob("*.jsonl")):
|
||||
st = path.stem
|
||||
if only and st not in only:
|
||||
continue
|
||||
start, end = regression.label_range(path)
|
||||
ms = load(str(Path(sys.argv[3]) / st))
|
||||
h, b = parse_time(start) - timedelta(days=3), parse_time(end)
|
||||
chunk = {s: k for s, v in ms.items() if (k := [m for m in v if h <= m["t"] < b])}
|
||||
print(f"== {st} {start} → {end}")
|
||||
for e in score.read_labels(str(path), start, end):
|
||||
if e["family"] == "Displacement":
|
||||
print(" LABEL", e["id"], e["start"], e["end"], e["description"][:90])
|
||||
for e in D.drift(chunk):
|
||||
print(" drift", e["start"], e["end"], e["sensors"][0], e["text"].split(": ")[1][:30])
|
||||
@@ -0,0 +1,20 @@
|
||||
# Dumps the episodes of every detector (or one kind) over a window as categories.window sees it (3 days of history): start, end, kind, label, sensors, text. Args: <detectors dir> <station folder> <from> <to> [kind]
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts"), str(det.parents[0] / "aimsight-tools" / "scripts"), str(Path.cwd() / "tools" / "scripts")]
|
||||
import importlib
|
||||
from data import load
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
start, end = day(sys.argv[3]), day(sys.argv[4])
|
||||
ms = load(sys.argv[2])
|
||||
chunk = {s: k for s, v in ms.items() if (k := [m for m in v if start - timedelta(days=3) <= m["t"] < end])}
|
||||
kind = sys.argv[5] if len(sys.argv) > 5 else None
|
||||
for name in ("displacement", "no_data", "target_issue", "thermal_displacement", "visibility"):
|
||||
mod = importlib.import_module(name)
|
||||
eps = mod.detect(chunk, **({"end": end} if name == "no_data" else {}))
|
||||
for e in eps:
|
||||
if kind and e["kind"] != kind and e["label"] != kind:
|
||||
continue
|
||||
print(e["start"], e["end"], e["kind"], "|", e["label"], "|", ",".join(e["sensors"])[:80], "|", e["text"][:120])
|
||||
@@ -0,0 +1,13 @@
|
||||
# Prints every event of categories.window over a window with all its episodes (start, end, label, first sensors): where each episode went. Args: <detectors dir> <station folder> <from> <to>
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts")]
|
||||
import categories
|
||||
from data import load
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
for v in categories.window(load(sys.argv[2]), day(sys.argv[3]), day(sys.argv[4])):
|
||||
print(v["start"], v["end"], v["category"])
|
||||
for e in v["episodes"]:
|
||||
print(" ", e["start"], e["end"], e["label"], ",".join(e["sensors"])[:40])
|
||||
@@ -0,0 +1,19 @@
|
||||
# Lists the instants thermal_displacement.slides keeps (raw and corrected moving together), with how many sensors move on each side, over a window (3 days of history). Args: <detectors dir> <station folder> <from> <to>
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts"), str(det.parents[0] / "aimsight-tools" / "scripts"), str(Path.cwd() / "tools" / "scripts")]
|
||||
import thermal_displacement as T
|
||||
from data import load, is_reference, iso
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
start, end = day(sys.argv[3]), day(sys.argv[4])
|
||||
ms = load(sys.argv[2])
|
||||
m = {s: k for s, v in ms.items() if (k := [x for x in v if start - timedelta(days=3) <= x["t"] < end])}
|
||||
targets = [v for v in m.values() if not is_reference(v)]
|
||||
raw = {c: T._common([T._signs(v, c) for v in m.values()]) for c in ("x", "y")}
|
||||
corr = {c: T._common([T._signs(v, c) for v in targets]) for c in ("corr_x", "corr_y")}
|
||||
r, c = raw["x"] | raw["y"], corr["corr_x"] | corr["corr_y"]
|
||||
print("wave corr:", bool(T._wave(m, ("corr_x", "corr_y"), "Thermal", False)), "wave raw:", bool(T._wave(m, ("x", "y"), "Camera thermal", True)))
|
||||
for t in sorted(r & c):
|
||||
print(iso(t), "raw:", "x" if t in raw["x"] else "-", "y" if t in raw["y"] else "-", "corr:", "x" if t in corr["corr_x"] else "-", "y" if t in corr["corr_y"] else "-")
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Stage (git index only) the hunks of one file's working diff, except those containing a given text: commits one's own hunks in a file that also carries someone else's uncommitted change.
|
||||
|
||||
Usage: python3 stage_hunks.py <repo> <file> <text of the hunks to leave out> [--dry]
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
repo, path, exclude = sys.argv[1:4]
|
||||
dry = "--dry" in sys.argv
|
||||
diff = subprocess.run(["git", "-C", repo, "diff", "--", path], capture_output=True, text=True, check=True).stdout
|
||||
lines = diff.splitlines(keepends=True)
|
||||
head, hunks = [], []
|
||||
for line in lines:
|
||||
if line.startswith("@@"):
|
||||
hunks.append([line])
|
||||
elif hunks:
|
||||
hunks[-1].append(line)
|
||||
else:
|
||||
head.append(line)
|
||||
kept = [h for h in hunks if not any(exclude in l for l in h if l[:1] in "+-")]
|
||||
print(f"{len(hunks)} hunks, {len(kept)} staged, {len(hunks) - len(kept)} left out")
|
||||
if not kept:
|
||||
sys.exit("nothing to stage")
|
||||
patch = "".join(head) + "".join("".join(h) for h in kept)
|
||||
if dry:
|
||||
print(patch)
|
||||
else:
|
||||
subprocess.run(["git", "-C", repo, "apply", "--cached", "--recount", "-"], input=patch, text=True, check=True)
|
||||
@@ -0,0 +1,26 @@
|
||||
# Per family over a range: labels touching it, labels overlapped by an event of the family, events of the family touching it, events overlapping no label of the family; then the label ids missed and the wrong events. Args: <detectors dir> <station folder> <labels.jsonl> <from> <to>
|
||||
import sys, json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts")]
|
||||
import categories
|
||||
from data import load
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
a, b = sys.argv[4], sys.argv[5]
|
||||
evs = [v for v in categories.window(load(sys.argv[2]), day(a), day(b))]
|
||||
labels = [L for L in map(json.loads, filter(str.strip, open(sys.argv[3]))) if L["start"] < b and L["end"] >= a and L["family"] != "None"]
|
||||
ov = lambda L, v: L["start"] <= v["end"] and v["start"] <= L["end"]
|
||||
fams = sorted({L["family"] for L in labels} | {v["category"] for v in evs})
|
||||
print("| Family | labelled | found | flagged | wrongly |\n|---|---|---|---|---|")
|
||||
missed, wrong = [], []
|
||||
for f in fams:
|
||||
ls = [L for L in labels if L["family"] == f]
|
||||
es = [v for v in evs if v["category"] == f]
|
||||
fd = [L for L in ls if any(ov(L, v) for v in es)]
|
||||
wr = [v for v in es if not any(ov(L, v) for L in ls)]
|
||||
missed += [f"{L['id']} ({f})" for L in ls if L not in fd]
|
||||
wrong += [f"{v['start']}→{v['end']} {f}" for v in wr]
|
||||
print(f"| {f} | {len(ls)} | {len(fd)} | {len(es)} | {len(wr)} |")
|
||||
print("missed:", ", ".join(missed))
|
||||
print("wrong:", "; ".join(wrong))
|
||||
@@ -0,0 +1,16 @@
|
||||
# Traces the episodes of one sensor through categories.events over a window: the event each one ends in (or none). Args: <detectors dir> <station folder> <from> <to> <sensor>
|
||||
import sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts")]
|
||||
import categories
|
||||
from data import load
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
a, b, s = day(sys.argv[3]), day(sys.argv[4]), sys.argv[5]
|
||||
ms = load(sys.argv[2])
|
||||
chunk = {k: x for k, v in ms.items() if (x := [m for m in v if a - timedelta(days=3) <= m["t"] < b])}
|
||||
for v in categories.events(chunk, b):
|
||||
for e in v["episodes"]:
|
||||
if s in e["sensors"] and len(e["sensors"]) < 5:
|
||||
print(v["start"], v["end"], v["category"], "<-", e["start"], e["end"], e["label"])
|
||||
@@ -0,0 +1,16 @@
|
||||
# Makes a variant of the detectors for the pruning: copies <src> to <dst> (without .git) and replaces, in <file> (relative), each <old> by <new> (pairs of arguments; each old must occur exactly once). Args: <src> <dst> <file> <old> <new> [<old> <new> ...]
|
||||
import shutil, sys
|
||||
from pathlib import Path
|
||||
src, dst, rel, pairs = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3], sys.argv[4:]
|
||||
if dst.exists():
|
||||
shutil.rmtree(dst)
|
||||
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(".git", "__pycache__"))
|
||||
f = dst / rel
|
||||
text = f.read_text()
|
||||
for old, new in zip(pairs[::2], pairs[1::2]):
|
||||
n = text.count(old)
|
||||
if n != 1:
|
||||
sys.exit(f"{dst.name}: {n} occurrences of {old!r}")
|
||||
text = text.replace(old, new)
|
||||
f.write_text(text)
|
||||
print(dst.name, "ok")
|
||||
@@ -0,0 +1,39 @@
|
||||
# For each label of a family over a window, prints per instant (from 1 h before to 1 h after) what visibility.py reads: the median error_value z (MAD above each sensor's median), the number of 'high' sensors (K_MAD and FACTOR), the number rejected. Args: <detectors dir> <station folder> <labels.jsonl> <from> <to> [family]
|
||||
import sys, json, statistics
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
det = Path(sys.argv[1]).resolve()
|
||||
sys.path[:0] = [str(det / "scripts"), str(det.parents[0] / "aimsight-tools" / "scripts"), str(Path.cwd() / "tools" / "scripts")]
|
||||
import visibility as V
|
||||
from episodes import level
|
||||
from data import load, parse_time, iso
|
||||
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
||||
start, end = day(sys.argv[4]), day(sys.argv[5])
|
||||
fam = sys.argv[6] if len(sys.argv) > 6 else "Visibility"
|
||||
ms = load(sys.argv[2])
|
||||
chunk = {s: k for s, v in ms.items() if (k := [m for m in v if start - timedelta(days=3) <= m["t"] < end])}
|
||||
z, high, rej = {}, {}, {}
|
||||
for s, v in chunk.items():
|
||||
e = [m["error_value"] for m in v if m["error_value"] is not None]
|
||||
if len(e) < 10:
|
||||
continue
|
||||
med, mad = level(e)
|
||||
for m in v:
|
||||
x = m["error_value"]
|
||||
if x is None:
|
||||
continue
|
||||
z.setdefault(m["t"], []).append((x - med) / mad)
|
||||
if x > med + V.K_MAD * mad and x > V.FACTOR * med:
|
||||
high.setdefault(m["t"], set()).add(s)
|
||||
if m["error_threshold"] and x > m["error_threshold"]:
|
||||
rej.setdefault(m["t"], set()).add(s)
|
||||
labels = [json.loads(l) for l in open(sys.argv[3]) if l.strip()]
|
||||
for L in labels:
|
||||
if L["family"] != fam or not (L["start"] < sys.argv[5] and L["end"] >= sys.argv[4]):
|
||||
continue
|
||||
a, b = parse_time(L["start"]) - timedelta(hours=1), parse_time(L["end"]) + timedelta(hours=1)
|
||||
print(L["id"], L["start"], L["end"])
|
||||
for t in sorted(z):
|
||||
if a <= t <= b:
|
||||
inside = "*" if L["start"] < iso(t) < L["end"] else " "
|
||||
print(f" {inside} {iso(t)} zmed={statistics.median(z[t]):6.2f} high={len(high.get(t, ())):2d} rej={len(rej.get(t, ())):2d} n={len(z[t])}")
|
||||
Reference in new issue
Block a user