Beam-stop shadow detection, and a low-resolution limit for scaling

rugnux finds the beam stop and its holder in a projection of 60 images and
marks them in the pixel mask as bit 9 (--detect-beam-stop[=N|off], on by
default). Reflections behind the stop are attenuated but not flagged, so they
integrate low with a plausible sigma and nothing downstream catches them: the
signal-box gate requires 100% valid pixels and shadow pixels are valid, the
background clip is high-side only, and the |zeta| cut applies only to the
space-group search merge.

The detection compares each pixel's background against the typical background
at the same radius on two channels. An azimuthal one (the ring median) finds
the holder arm, which is a minority of its ring; a radial one (the background
just outside) finds the disk, which the ring median cannot see because inside a
fully blocked ring the median is the shadow itself. Pixels are pooled over a
5x5 box and tested only where the background has actually been counted, so
low-background data no longer masks the whole detector. Recorded reflections
are carved back out - a beam stop cannot block a reflection that was measured.

Bit 9 belongs to the run that found it, not to the dataset: it is cleared when
a run starts, so a mask read back from a file that carries one starts clear.
The user mask (bit 8) is left alone.

Scaling and merging gain a low-resolution limit, default 50 A
(--scaling-low-resolution <num>, 0 removes it), applied per observation before
scaling so it also protects the per-frame scale fit and the space-group search.
50 A is the value XDS configurations use; rugnux_vs_xds.py now matches both of
XDS's resolution limits instead of only the high one, so the lowest shell is
the same shell in the two programs.

The viewer draws the detected shadow in coral with a "Show beam stop" switch in
the side panel, exposes the low-resolution limit in the settings dock, and
offers detection in its processing jobs. Adding an image marker meant giving
the reader a MIN_REAL_PXL_VALUE, because several places classify a pixel by
range rather than by equality and would otherwise read the new marker as a very
negative intensity.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-09 01:05:31 +02:00
co-authored by Claude Opus 5
parent c673521b76
commit a29c36600f
45 changed files with 562 additions and 196 deletions
+15 -3
View File
@@ -97,6 +97,8 @@ void JFJochDiffractionImage::mouseHover(const QPointF &coord, Qt::KeyboardModifi
intensity_str = " Gap ";
else if (intensity == ERROR_PXL_VALUE)
intensity_str = " Bad pxl ";
else if (intensity == BEAM_STOP_PXL_VALUE)
intensity_str = " Beam stop ";
emit writeStatusBar(QString("x=%1 y=%2 %3 d=%4 Å")
.arg(coord.x(), 0, 'f', 1)
@@ -134,13 +136,15 @@ void JFJochDiffractionImage::ColorRow(size_t y, const PixelColorMap &map, QRgb *
for (size_t x = 0; x < W; ++x) {
const int32_t v = row[x];
// The three sentinels are the extremes of the int32 range, so one range test
// separates them from every real pixel value
// The markers occupy the extremes of the int32 range, so one range test separates them
// from every real pixel value (MIN_REAL_PXL_VALUE moves when a marker is added)
rgb c;
if (v > GAP_PXL_VALUE && v < SATURATED_PXL_VALUE)
if (v >= MIN_REAL_PXL_VALUE && v < SATURATED_PXL_VALUE)
c = map.Apply(static_cast<float>(v));
else if (v == GAP_PXL_VALUE)
c = map.gap;
else if (v == BEAM_STOP_PXL_VALUE)
c = map.beam_stop;
else
c = (v == ERROR_PXL_VALUE) ? map.bad : map.saturated;
@@ -975,6 +979,12 @@ void JFJochDiffractionImage::showSaturation(bool input) {
updateOverlay();
}
void JFJochDiffractionImage::showBeamStop(bool input) {
show_beam_stop = input;
RenderImage();
updateOverlay();
}
void JFJochDiffractionImage::highlightIceRings(bool input) {
highlight_ice_rings = input;
updateOverlay();
@@ -1008,6 +1018,8 @@ QString JFJochDiffractionImage::PixelLabel(int x, int y) const {
return QStringLiteral("Gap");
if (v == ERROR_PXL_VALUE)
return QStringLiteral("Err");
if (v == BEAM_STOP_PXL_VALUE)
return QStringLiteral("Stop");
if (v == SATURATED_PXL_VALUE)
return QStringLiteral("Sat");
return QString::number(v);