diff --git a/app/server/validity.py b/app/server/validity.py index 7a04af3..002d251 100644 --- a/app/server/validity.py +++ b/app/server/validity.py @@ -30,29 +30,40 @@ def listing(st=""): 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 def create(body): st, start, end = body.get("station", ""), body.get("start", ""), body.get("end", "") n = points.name(st, start, end) - a, b = 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()}) + points.create(n, measured(st, *station.bounds(start, end))) 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 def dataset(n): - """-> {name, station, start, end, sensors: {sensor: {t, x, y, valid}}}: corr_x, corr_y (px, the curves labelled) of - each point, None where the data no longer have it (a pumping again).""" + """-> {name, station, start, end, sensors: {sensor: {t, valid, columns: {column: [value]}}}}: the COLUMNS of each + 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] now = {(s, points.time(m["t"])): m for s, ms in data.load(station.folder(st)).items() for m in ms} out = {} 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["x"].append(m.get("corr_x")) - o["y"].append(m.get("corr_y")) 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} diff --git a/app/web/src/pages/Points.jsx b/app/web/src/pages/Points.jsx index 0b84ae8..08e4c25 100644 --- a/app/web/src/pages/Points.jsx +++ b/app/web/src/pages/Points.jsx @@ -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 // 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. const VALID = "#2f9e44", INVALID = "#e03131"; 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 }) { const g = useRef(), [Plotly, setPlotly] = useState(null), dark = useComputedColorScheme("light") === "dark"; const latest = useRef(); @@ -84,21 +92,31 @@ function Plot({ o, sensor, set, mode }) { useEffect(() => { if (!Plotly) return; 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}
%{y:.4f} px", - line: { width: 1, color: dark ? "#555" : "#ccc" }, marker: { size: 6, color }, unselected: { marker: { opacity: 1 } } }); - const axis = { gridcolor: grid, zeroline: false }; - Plotly.react(g.current, [trace(o.x, "y"), trace(o.y, "y2")], { - height: 560, margin: { l: 60, r: 20, t: 10, b: 30 }, showlegend: false, dragmode: "select", selectdirection: "any", + const panels = PANELS.filter(([c]) => o.columns[c]), n = panels.length, h = (1 - GAP * (n - 1)) / n; + const axis = { gridcolor: grid, zeroline: false }, layout = {}, traces = []; + panels.forEach(([c, title, unit], k) => { + const y = k ? `y${k + 1}` : "y", top = 1 - k * (h + GAP); + 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}
${title}: %{y:.4f}${unit}`, 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 }, - grid: { rows: 2, columns: 1, shared_xaxes: true }, xaxis: { ...axis, anchor: "y2" }, - yaxis: { ...axis, domain: [0.53, 1], title: { text: "corr_x [px]" } }, yaxis2: { ...axis, domain: [0, 0.47], title: { text: "corr_y [px]" } }, + xaxis: { ...axis, anchor: n > 1 ? `y${n}` : "y" }, }, { responsive: true, displaylogo: false, doubleClick: "reset", modeBarButtonsToRemove: ["lasso2d", "autoScale2d", "toggleSpikelines"] }); if (!g.current._bound) { // once per plot: the handlers read the latest state 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 => { - if (!ev?.points?.length) return; - latest.current.set([...new Set(ev.points.map(p => p.pointIndex))], latest.current.mode === "valid"); + const is = [...new Set(ofPoints(ev?.points || []))]; + if (!is.length) return; + latest.current.set(is, latest.current.mode === "valid"); Plotly.relayout(g.current, { selections: [] }); }); }