Files
Jungfraujoch/frontend/src/components/DataProcessingSettings.tsx
leonarski_f 7f2ebd8209
Build Packages / Build documentation (push) Successful in 46s
Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m25s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m46s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m25s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m41s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m46s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m37s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 24m31s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m9s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m47s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 26m21s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 27m36s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 29m27s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 31m46s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 25m22s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m36s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 31m49s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 23m57s
Build Packages / Unit tests (push) Successful in 1h47m52s
Build Packages / Validation Battery (push) Successful in 44m55s
v1.0.0-rc.184 (#95)
* Rugnux: Rotation processing recovers most of the speed lost since 1.0.0-rc.180; live processing in jfjoch_broker finishes sooner.
* Rugnux: More reliable rotation processing and indexing, including small molecules and supercells.
* Rugnux: More robust serial data and model refinement; molecular replacement handles multi-chain models.
* jfjoch_broker (experimental): Live serial processing keeps the detector geometry fixed for the whole run.
* jfjoch_broker: Pixel sum without an FPGA, a mask bit for inactive pixels, and several stability fixes.
* jfjoch_broker: Rotation indexing and quick integration moved to rugnux live mode; their API settings are deprecated and ignored.
* jfjoch_broker, Rugnux: Azimuthal integration can use logarithmic (log10) Q bins or a given number of bins, set from the API, the web interface and the Rugnux command line.
* jfjoch_viewer: Build and display fixes; the README is rewritten.

Reviewed-on: #95
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-10 22:06:51 +01:00

202 lines
12 KiB
TypeScript

import {memo, ReactNode, useEffect, useState} from 'react';
import {Button, FormControlLabel, Grid, Slider, Stack, Switch, Typography} from "@mui/material";
import {spot_finding_settings} from "../client";
import {putConfigSpotFindingMutation} from "../client/@tanstack/react-query.gen";
import SettingsPanel from "./SettingsPanel";
import {useUpload} from "./useUpload";
import _ from "lodash";
type MyProps = {
s?: spot_finding_settings,
update: () => void
};
type Edits = Partial<spot_finding_settings>;
// The broker stores the thresholds as float32, so 0.02 comes back as 0.0199999995: compare numbers
// with a tolerance, or an uploaded value would never be recognised as the broker's.
const same = (a: unknown, b: unknown) =>
typeof a === "number" && typeof b === "number" ? Math.abs(a - b) <= 1e-6 * Math.max(1, Math.abs(a)) : a === b;
// The edits that still differ from the broker's copy.
const pendingEdits = (edits: Edits, serverS: spot_finding_settings): Edits =>
_.pickBy(edits, (v, k) => !same(v, serverS[k as keyof spot_finding_settings]));
type SettingSliderProps = {
label: ReactNode,
value: number,
min: number,
max: number,
step: number,
digits?: number,
disabled: boolean,
onChange: (v: number) => void,
onCommit: (v: number) => void
};
// Firefox saves a range input whose value the browser snapped to the slider's step (the broker's float32
// ice-ring width 0.02 reads back as 0.0199999...) as if the user had edited it, and on session restore
// writes it back with an input event, which MUI commits as a change the user never made.
const NO_FORM_RESTORE = { input: { autoComplete: "off" } };
function SettingSlider({label, value, min, max, step, digits = 0, disabled, onChange, onCommit}: SettingSliderProps) {
return <>
<Typography gutterBottom>{label}</Typography>
<Slider slotProps={NO_FORM_RESTORE} disabled={disabled} value={value} min={min} max={max} step={step}
aria-label={typeof label === "string" ? label : undefined}
onChange={(_e, v) => onChange(v as number)}
onChangeCommitted={(_e, v) => onCommit(v as number)}
valueLabelDisplay="auto" valueLabelFormat={(x) => x.toFixed(digits)}/>
</>;
}
// The panel holds the broker's copy (serverS, from the /statistics poll) and the user's edits on top
// of it, and shows the two merged. Nothing is shown before the broker's copy has arrived, and what is
// sent is always the broker's copy with the edits applied - never a value the frontend made up.
// Edits are sent by Upload; with Live sync engaged each change is sent as it is made instead.
function DataProcessingSettings({s: serverS, update}: MyProps) {
const [edits, setEdits] = useState<Edits>({});
const [liveSync, setLiveSync] = useState(false);
// The value a limit switched back on returns to: the last one the broker or the slider had.
const [highResLimit, setHighResLimit] = useState(2.5);
const [highResGap, setHighResGap] = useState(1.5);
const { submit, pending, snackbar } = useUpload({
...putConfigSpotFindingMutation(),
onSuccess: () => update(),
});
// An edit is done once the broker reports the same value (after Upload, live sync, or another
// client setting it); a rejected one stays and keeps the panel marked as unsaved.
useEffect(() => {
if (serverS === undefined)
return;
setEdits(e => pendingEdits(e, serverS));
if (serverS.high_resolution_limit !== undefined)
setHighResLimit(serverS.high_resolution_limit);
if (serverS.high_res_gap_Q_recipA !== undefined)
setHighResGap(serverS.high_res_gap_Q_recipA);
}, [serverS]);
if (serverS === undefined)
return (
<SettingsPanel title="Spot finding parameters" sx={{ minHeight: 800 }} snackbar={snackbar}>
<Typography sx={{ opacity: 0.7 }}>Waiting for the broker's settings ...</Typography>
</SettingsPanel>
);
const s: spot_finding_settings = {...serverS, ...edits};
const dirty = !_.isEmpty(pendingEdits(edits, serverS));
// A slider being dragged only moves the panel; MUI fires onChange for every intermediate position.
const preview = (patch: Edits) => setEdits(e => ({...e, ...patch}));
// A finished change: kept as an edit, and sent at once only with live sync engaged.
const commit = (patch: Edits) => {
const next = {...edits, ...patch};
setEdits(next);
if (liveSync)
submit({...serverS, ...next});
};
const toggle = (label: string, checked: boolean, onChange: (checked: boolean) => void, disabled = !s.enable) =>
<FormControlLabel label={label} disabled={disabled}
control={<Switch checked={checked} onChange={(e) => onChange(e.target.checked)}/>}/>;
return (
<SettingsPanel title="Spot finding parameters" sx={{ minHeight: 800 }} snackbar={snackbar} dirty={dirty}
onUpload={() => submit({...serverS, ...edits})} uploadDisabled={!dirty || pending}
actions={<>
<Button variant="outlined" disabled={!dirty} onClick={() => setEdits({})}>Revert</Button>
{/* Engaged only from a clean panel, so live sync never sends edits made before it. */}
<FormControlLabel label="Live sync" disabled={dirty && !liveSync}
control={<Switch checked={liveSync}
onChange={(e) => setLiveSync(e.target.checked)}/>}/>
</>}>
<Typography variant="body2" color={liveSync ? "warning.main" : dirty ? "warning.main" : "text.secondary"}>
{liveSync ? "Live sync on: each change is sent to the broker at once"
: dirty ? "Unsaved edits: press Upload to send them, or Revert"
: "Showing the broker's settings"}
</Typography>
<Grid container spacing={0}>
<Grid item xs={1}/>
<Grid item xs={10}>
<Stack alignItems="flex-start">
{toggle("Spot finding", s.enable, (v) => commit({enable: v}), false)}
{/* Rejected by a broker whose detector finds spots on the FPGA: the edit then stays
unsaved and the snackbar says why. */}
{toggle("Adaptive (self-calibrating) threshold", s.adaptive_threshold ?? false,
(v) => commit({adaptive_threshold: v}))}
</Stack>
<Typography variant="caption" display="block" sx={{ opacity: 0.7, mb: 1 }}>
Sets the count threshold per resolution ring from each image's own noise.
Not available where spots are found on the FPGA.
</Typography>
<SettingSlider label="Count threshold" value={Number(s.photon_count_threshold)}
disabled={!s.enable || (s.adaptive_threshold ?? false)}
min={1} max={50} step={1}
onChange={(v) => preview({photon_count_threshold: v})}
onCommit={(v) => commit({photon_count_threshold: v})}/>
<SettingSlider label="False pixels / frame (adaptive operating point)"
value={Number(s.false_pixels_per_frame ?? 100)}
disabled={!s.enable || !(s.adaptive_threshold ?? false)}
min={1} max={1000} step={1}
onChange={(v) => preview({false_pixels_per_frame: v})}
onCommit={(v) => commit({false_pixels_per_frame: v})}/>
<SettingSlider label="Signal-to-noise threshold" value={Number(s.signal_to_noise_threshold)}
disabled={!s.enable} min={2} max={10} step={0.5} digits={1}
onChange={(v) => preview({signal_to_noise_threshold: v})}
onCommit={(v) => commit({signal_to_noise_threshold: v})}/>
<SettingSlider label="Minimum pixel / spot" value={Number(s.min_pix_per_spot)}
disabled={!s.enable} min={1} max={8} step={1}
onChange={(v) => preview({min_pix_per_spot: v})}
onCommit={(v) => commit({min_pix_per_spot: v})}/>
<SettingSlider label={<>Low resolution limit [&#8491;]</>} value={Number(s.low_resolution_limit)}
disabled={!s.enable} min={10} max={100} step={0.1} digits={1}
onChange={(v) => preview({low_resolution_limit: v})}
onCommit={(v) => commit({low_resolution_limit: v})}/>
{/* No high-resolution limit means spot finding goes as far as the detector reaches. */}
{toggle("To detector edge", s.high_resolution_limit === undefined,
(v) => commit({high_resolution_limit: v ? undefined : highResLimit}))}
<SettingSlider label={<>High resolution limit [&#8491;]</>}
value={Number(s.high_resolution_limit ?? highResLimit)}
disabled={!s.enable || s.high_resolution_limit === undefined}
min={1} max={5} step={0.1} digits={1}
onChange={(v) => { setHighResLimit(v); preview({high_resolution_limit: v}); }}
onCommit={(v) => commit({high_resolution_limit: v})}/>
<SettingSlider label={<>High resolution limit for counting low resolution spots [&#8491;]</>}
value={Number(s.high_resolution_limit_for_spot_count_low_res)}
disabled={!s.enable} min={2} max={8} step={0.1} digits={1}
onChange={(v) => preview({high_resolution_limit_for_spot_count_low_res: v})}
onCommit={(v) => commit({high_resolution_limit_for_spot_count_low_res: v})}/>
<SettingSlider label={<>Ice ring width in Q-space [&#8491;<sup>-1</sup>]</>}
value={Number(s.ice_ring_width_q_recipA)}
disabled={!s.enable} min={0.0} max={0.2} step={0.001} digits={3}
onChange={(v) => preview({ice_ring_width_q_recipA: v})}
onCommit={(v) => commit({ice_ring_width_q_recipA: v})}/>
{toggle("High-res gap Q-space filter", s.high_res_gap_Q_recipA !== undefined,
(v) => commit({high_res_gap_Q_recipA: v ? highResGap : undefined}))}
<SettingSlider label={<>High-res gap [&#8491;<sup>-1</sup>]</>}
value={Number(s.high_res_gap_Q_recipA ?? highResGap)}
disabled={!s.enable || s.high_res_gap_Q_recipA === undefined}
min={0.1} max={5.0} step={0.01} digits={2}
onChange={(v) => { setHighResGap(v); preview({high_res_gap_Q_recipA: v}); }}
onCommit={(v) => commit({high_res_gap_Q_recipA: v})}/>
<Stack alignItems="flex-start" sx={{ mt: 2 }}>
{toggle("Indexing", s.indexing, (v) => commit({indexing: v}))}
</Stack>
</Grid>
<Grid item xs={1}/>
</Grid>
</SettingsPanel>
);
}
export default memo(DataProcessingSettings);