Points: the plots rx, ry, error value (its threshold dashed) and image quality, stacked; the points from rx, ry, rejected measurements included

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-20 08:41:06 +01:00
1 parent 810e349b42
commit 7ef808eee3
2 files changed
+49 -20

No files matched your search

+19 -8
View File
@@ -30,29 +30,40 @@ def listing(st=""):
return [summary(n) for n in points.datasets(st or None)] return [summary(n) for n in points.datasets(st or None)]
def measured(st, a, b):
"""-> {sensor: [t]}: the points of [a, b), every measurement with a relative position, the rejected ones included
(labeling/scripts/points.py)."""
return {s: [m["t"] for m in ms if a <= m["t"] < b and m["relative_x"] is not None and m["relative_y"] is not None]
for s, ms in data.load(station.folder(st)).items()}
@refused @refused
def create(body): def create(body):
st, start, end = body.get("station", ""), body.get("start", ""), body.get("end", "") st, start, end = body.get("station", ""), body.get("start", ""), body.get("end", "")
n = points.name(st, start, end) n = points.name(st, start, end)
a, b = station.bounds(start, end) points.create(n, measured(st, *station.bounds(start, end)))
points.create(n, {s: [m["t"] for m in ms if a <= m["t"] < b and m["corr_x"] is not None and m["corr_y"] is not None]
for s, ms in data.load(station.folder(st)).items()})
return summary(n) return summary(n)
# the plots of the page, in their order: rx, ry, the recognition error and its threshold, the image quality
COLUMNS = ("relative_x", "relative_y", "error_value", "error_threshold", "peak", "flux", "sharpness", "fwhm", "dominance", "snr")
@refused @refused
def dataset(n): def dataset(n):
"""-> {name, station, start, end, sensors: {sensor: {t, x, y, valid}}}: corr_x, corr_y (px, the curves labelled) of """-> {name, station, start, end, sensors: {sensor: {t, valid, columns: {column: [value]}}}}: the COLUMNS of each
each point, None where the data no longer have it (a pumping again).""" point, None where the data no longer have it (a pumping or a run again); a column empty for the sensor left out."""
p, st = points.read(n), points.parts(n)[0] p, st = points.read(n), points.parts(n)[0]
now = {(s, points.time(m["t"])): m for s, ms in data.load(station.folder(st)).items() for m in ms} now = {(s, points.time(m["t"])): m for s, ms in data.load(station.folder(st)).items() for m in ms}
out = {} out = {}
for (s, t), v in sorted(p.items()): for (s, t), v in sorted(p.items()):
m, o = now.get((s, t), {}), out.setdefault(s, {"t": [], "x": [], "y": [], "valid": []}) m, o = now.get((s, t), {}), out.setdefault(s, {"t": [], "valid": [], "columns": {c: [] for c in COLUMNS}})
o["t"].append(t[:19].replace("T", " ")) # as Plotly shows it, UTC o["t"].append(t[:19].replace("T", " ")) # as Plotly shows it, UTC
o["x"].append(m.get("corr_x"))
o["y"].append(m.get("corr_y"))
o["valid"].append(v) o["valid"].append(v)
for c in COLUMNS:
o["columns"][c].append(m.get(c))
for o in out.values():
o["columns"] = {c: vs for c, vs in o["columns"].items() if any(x is not None for x in vs)}
return {**summary(n), "sensors": out} return {**summary(n), "sensors": out}
+30 -12
View File
@@ -4,7 +4,8 @@ import { call, Selector } from "../common.jsx";
// Points: the point labels (labeling/points/, labeling/scripts/points.py), one boolean per measurement of a range, valid or // Points: the point labels (labeling/points/, labeling/scripts/points.py), one boolean per measurement of a range, valid or
// not, set by hand: the ground truth of the benchmarks. Mainly on the runs of the emulator: the page starts on that source. A dataset per station and range, created with every point valid; // not, set by hand: the ground truth of the benchmarks. Mainly on the runs of the emulator: the page starts on that source. A dataset per station and range, created with every point valid;
// one target at a time, corr_x above corr_y; a click on a point switches it, a box sets every point inside it (mode). // one target at a time, its rx, ry, error value and image quality stacked on the same time; a click on a point of any plot
// switches it, a box sets every point inside it (mode).
// Each change is saved at once. // Each change is saved at once.
const VALID = "#2f9e44", INVALID = "#e03131"; const VALID = "#2f9e44", INVALID = "#e03131";
const FONT = "Roboto, sans-serif"; const FONT = "Roboto, sans-serif";
@@ -75,7 +76,14 @@ export default function Points({ selection, choose }) {
); );
} }
// corr_x above corr_y (px, the curves labelled), sharing the time; the points green valid, red invalid // The plots, top to bottom, those the sensor has (validity.COLUMNS): [column, title, unit of the tooltip]; the threshold
// of the error drawn dashed on its plot
const PANELS = [["relative_x", "rx [px]", " px"], ["relative_y", "ry [px]", " px"], ["error_value", "Error value", ""],
["peak", "Peak", ""], ["flux", "Flux", ""], ["sharpness", "Sharpness", ""], ["fwhm", "FWHM [px]", " px"],
["dominance", "Dominance", ""], ["snr", "SNR", ""]];
const ROW = 170, GAP = 0.012; // px per plot; space between plots (fraction of the height)
// the points green valid, red invalid, the same point at the same index on every plot
function Plot({ o, sensor, set, mode }) { function Plot({ o, sensor, set, mode }) {
const g = useRef(), [Plotly, setPlotly] = useState(null), dark = useComputedColorScheme("light") === "dark"; const g = useRef(), [Plotly, setPlotly] = useState(null), dark = useComputedColorScheme("light") === "dark";
const latest = useRef(); const latest = useRef();
@@ -84,21 +92,31 @@ function Plot({ o, sensor, set, mode }) {
useEffect(() => { useEffect(() => {
if (!Plotly) return; if (!Plotly) return;
const color = o.valid.map(v => (v ? VALID : INVALID)), text = dark ? "#c9c9c9" : "#495057", grid = dark ? "#2e2e2e" : "#eef0f2"; const color = o.valid.map(v => (v ? VALID : INVALID)), text = dark ? "#c9c9c9" : "#495057", grid = dark ? "#2e2e2e" : "#eef0f2";
const trace = (y, yaxis) => ({ type: "scattergl", mode: "lines+markers", x: o.t, y, yaxis, hovertemplate: "%{x}<br>%{y:.4f} px<extra></extra>", const panels = PANELS.filter(([c]) => o.columns[c]), n = panels.length, h = (1 - GAP * (n - 1)) / n;
line: { width: 1, color: dark ? "#555" : "#ccc" }, marker: { size: 6, color }, unselected: { marker: { opacity: 1 } } }); const axis = { gridcolor: grid, zeroline: false }, layout = {}, traces = [];
const axis = { gridcolor: grid, zeroline: false }; panels.forEach(([c, title, unit], k) => {
Plotly.react(g.current, [trace(o.x, "y"), trace(o.y, "y2")], { const y = k ? `y${k + 1}` : "y", top = 1 - k * (h + GAP);
height: 560, margin: { l: 60, r: 20, t: 10, b: 30 }, showlegend: false, dragmode: "select", selectdirection: "any", layout[k ? `yaxis${k + 1}` : "yaxis"] = { ...axis, domain: [Math.max(0, top - h), top], title: { text: title, font: { size: 11 } } };
traces.push({ type: "scattergl", mode: "lines+markers", x: o.t, y: o.columns[c], yaxis: y, meta: "point",
hovertemplate: `%{x}<br>${title}: %{y:.4f}${unit}<extra></extra>`, line: { width: 1, color: dark ? "#555" : "#ccc" },
marker: { size: 5, color }, unselected: { marker: { opacity: 1 } } });
if (c === "error_value" && o.columns.error_threshold)
traces.push({ type: "scattergl", mode: "lines", x: o.t, y: o.columns.error_threshold, yaxis: y, meta: "threshold", hoverinfo: "skip",
line: { width: 1, dash: "dash", color: INVALID } });
});
Plotly.react(g.current, traces, {
...layout, height: ROW * n + 40, margin: { l: 70, r: 20, t: 10, b: 30 }, showlegend: false, dragmode: "select", selectdirection: "any",
uirevision: sensor, paper_bgcolor: "rgba(0,0,0,0)", plot_bgcolor: "rgba(0,0,0,0)", font: { family: FONT, size: 11, color: text }, uirevision: sensor, paper_bgcolor: "rgba(0,0,0,0)", plot_bgcolor: "rgba(0,0,0,0)", font: { family: FONT, size: 11, color: text },
grid: { rows: 2, columns: 1, shared_xaxes: true }, xaxis: { ...axis, anchor: "y2" }, xaxis: { ...axis, anchor: n > 1 ? `y${n}` : "y" },
yaxis: { ...axis, domain: [0.53, 1], title: { text: "corr_x [px]" } }, yaxis2: { ...axis, domain: [0, 0.47], title: { text: "corr_y [px]" } },
}, { responsive: true, displaylogo: false, doubleClick: "reset", modeBarButtonsToRemove: ["lasso2d", "autoScale2d", "toggleSpikelines"] }); }, { responsive: true, displaylogo: false, doubleClick: "reset", modeBarButtonsToRemove: ["lasso2d", "autoScale2d", "toggleSpikelines"] });
if (!g.current._bound) { // once per plot: the handlers read the latest state if (!g.current._bound) { // once per plot: the handlers read the latest state
g.current._bound = true; g.current._bound = true;
g.current.on("plotly_click", ev => { const i = ev.points[0].pointIndex; latest.current.set([i], !latest.current.o.valid[i]); }); const ofPoints = ps => ps.filter(p => p.data.meta === "point").map(p => p.pointIndex);
g.current.on("plotly_click", ev => { const [i] = ofPoints(ev.points); if (i !== undefined) latest.current.set([i], !latest.current.o.valid[i]); });
g.current.on("plotly_selected", ev => { g.current.on("plotly_selected", ev => {
if (!ev?.points?.length) return; const is = [...new Set(ofPoints(ev?.points || []))];
latest.current.set([...new Set(ev.points.map(p => p.pointIndex))], latest.current.mode === "valid"); if (!is.length) return;
latest.current.set(is, latest.current.mode === "valid");
Plotly.relayout(g.current, { selections: [] }); Plotly.relayout(g.current, { selections: [] });
}); });
} }