Merge branch 'worktree-agent-aa55c81220288558b' into grid-scan-integration

# Conflicts:
#	common/ScanResultGenerator.cpp
#	docs/CBOR.md
#	docs/HDF5.md
#	frame_serialize/CBORStream2Deserializer.cpp
#	frame_serialize/CBORStream2Serializer.cpp
#	writer/HDF5DataFilePluginMX.cpp
#	writer/HDF5DataFilePluginMX.h
#	writer/HDF5NXmx.cpp
This commit is contained in:
leonarski_f committed 2026-09-08 07:54:46 +02:00
commit 36a082c2f8
36 files changed
+286 -134

No files matched your search

+5 -3
View File
@@ -899,7 +899,9 @@ PlotType ConvertPlotType(const std::optional<std::string>& input) {
"Plot type is compulsory paramater");
if (input == "bkg_estimate") return PlotType::BkgEstimate;
if (input == "spindle_blind_fraction") return PlotType::SpindleBlindFraction;
if (input == "ice_ring_score") return PlotType::IceRingScore;
// ice_ring_score is the retired spelling of ice_ring_ratio, kept so existing clients keep
// working; both name the same plot.
if (input == "ice_ring_ratio" || input == "ice_ring_score") return PlotType::IceRingRatio;
if (input == "protein_score") return PlotType::ProteinScore;
if (input == "ice_score") return PlotType::IceScore;
if (input == "azint") return PlotType::AzInt;
@@ -1152,8 +1154,8 @@ org::openapitools::server::model::Scan_result Convert(const ScanResult& input) {
tmp.setSpots(i.spot_count.value());
if (i.spot_count_ice.has_value())
tmp.setSpotsIce(i.spot_count_ice.value());
if (i.ice_ring_score.has_value())
tmp.setIce(i.ice_ring_score.value());
if (i.ice_ring_ratio.has_value())
tmp.setIce(i.ice_ring_ratio.value());
if (i.protein_score.has_value())
tmp.setProteinScore(i.protein_score.value());
if (i.ice_score.has_value())
+1
View File
@@ -121,6 +121,7 @@ components:
- image_scale_factor
- image_scale_cc
- compression_ratio
- ice_ring_ratio
- ice_ring_score
- protein_score
- ice_score
+3 -3
View File
@@ -178,12 +178,12 @@ float AzimuthalIntegrationProfile::GetBkgEstimate(const AzimuthalIntegrationSett
return GetMeanValueOfBins(min_bin, max_bin);
}
float AzimuthalIntegrationProfile::GetIceRingScore(const AzimuthalIntegrationSettings &settings,
float AzimuthalIntegrationProfile::GetIceRingRatio(const AzimuthalIntegrationSettings &settings,
float half_width_q) const {
return IceRingScore(GetResult1D(), q_bins, settings, half_width_q);
return IceRingRatio(GetResult1D(), q_bins, settings, half_width_q);
}
float AzimuthalIntegrationProfile::IceRingScore(const std::vector<float> &profile, int32_t q_bins,
float AzimuthalIntegrationProfile::IceRingRatio(const std::vector<float> &profile, int32_t q_bins,
const AzimuthalIntegrationSettings &settings,
float half_width_q) {
// Strongest hexagonal-ice ring's intensity relative to the background *under* it (1 = no ice). The
+2 -2
View File
@@ -46,11 +46,11 @@ public:
float GetBkgEstimate(const AzimuthalIntegrationSettings& settings) const;
// Single per-image ice indicator: the strongest hexagonal-ice ring's intensity relative to the smooth
// radial background interpolated under it (1 = no ice, >1 = ice). See the .cpp for the background fit.
float GetIceRingScore(const AzimuthalIntegrationSettings& settings, float half_width_q) const;
float GetIceRingRatio(const AzimuthalIntegrationSettings& settings, float half_width_q) const;
// The same score for a radial profile that is not this object's: the adaptive spot finder computes a
// peak-excluded per-ring background in these same bins, which is a much cleaner input (see the .cpp).
// profile is q_bins long, or q_bins x azimuthal bins, in which case it is averaged over azimuth first.
static float IceRingScore(const std::vector<float>& profile, int32_t q_bins,
static float IceRingRatio(const std::vector<float>& profile, int32_t q_bins,
const AzimuthalIntegrationSettings& settings, float half_width_q);
MultiLinePlot GetPlot(bool force_1d = false, PlotAzintUnit plot_unit = PlotAzintUnit::Q_recipA) const;
AzimuthalIntegrationProfile& operator+=(const AzimuthalIntegrationProfile& profile); // Not thread safe
+12 -8
View File
@@ -114,7 +114,7 @@ struct DataMessage {
// bands' own q width - so spot_count_ice_rings / spot_count_ice_control is 1 when spots are spread
// evenly and > 1 when they pile up on the rings. Pooled over the run (a ratio of two per-image
// counts this small is meaningless on its own image), it is the second ice channel: TEXTURED ice
// arrives as discrete spots and leaves the radial profile - and so ice_ring_score - flat.
// arrives as discrete spots and leaves the radial profile - and so ice_ring_ratio - flat.
std::optional<float> spot_count_ice_control;
std::optional<int64_t> spot_count_low_res;
@@ -127,7 +127,11 @@ struct DataMessage {
std::vector<uint64_t> az_int_profile_count;
std::optional<float> bkg_estimate;
std::optional<float> ice_ring_score; // strongest ice ring over the smooth radial background (1 = none)
// Strongest ice ring over the smooth radial background. A RATIO, so 1 means no ice and it is
// unbounded above - the opposite convention to the two *_score members below, which is why the
// name says ratio. Wire key "ice_ring_ratio", dataset /entry/MX/iceRingRatio; both readers also
// accept the retired "ice_ring_score"/iceRingScore spellings.
std::optional<float> ice_ring_ratio;
// How much of a single sweep's blind cone this orientation makes unrecoverable: 0 = one sweep
// about the spindle reaches everything the point group can give, 1 = a short lattice row lies on
// the spindle and the whole cone is lost coherently - each shell losing its own 1 - cos theta(d),
@@ -140,7 +144,7 @@ struct DataMessage {
// Two DETECTION scores in [0,1], saturating: is there protein diffraction on this image, and is
// there crystalline ice. Not quality measures - resolution, B factor and the indexing rate say how
// good the diffraction is, and neither the spot count nor the resolution enters either score as a
// term. ice_score answers the question ice_ring_score above only reports on: it combines the radial
// term. ice_score answers the question ice_ring_ratio above only reports on: it combines the radial
// powder evidence with a spot excess on the ice radii, and it saturates, so it can be thresholded.
// Both are computed from the geometry's beam centre; see image_analysis/IceScore.h and
// image_analysis/spot_finding/SpotUtils.h.
@@ -470,12 +474,12 @@ struct EndMessage {
std::vector<float> image_scale_factor;
std::vector<float> image_scale_cc;
std::vector<float> image_scale_mosaicity;
// Per-image ice strength. Note the name carries no v_ prefix, unlike v_bkg_estimate above - it
// was shipped that way and the CBOR key is part of the stream format.
std::vector<float> ice_ring_score;
// Per-image ice ring ratio (1 = no ice). Note the name carries no v_ prefix, unlike
// v_bkg_estimate above - it was shipped that way and the CBOR key is part of the stream format.
std::vector<float> ice_ring_ratio;
// Run mean of the above, the single "how icy was this dataset" number (1 = no ice). The
// bkg_estimate scalar's counterpart; written to /entry/MX/iceRingScoreMean.
std::optional<float> ice_ring_score_mean;
// bkg_estimate scalar's counterpart; written to /entry/MX/iceRingRatioMean.
std::optional<float> ice_ring_ratio_mean;
// Per-image sweep-quality code: 0 = the image falls in no flagged range, otherwise 1 + the
// SweepQualityReason of the range it falls in (image_analysis/scale_merge/Merge.h). Written to
+10 -10
View File
@@ -62,7 +62,7 @@ void JFJochReceiverPlots::Setup(const DiffractionExperiment &experiment, const A
}
bkg_estimate.Clear(r);
spindle_blind_fraction.Clear(r);
ice_ring_score.Clear(r);
ice_ring_ratio.Clear(r);
protein_score.Clear(r);
ice_score.Clear(r);
spot_count.Clear(r);
@@ -132,7 +132,7 @@ void JFJochReceiverPlots::Setup(const DiffractionExperiment &experiment, const A
void JFJochReceiverPlots::Add(const DataMessage &msg, const AzimuthalIntegrationProfile &profile) {
bkg_estimate.AddElement(msg.number, msg.bkg_estimate);
spindle_blind_fraction.AddElement(msg.number, msg.spindle_blind_fraction);
ice_ring_score.AddElement(msg.number, msg.ice_ring_score);
ice_ring_ratio.AddElement(msg.number, msg.ice_ring_ratio);
protein_score.AddElement(msg.number, msg.protein_score);
ice_score.AddElement(msg.number, msg.ice_score);
resolution_estimate.AddElement(msg.number, msg.resolution_estimate);
@@ -286,8 +286,8 @@ MultiLinePlot JFJochReceiverPlots::GetPlots(const PlotRequest &request) {
case PlotType::SpindleBlindFraction:
ret = spindle_blind_fraction.GetMeanPlot(nbins, start, incr, request.fill_value);
break;
case PlotType::IceRingScore:
ret = ice_ring_score.GetMeanPlot(nbins, start, incr, request.fill_value);
case PlotType::IceRingRatio:
ret = ice_ring_ratio.GetMeanPlot(nbins, start, incr, request.fill_value);
break;
case PlotType::ProteinScore:
ret = protein_score.GetMeanPlot(nbins, start, incr, request.fill_value);
@@ -520,16 +520,16 @@ std::optional<float> JFJochReceiverPlots::GetIceRingSpotRatio() const {
return ring / control;
}
std::optional<float> JFJochReceiverPlots::GetIceRingScore() const {
auto tmp = ice_ring_score.Mean();
std::optional<float> JFJochReceiverPlots::GetIceRingRatio() const {
auto tmp = ice_ring_ratio.Mean();
if (std::isfinite(tmp))
return tmp;
else
return {};
}
std::vector<float> JFJochReceiverPlots::GetIceRingScoreArray() const {
return ice_ring_score.ExportArray();
std::vector<float> JFJochReceiverPlots::GetIceRingRatioArray() const {
return ice_ring_ratio.ExportArray();
}
std::optional<float> JFJochReceiverPlots::GetProteinScore() const {
@@ -623,8 +623,8 @@ void JFJochReceiverPlots::GetPlotRaw(std::vector<float> &v, PlotType type, const
case PlotType::SpindleBlindFraction:
v = spindle_blind_fraction.ExportArray();
break;
case PlotType::IceRingScore:
v = ice_ring_score.ExportArray();
case PlotType::IceRingRatio:
v = ice_ring_ratio.ExportArray();
break;
case PlotType::ProteinScore:
v = protein_score.ExportArray();
+3 -3
View File
@@ -43,7 +43,7 @@ class JFJochReceiverPlots {
StatusVector bkg_estimate;
StatusVector spindle_blind_fraction;
StatusVector ice_ring_score;
StatusVector ice_ring_ratio;
StatusVector protein_score;
StatusVector ice_score;
StatusVector spot_count;
@@ -127,7 +127,7 @@ public:
std::optional<float> GetBkgEstimate() const;
// Run mean of the per-image spindle severity, over the frames that had one; nothing when none did.
std::optional<float> GetSpindleBlindFraction() const;
std::optional<float> GetIceRingScore() const;
std::optional<float> GetIceRingRatio() const;
// Pooled over the run: spots on the hexagonal rings over the same q width of ice-free control
// flanks. 1 = spots spread evenly, > 1 = they pile up on the rings (textured ice).
[[nodiscard]] std::optional<float> GetIceRingSpotRatio() const;
@@ -135,7 +135,7 @@ public:
// not a mean - a few blank or badly-shot frames pull a mean a long way and leave the median where
// the run actually is.
[[nodiscard]] std::optional<float> GetResolutionEstimate() const;
std::vector<float> GetIceRingScoreArray() const;
std::vector<float> GetIceRingRatioArray() const;
// Run means of the two per-image detection scores, and the per-image arrays behind them.
[[nodiscard]] std::optional<float> GetProteinScore() const;
[[nodiscard]] std::optional<float> GetIceScore() const;
+1 -1
View File
@@ -15,7 +15,7 @@ enum class PlotType {
ROISum, ROIMean, ROIMaxCount, ROIPixels, ROIWeightedX, ROIWeightedY, PacketsReceived, MaxValue,
ResolutionEstimate, ProfileRadius, Mosaicity, BFactor, PixelSum, StrongPixels,
RefinementBeamX, RefinementBeamY, ImageProcessingTime, IntegratedReflections,
ImageScaleFactor, ImageScaleCC, CompressionRatio, IndexingLatticeCount, IceRingScore,
ImageScaleFactor, ImageScaleCC, CompressionRatio, IndexingLatticeCount, IceRingRatio,
ProteinScore, IceScore
};
+1 -1
View File
@@ -70,7 +70,7 @@ class ScalingSettings {
// better on weak. --no-expected-variance-merge restores the old observed-sigma weighting.
bool expected_variance_merge = true;
// Minimum measured ice strength (iceRingScore, 1 = no ice) before any ice-ring handling is applied
// Minimum measured ice strength (iceRingRatio, 1 = no ice) before any ice-ring handling is applied
// at all. The eleven fixed hexagonal bands cover 16-26% of the unique reflections at typical
// resolutions REGARDLESS of whether the crystal has ice, so flagging unconditionally taxes clean
// data for nothing. 0 disables the gate (always handle ice, the previous behaviour).
+1 -1
View File
@@ -44,7 +44,7 @@ struct ScanResultElem {
std::optional<int64_t> integrated_reflections;
std::optional<float> image_scale_factor;
std::optional<float> image_scale_cc;
std::optional<float> ice_ring_score;
std::optional<float> ice_ring_ratio;
std::optional<float> protein_score;
std::optional<float> ice_score;
};
+3 -3
View File
@@ -64,7 +64,7 @@ void ScanResultGenerator::Add(const DataMessage &message) {
v[image_number].integrated_reflections = message.integrated_reflections;
v[image_number].image_scale_factor = message.image_scale_factor;
v[image_number].image_scale_cc = message.image_scale_cc;
v[image_number].ice_ring_score = message.ice_ring_score;
v[image_number].ice_ring_ratio = message.ice_ring_ratio;
v[image_number].protein_score = message.protein_score;
v[image_number].ice_score = message.ice_score;
if (message.lattice_type)
@@ -119,7 +119,7 @@ void ScanResultGenerator::FillEndMessage(EndMessage &message) const {
message.error_pixel_count.resize(n);
message.image_scale_factor.resize(n, NAN);
message.image_scale_cc.resize(n, NAN);
message.ice_ring_score.resize(n, NAN);
message.ice_ring_ratio.resize(n, NAN);
message.v_protein_score.resize(n, NAN);
message.v_ice_score.resize(n, NAN);
message.integrated_reflections.resize(n);
@@ -154,7 +154,7 @@ void ScanResultGenerator::FillEndMessage(EndMessage &message) const {
message.error_pixel_count[number] = static_cast<int32_t>(value_or_zero(e.err_pixels));
message.image_scale_factor[number] = e.image_scale_factor.value_or(NAN);
message.image_scale_cc[number] = e.image_scale_cc.value_or(NAN);
message.ice_ring_score[number] = e.ice_ring_score.value_or(NAN);
message.ice_ring_ratio[number] = e.ice_ring_ratio.value_or(NAN);
message.v_protein_score[number] = e.protein_score.value_or(NAN);
message.v_ice_score[number] = e.ice_score.value_or(NAN);
message.integrated_reflections[number] = static_cast<int32_t>(value_or_zero(e.integrated_reflections));
+3 -3
View File
@@ -226,7 +226,7 @@ See [DECTRIS documentation](https://github.com/dectris/documentation/tree/main/s
| packets_expected | uint64 | Number of packets expected per image (in units of 2 kB) | | |
| packets_received | uint64 | Number of packets received per image (in units of 2 kB) | | |
| bkg_estimate | float | Mean value for pixels in resolution range from 3.0 to 5.0 A \[photons\] | | |
| ice_ring_score | float | Strongest hexagonal-ice ring intensity over the smooth radial background (1 = no ice) | | |
| ice_ring_ratio | float | Strongest hexagonal-ice ring intensity over the smooth radial background (1 = no ice). Was `ice_ring_score`; readers accept both, producers emit this one | | |
| protein_score | float | Protein diffraction detection score, 0 to 1, saturating (0 = none, 1 = certain) | | |
| ice_score | float | Crystalline ice detection score, 0 to 1, saturating (0 = none, 1 = certain) | | |
| spindle_blind_fraction | float | Fraction (0-1) of a rotation sweep's blind cone this orientation makes unrecoverable, as a lone-2-fold worst-case bound; >= 0.5 should engage a recovery protocol, and ABSENT means the frame could not be assessed, which automation must treat the same way | | |
@@ -324,11 +324,11 @@ See [DECTRIS documentation](https://github.com/dectris/documentation/tree/main/s
| image_indexed | Array(uint8) | Per-image indexing result; 0 = not indexed, nonzero = indexed | |
| v_bkg_estimate | Array(float) | Per-image background estimate | |
| v_spindle_blind_fraction | Array(float) | Per-image spindle_blind_fraction; NaN where the frame had no value (which is "cannot say", not zero) | |
| ice_ring_score | Array(float) | Per-image strongest ice-ring intensity over the smooth radial background (1 = no ice) | |
| ice_ring_ratio | Array(float) | Per-image strongest ice-ring intensity over the smooth radial background (1 = no ice). Was `ice_ring_score`; readers accept both | |
| v_protein_score | Array(float) | Per-image protein diffraction detection score, 0 to 1 | |
| v_ice_score | Array(float) | Per-image crystalline ice detection score, 0 to 1 | |
| spot_count_ice_control | Array(float) | Per-image spot count in the ice-free flanks beside the hexagonal rings, rescaled to the ring bands' q width | |
| ice_ring_score_mean | float | Mean ice-ring score for the whole run (1 = no ice) | |
| ice_ring_ratio_mean | float | Mean ice-ring ratio for the whole run (1 = no ice). Was `ice_ring_score_mean`; readers accept both | |
| protein_score | float | Mean protein detection score for the whole run | |
| ice_score | float | Mean ice detection score for the whole run | |
| profile_radius | Array(float) | Per-image profile radius \[Angstrom^-1\] | |
+27
View File
@@ -34,6 +34,33 @@ across them and are the ones the rest of the documentation cites.
twinning and translational pseudo-symmetry, the resolution cutoff, diffraction anisotropy, and
model-based validation.
## Naming: score, ratio, count
Per-image quantities are named for the *kind* of number they are, because several of them describe
the same physics on opposite conventions and the name is the only thing that says which:
| Suffix | Range | What 1 means | Examples |
|---|---|---|---|
| `*_score` | bounded, 0 to 1, saturating | **certainly present** | `protein_score`, `ice_score` |
| `*_ratio` | unbounded above | **none** | `ice_ring_ratio`, the ice-band spot ratio |
| `*_count` | integer | one occurrence | `spot_count`, `spot_count_ice_rings`, `spot_count_ice_control` |
So a score is bounded and 1 is certainty; a ratio is unbounded and 1 is nothing. `ice_score` and
`ice_ring_ratio` both describe ice and their extremes are opposite ends of the scale.
The identifiers, the stored names and the wire names all follow it. The ice ring ratio was called
`ice_ring_score` before; nothing that reads an old file or an old stream lost anything in the rename:
| Surface | Now | Retired spelling |
|---|---|---|
| HDF5 | `/entry/MX/iceRingRatio`, `iceRingRatioMean` | `iceRingScore`, `iceRingScoreMean` — **still read**, so a file written before the rename still opens |
| CBOR | `ice_ring_ratio`, `ice_ring_ratio_mean` | `ice_ring_score`, `ice_ring_score_mean` — **still decoded**, so an older producer's stream still reads |
| REST `plot_type` | `ice_ring_ratio` | `ice_ring_score` — **still accepted**, and not scheduled for removal; both name the same plot |
| CLI | `--ice-min-score` | *unchanged*, deliberately. It is a threshold on the ratio, and it is the one surface a user types |
Writers and producers emit the new spelling only. The old one is read but never written, which is
what makes the rename a one-way migration rather than a flag day.
## References
The methods draw on, and in places reimplement, solutions from:
+2 -2
View File
@@ -427,7 +427,7 @@ Both constants carry a mechanism. A quantile from the middle of the distribution
### 3.7 Detection scores: is there protein here, is there ice here
`iceRingScore` above is a *magnitude* — a ratio, unbounded, answering "how strong is the worst ring".
`iceRingRatio` above is a *magnitude* — a ratio, unbounded, answering "how strong is the worst ring".
Two further per-image scalars answer a different question, the one a grid scan actually asks:
`proteinScore` and `iceScore`, both in $[0,1]$ and both **saturating**, so a superb crystal and a
barely-diffracting one score the same. They are **detection** scores, not quality measures — the
@@ -450,7 +450,7 @@ the pooled false-positive rate over the remaining ones below $5\times10^{-4}$.
**Ice** reaches the frame two ways, and they need different evidence, so two channels are computed
and the stronger one wins. The *radial* channel reads the plain azimuthal profile — not the
peak-excluded background the `iceRingScore` uses, because it needs the profile's own standard
peak-excluded background the `iceRingRatio` uses, because it needs the profile's own standard
deviation, which that background does not carry. Each band is read as an excess over a running
median (half-window 6 bins, which rejects a 3–5 bin powder ring but follows the ~40-bin vitreous
halo, so the halo cannot score), in units of the bin mean's own error $\sigma/\sqrt{n}$ smoothed
+2 -2
View File
@@ -345,7 +345,7 @@ In legacy/VDS mode these live in the data files and are linked/virtual-stacked i
| `resolutionEstimate` | Å | resolution the merged data are predicted to reach, from this image's spots alone |
| `integratedReflections` | | number of integrated reflections |
| `bkgEstimate` | photons | mean background in the 3–5 Å resolution band |
| `iceRingScore` | ratio | strongest hexagonal-ice ring intensity over the smooth radial background (1 = no ice) |
| `iceRingRatio` | ratio | strongest hexagonal-ice ring intensity over the smooth radial background (1 = no ice). Was `iceRingScore`; the reader accepts either, so a file written before the rename still opens |
| `proteinScore` | | protein diffraction detection score, 0 to 1, saturating (0 = none, 1 = certain) |
| `iceScore` | | crystalline ice detection score, 0 to 1, saturating (0 = none, 1 = certain) |
| `spindleBlindFraction` | fraction (0-1) | how much of a rotation sweep's blind cone this orientation makes unrecoverable, as a lone-2-fold worst-case bound; NaN = the frame could not be assessed, which automation must treat like a value at or above the 0.5 trigger, never as 0 |
@@ -372,7 +372,7 @@ variants.
| `bkgEstimateMean` | photons | mean background over the run |
| `spindleBlindFractionMean` | fraction (0-1) | mean `spindleBlindFraction` over the frames that had one |
| `spindleLostUniqueFraction` | fraction (0-1) | unique reflections (to the run's resolution limit) the mounting made unmeasurable, exact under the measured point group and indexed orientation; offline (rugnux) only |
| `iceRingScoreMean` | ratio | mean `iceRingScore` over the run — the single "how icy was this dataset" number (1 = no ice) |
| `iceRingRatioMean` | ratio | mean `iceRingRatio` over the run — the single "how icy was this dataset" number (1 = no ice). Was `iceRingScoreMean` |
| `proteinScoreMean` | | mean `proteinScore` over the run |
| `iceScoreMean` | | mean `iceScore` over the run |
| `scoreBeamCenterX`, `scoreBeamCenterY` | pixel | the beam centre `proteinScore` and `iceScore` were computed with. Both read *d* out of the geometry, and `/entry/instrument/detector/beam_center_x`/`_y` carries the **refined** centre where refinement ran, so without this pair a rescoring could not tell an algorithm disagreement from a geometry one |
+9 -6
View File
@@ -822,8 +822,10 @@ namespace {
message.packets_received = GetCBORUInt(value);
else if (key == "bkg_estimate")
message.bkg_estimate = GetCBORFloat(value);
else if (key == "ice_ring_score")
message.ice_ring_score = GetCBORFloat(value);
// Renamed from ice_ring_score; both spellings are accepted so a stream from an older
// producer still decodes. Optional keys are back-compatible either way, so no version bump.
else if (key == "ice_ring_ratio" || key == "ice_ring_score")
message.ice_ring_ratio = GetCBORFloat(value);
else if (key == "protein_score")
message.protein_score = GetCBORFloat(value);
else if (key == "ice_score")
@@ -1517,12 +1519,13 @@ namespace {
message.ice_score = GetCBORFloat(value);
else if (key == "v_spindle_blind_fraction")
GetCBORFloatArray(value, message.v_spindle_blind_fraction);
else if (key == "ice_ring_score")
GetCBORFloatArray(value, message.ice_ring_score);
// Both spellings, as in the image block above.
else if (key == "ice_ring_ratio" || key == "ice_ring_score")
GetCBORFloatArray(value, message.ice_ring_ratio);
else if (key == "spot_count_ice_control")
GetCBORFloatArray(value, message.spot_count_ice_control);
else if (key == "ice_ring_score_mean")
message.ice_ring_score_mean = GetCBORFloat(value);
else if (key == "ice_ring_ratio_mean" || key == "ice_ring_score_mean")
message.ice_ring_ratio_mean = GetCBORFloat(value);
else if (key == "profile_radius")
GetCBORFloatArray(value, message.profile_radius);
else if (key == "mosaicity")
+3 -3
View File
@@ -829,8 +829,8 @@ void CBORStream2Serializer::SerializeSequenceEnd(const EndMessage& message) {
CBOR_ENC(mapEncoder, "protein_score", message.protein_score);
CBOR_ENC(mapEncoder, "ice_score", message.ice_score);
CBOR_ENC(mapEncoder, "v_spindle_blind_fraction", message.v_spindle_blind_fraction);
CBOR_ENC(mapEncoder, "ice_ring_score", message.ice_ring_score);
CBOR_ENC(mapEncoder, "ice_ring_score_mean", message.ice_ring_score_mean);
CBOR_ENC(mapEncoder, "ice_ring_ratio", message.ice_ring_ratio);
CBOR_ENC(mapEncoder, "ice_ring_ratio_mean", message.ice_ring_ratio_mean);
CBOR_ENC(mapEncoder, "spot_count_ice_control", message.spot_count_ice_control);
CBOR_ENC(mapEncoder, "profile_radius", message.profile_radius);
CBOR_ENC(mapEncoder, "mosaicity", message.mosaicity);
@@ -926,7 +926,7 @@ void CBORStream2Serializer::SerializeImageInternal(CborEncoder &mapEncoder, cons
CBOR_ENC(mapEncoder, "packets_expected", message.packets_expected);
CBOR_ENC(mapEncoder, "packets_received", message.packets_received);
CBOR_ENC(mapEncoder, "bkg_estimate", message.bkg_estimate);
CBOR_ENC(mapEncoder, "ice_ring_score", message.ice_ring_score);
CBOR_ENC(mapEncoder, "ice_ring_ratio", message.ice_ring_ratio);
CBOR_ENC(mapEncoder, "protein_score", message.protein_score);
CBOR_ENC(mapEncoder, "ice_score", message.ice_score);
CBOR_ENC(mapEncoder, "spindle_blind_fraction", message.spindle_blind_fraction);
@@ -52,6 +52,7 @@ function AxisTypeY(plot: plot_type) : string | ReactNode {
case plot_type.SPOT_COUNT_INDEXED:
case plot_type.SPOT_COUNT_ICE:
return "Count";
case plot_type.ICE_RING_RATIO:
case plot_type.ICE_RING_SCORE:
return "Ratio";
case plot_type.PROTEIN_SCORE:
@@ -50,7 +50,7 @@ function DataProcessingPlots({type: initialType, height}: MyProps) {
<MenuItem value={plot_type.SPOT_COUNT_LOW_RES}>Spot count low res.</MenuItem>
<MenuItem value={plot_type.SPOT_COUNT_INDEXED}>Spot count indexed</MenuItem>
<MenuItem value={plot_type.SPOT_COUNT_ICE}>Spot count ice ring</MenuItem>
<MenuItem value={plot_type.ICE_RING_SCORE}>Ice ring score</MenuItem>
<MenuItem value={plot_type.ICE_RING_RATIO}>Ice ring ratio</MenuItem>
<MenuItem value={plot_type.PROTEIN_SCORE}>Protein detection score</MenuItem>
<MenuItem value={plot_type.ICE_SCORE}>Ice detection score</MenuItem>
<MenuItem value={plot_type.AZINT}>Azimuthal integration profile</MenuItem>
+46 -28
View File
@@ -26,18 +26,17 @@ namespace {
constexpr float Z_CAP = 6.0f;
// The conventional 3-sigma detection maps to a score of 0.5.
constexpr float S_HALF = 3.0f;
// Half-width of a band, in q. A mis-set beam centre smears and splits a ring, so the best bin
// within this distance is taken rather than the one the geometry predicts.
constexpr float BAND_HALF_Q = 0.012f;
// How far either side of a predicted band the radial channel looks for the bin that carries it.
// This is NOT a second band half-width competing with the spot channel's half_width_q: it is a
// tolerance for a mis-set beam centre, which smears and splits a ring, and it is set a priori from
// the measured centre error (+-0.6 % in d) rather than fitted. There is one band width in this
// file, and it is the pipeline's ice_ring_width_Q_recipA, passed in.
constexpr float CENTRE_SMEAR_Q = 0.012f;
// Bins nearer than this to a band of EITHER phase are not part of the null.
constexpr float NULL_EXCLUSION_Q = 0.025f;
// Fewer null bins than this and the null is not measured.
constexpr int NULL_MIN_BINS = 20;
// Band half-width for the spot channel, in q. Wider than the spot finder's own ice marking width
// (ice_ring_width_Q_recipA, 0.03): measured, 0.03 costs 5 pp of specificity on protein frames for
// no gain on ice, because a wider band collects more of the crystal's own reflections.
constexpr float SPOT_BAND_HALF_Q = 0.02f;
// How far a band may be slid for its control, and in what steps.
constexpr float SPOT_OFFSET_MAX_Q = 0.45f;
constexpr float SPOT_OFFSET_STEP_Q = 0.0025f;
@@ -144,20 +143,20 @@ namespace {
return std::min(sum, 1.0);
}
// Live pixels within +-SPOT_BAND_HALF_Q of q.
double AreaAt(const std::vector<double> &count_q, float low_q, float dq, float q) {
// Live pixels within +-w of q.
double AreaAt(const std::vector<double> &count_q, float low_q, float dq, float q, float w) {
double area = 0.0;
const int lo = static_cast<int>(std::ceil((q - SPOT_BAND_HALF_Q - low_q) / dq - 0.5f));
const int hi = static_cast<int>(std::floor((q + SPOT_BAND_HALF_Q - low_q) / dq - 0.5f));
const int lo = static_cast<int>(std::ceil((q - w - low_q) / dq - 0.5f));
const int hi = static_cast<int>(std::floor((q + w - low_q) / dq - 0.5f));
for (int i = std::max(lo, 0); i <= std::min(hi, static_cast<int>(count_q.size()) - 1); i++)
area += count_q[i];
return area;
}
// Spots within +-SPOT_BAND_HALF_Q of q, from the sorted spot q list.
double CountAt(const std::vector<float> &sorted_q, float q) {
const auto lo = std::lower_bound(sorted_q.begin(), sorted_q.end(), q - SPOT_BAND_HALF_Q);
const auto hi = std::upper_bound(sorted_q.begin(), sorted_q.end(), q + SPOT_BAND_HALF_Q);
// Spots within +-w of q, from the sorted spot q list.
double CountAt(const std::vector<float> &sorted_q, float q, float w) {
const auto lo = std::lower_bound(sorted_q.begin(), sorted_q.end(), q - w);
const auto hi = std::upper_bound(sorted_q.begin(), sorted_q.end(), q + w);
return static_cast<double>(std::distance(lo, hi));
}
}
@@ -186,7 +185,7 @@ float IceScoreRadial(const std::vector<float> &profile, const std::vector<float>
const std::vector<float> background = RunningMedian(prof, BACKGROUND_HALF_WINDOW);
const std::vector<float> sigma_smooth = RunningMedian(sigma, SIGMA_HALF_WINDOW);
const int bh = std::max(1, static_cast<int>(std::lround(BAND_HALF_Q / dq)));
const int bh = std::max(1, static_cast<int>(std::lround(CENTRE_SMEAR_Q / dq)));
auto q_of = [&](int i) { return low_q + (static_cast<float>(i) + 0.5f) * dq; };
// Per-bin excess in units of the bin mean's own error, floored so that only a real excess counts.
@@ -260,11 +259,11 @@ float IceScoreRadial(const std::vector<float> &profile, const std::vector<float>
}
float IceScoreSpots(const std::vector<SpotToSave> &spots, const std::vector<uint64_t> &profile_count,
int32_t q_bins, const AzimuthalIntegrationSettings &settings) {
int32_t q_bins, const AzimuthalIntegrationSettings &settings, float half_width_q) {
const int nq = std::max<int>(q_bins, 0);
const float low_q = settings.GetLowQ_recipA();
const float dq = settings.GetQSpacing_recipA();
if (nq < 2 || !(dq > 0.0f) || spots.empty() || profile_count.empty())
if (nq < 2 || !(dq > 0.0f) || !(half_width_q > 0.0f) || spots.empty() || profile_count.empty())
return 0.0f;
const std::vector<double> count_q = FoldCountToQ(profile_count, nq);
@@ -282,23 +281,23 @@ float IceScoreSpots(const std::vector<SpotToSave> &spots, const std::vector<uint
double k0 = 0.0, mu = 0.0, var = 0.0;
for (const float qb: band_q) {
const double area_band = AreaAt(count_q, low_q, dq, qb);
const double area_band = AreaAt(count_q, low_q, dq, qb, half_width_q);
if (!(area_band > 0.0))
continue;
std::vector<double> control;
for (float delta = 2.0f * SPOT_BAND_HALF_Q; delta <= SPOT_OFFSET_MAX_Q; delta += SPOT_OFFSET_STEP_Q) {
for (float delta = 2.0f * half_width_q; delta <= SPOT_OFFSET_MAX_Q; delta += SPOT_OFFSET_STEP_Q) {
// An offset that lands on another ice band is not a control.
float nearest = 1e9f;
for (const float qo: band_q)
nearest = std::min(nearest, std::min(std::fabs(qb + delta - qo), std::fabs(qb - delta - qo)));
if (nearest < 2.0f * SPOT_BAND_HALF_Q)
if (nearest < 2.0f * half_width_q)
continue;
const double area_hi = AreaAt(count_q, low_q, dq, qb + delta);
const double area_lo = AreaAt(count_q, low_q, dq, qb - delta);
const double area_hi = AreaAt(count_q, low_q, dq, qb + delta, half_width_q);
const double area_lo = AreaAt(count_q, low_q, dq, qb - delta, half_width_q);
if (area_hi < SPOT_MIN_AREA_FRACTION * area_band || area_lo < SPOT_MIN_AREA_FRACTION * area_band)
continue;
control.push_back(0.5 * area_band * (CountAt(spot_q, qb + delta) / area_hi
+ CountAt(spot_q, qb - delta) / area_lo));
control.push_back(0.5 * area_band * (CountAt(spot_q, qb + delta, half_width_q) / area_hi
+ CountAt(spot_q, qb - delta, half_width_q) / area_lo));
}
if (static_cast<int>(control.size()) < SPOT_MIN_OFFSETS)
continue;
@@ -309,7 +308,7 @@ float IceScoreSpots(const std::vector<SpotToSave> &spots, const std::vector<uint
double m2 = 0.0;
for (const double v: control)
m2 += (v - mean) * (v - mean);
k0 += CountAt(spot_q, qb);
k0 += CountAt(spot_q, qb, half_width_q);
mu += mean;
var += m2 / static_cast<double>(control.size());
}
@@ -327,7 +326,26 @@ float IceScoreSpots(const std::vector<SpotToSave> &spots, const std::vector<uint
float IceScore(const std::vector<float> &profile, const std::vector<float> &profile_std,
const std::vector<uint64_t> &profile_count, int32_t q_bins,
const AzimuthalIntegrationSettings &settings, const std::vector<SpotToSave> &spots) {
const AzimuthalIntegrationSettings &settings, const std::vector<SpotToSave> &spots,
float half_width_q) {
// The larger of the two, deliberately, and this is a decided question rather than an open one.
//
// The radial channel cannot see ice that arrives as large crystallites: that ice diffracts as
// discrete spots and leaves the profile flat, so there is no radial evidence to read. Removing the
// spot channel would make the score blind to the regime the second channel exists for, by
// construction and not merely on this corpus.
//
// Measured over the corpus, the maximum takes the fraction of frames called icy in the protein
// classes labelled clean from 7% (radial alone) to 16%. That looks like a specificity cost and is
// not yet known to be one: the loops where the spot channel is the ONLY detector are precisely the
// ones whose ice status the labels do not settle, and several loops labelled clean - and three of
// four water loops - were independently found to carry a full hexagonal pattern. Until the corpus
// is relabelled from measurement rather than from directory names, the corpus cannot say whether
// those frames are false positives or correct detections nobody had recorded.
//
// If the rate does have to come down afterwards, the lever is to drop each hypothesis's worst band
// before scoring it (measured on the prototype: clean protein 20.5 -> 12.2%, ice 88.8 -> ~83%), not
// to remove a channel.
return std::max(IceScoreRadial(profile, profile_std, profile_count, q_bins, settings),
IceScoreSpots(spots, profile_count, q_bins, settings));
IceScoreSpots(spots, profile_count, q_bins, settings, half_width_q));
}
+11 -3
View File
@@ -31,6 +31,10 @@
// null, an amplitude and a band-count concordance, and the SMALLER is taken: a single elevated bin then
// fails, because real ice shows a whole pattern.
//
// This channel takes no band width: it reads the single bin the geometry predicts, searched over a small
// tolerance for the beam-centre error (see CENTRE_SMEAR_Q in the .cpp). The one band width in this file
// is the spot channel's, and it is the pipeline's.
//
// profile / profile_std / profile_count are q_bins long, or q_bins x azimuthal bins, in which case the
// first two are averaged over azimuth and the third summed. The scale of an excess is the bin MEAN's own
// error, std / sqrt(count) - the profile is a mean of many pixels, so its plain standard deviation is
@@ -52,10 +56,14 @@ float IceScoreRadial(const std::vector<float> &profile, const std::vector<float>
//
// profile_count is the azimuthal integration's live pixel count per bin, q_bins long or q_bins x
// azimuthal bins; it is what makes the offsets comparable where the detector edge cuts a radius short.
// half_width_q is the band half-width, the same one the spot finder marks ice rings with
// (SpotFindingSettings::ice_ring_width_Q_recipA) - one width, measured over the corpus, not two.
float IceScoreSpots(const std::vector<SpotToSave> &spots, const std::vector<uint64_t> &profile_count,
int32_t q_bins, const AzimuthalIntegrationSettings &settings);
int32_t q_bins, const AzimuthalIntegrationSettings &settings, float half_width_q);
// The score itself: whichever channel sees more.
// The score itself: whichever channel sees more. See the .cpp for why the maximum and not something
// gentler, and for the lever to reach for if the rate ever has to come down.
float IceScore(const std::vector<float> &profile, const std::vector<float> &profile_std,
const std::vector<uint64_t> &profile_count, int32_t q_bins,
const AzimuthalIntegrationSettings &settings, const std::vector<SpotToSave> &spots);
const AzimuthalIntegrationSettings &settings, const std::vector<SpotToSave> &spots,
float half_width_q);
+5 -4
View File
@@ -179,10 +179,10 @@ void MXAnalysisWithoutFPGA::Analyze(DataMessage &output,
const std::vector<float> &ring_bkg = adaptiveSpotFinder->GetRingBackground();
if (ring_bkg.empty())
return;
output.ice_ring_score = AzimuthalIntegrationProfile::IceRingScore(
output.ice_ring_ratio = AzimuthalIntegrationProfile::IceRingRatio(
ring_bkg, integration.GetQBinCount(), integration.Settings(),
spot_finding_settings.ice_ring_width_Q_recipA);
bragg_engine->BackgroundRadial(*output.ice_ring_score
bragg_engine->BackgroundRadial(*output.ice_ring_ratio
>= experiment.GetScalingSettings().GetIceMinScore());
};
@@ -289,7 +289,7 @@ void MXAnalysisWithoutFPGA::Analyze(DataMessage &output,
const std::vector<float> &ring_bkg = adaptiveSpotFinder->GetRingBackground();
const bool have_ring_bkg = spot_finding_settings.enable && spot_finding_settings.adaptive_threshold
&& !ring_bkg.empty();
output.ice_ring_score = AzimuthalIntegrationProfile::IceRingScore(
output.ice_ring_ratio = AzimuthalIntegrationProfile::IceRingRatio(
have_ring_bkg ? ring_bkg : profile.GetResult1D(), integration.GetQBinCount(),
integration.Settings(), spot_finding_settings.ice_ring_width_Q_recipA);
@@ -298,7 +298,8 @@ void MXAnalysisWithoutFPGA::Analyze(DataMessage &output,
// carry. Its second channel reads the spots, which SpotAnalyze has already put in the message.
output.ice_score = IceScore(output.az_int_profile, output.az_int_profile_std,
output.az_int_profile_count, integration.GetQBinCount(),
integration.Settings(), output.spots);
integration.Settings(), output.spots,
spot_finding_settings.ice_ring_width_Q_recipA);
}
ImageSpotFinder &MXAnalysisWithoutFPGA::FixedThresholdFinder() {
+19 -7
View File
@@ -575,7 +575,12 @@ HDF5MetadataSource::OpenResult HDF5MetadataSource::Open(const std::string &filen
dataset->indexing_result = master_file->ReadOptVector<float>("/entry/MX/imageIndexed");
dataset->bkg_estimate = master_file->ReadOptVector<float>("/entry/MX/bkgEstimate");
dataset->spindle_blind_fraction = master_file->ReadOptVector<float>("/entry/MX/spindleBlindFraction");
dataset->ice_ring_score = master_file->ReadOptVector<float>("/entry/MX/iceRingScore");
// Renamed from iceRingScore. Accept either for backward compatibility - a file
// written before the rename must still read, and --mode scale reads this to
// reproduce the ice gate the writing run applied.
dataset->ice_ring_ratio = master_file->ReadOptVector<float>("/entry/MX/iceRingRatio");
if (dataset->ice_ring_ratio.empty())
dataset->ice_ring_ratio = master_file->ReadOptVector<float>("/entry/MX/iceRingScore");
dataset->protein_score = master_file->ReadOptVector<float>("/entry/MX/proteinScore");
dataset->ice_score = master_file->ReadOptVector<float>("/entry/MX/iceScore");
dataset->score_beam_center_x = master_file->GetOptFloat("/entry/MX/scoreBeamCenterX");
@@ -726,8 +731,11 @@ HDF5MetadataSource::OpenResult HDF5MetadataSource::Open(const std::string &filen
data_file, "/entry/MX/spindleBlindFraction",
number_of_images, fimages);
ReadVector(dataset->ice_ring_score,
data_file, "/entry/MX/iceRingScore",
// Either spelling, as in the master above.
ReadVector(dataset->ice_ring_ratio,
data_file,
data_file.Exists("/entry/MX/iceRingRatio")
? "/entry/MX/iceRingRatio" : "/entry/MX/iceRingScore",
number_of_images, fimages);
ReadVector(dataset->protein_score,
@@ -1380,11 +1388,15 @@ void HDF5MetadataSource::FillPerImage(DataMessage &message, int64_t requested_im
if (dataset->spindle_blind_fraction.size() > image_number
&& std::isfinite(dataset->spindle_blind_fraction[image_number]))
message.spindle_blind_fraction = dataset->spindle_blind_fraction[image_number];
if (dataset->ice_ring_score.size() > image_number)
message.ice_ring_score = dataset->ice_ring_score[image_number];
if (dataset->protein_score.size() > image_number)
if (dataset->ice_ring_ratio.size() > image_number)
message.ice_ring_ratio = dataset->ice_ring_ratio[image_number];
// Same convention as spindle_blind_fraction above: a frame that produced no score is stored as
// NaN, and 0 is a real answer ("nothing detected here"), so a missing one has to come back absent
// rather than as a NaN that a threshold would then compare against.
if (dataset->protein_score.size() > image_number
&& std::isfinite(dataset->protein_score[image_number]))
message.protein_score = dataset->protein_score[image_number];
if (dataset->ice_score.size() > image_number)
if (dataset->ice_score.size() > image_number && std::isfinite(dataset->ice_score[image_number]))
message.ice_score = dataset->ice_score[image_number];
if (dataset->efficiency.size() > image_number)
message.image_collection_efficiency = dataset->efficiency[image_number];
+1 -1
View File
@@ -58,7 +58,7 @@ struct JFJochReaderDataset {
std::vector<float> bkg_estimate;
// NaN entries are frames with no value (CANNOT SAY), not zeros.
std::vector<float> spindle_blind_fraction;
std::vector<float> ice_ring_score;
std::vector<float> ice_ring_ratio;
// The two per-image detection scores, in [0,1] and saturating: is there protein diffraction on
// this image, and is there crystalline ice. From /entry/MX/proteinScore and /entry/MX/iceScore;
// empty when the file predates them. score_beam_center_x/y is the beam centre they were computed
+1 -1
View File
@@ -163,7 +163,7 @@ void JFJochReceiver::SendEndMessage() {
message.bkg_estimate = plots.GetBkgEstimate();
message.spindle_blind_fraction = plots.GetSpindleBlindFraction();
message.ice_ring_score_mean = plots.GetIceRingScore();
message.ice_ring_ratio_mean = plots.GetIceRingRatio();
message.protein_score = plots.GetProteinScore();
message.ice_score = plots.GetIceScore();
message.indexing_rate = plots.GetIndexingRate();
+3 -2
View File
@@ -435,7 +435,7 @@ void JFJochReceiverFPGA::FrameTransformationThread(uint32_t threadid) {
if (force_cpu_azint)
message.az_int_profile_std = az_int_profile_image.GetStd();
message.bkg_estimate = az_int_profile_image.GetBkgEstimate(experiment.GetAzimuthalIntegrationSettings());
message.ice_ring_score = az_int_profile_image.GetIceRingScore(
message.ice_ring_ratio = az_int_profile_image.GetIceRingRatio(
experiment.GetAzimuthalIntegrationSettings(), spot_finding_settings.ice_ring_width_Q_recipA);
// The radial channel of the ice score needs the profile's standard deviation, which the
// FPGA azimuthal integration does not produce - it abstains there and only the spot
@@ -443,7 +443,8 @@ void JFJochReceiverFPGA::FrameTransformationThread(uint32_t threadid) {
message.ice_score = IceScore(message.az_int_profile, message.az_int_profile_std,
message.az_int_profile_count,
experiment.GetAzimuthalIntegrationSettings().GetQBinCount(),
experiment.GetAzimuthalIntegrationSettings(), message.spots);
experiment.GetAzimuthalIntegrationSettings(), message.spots,
spot_finding_settings.ice_ring_width_Q_recipA);
scan_result.Add(message);
+10 -9
View File
@@ -3440,13 +3440,14 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
msg.az_int_profile_count = profile.GetPixelCount();
msg.az_int_profile_std = profile.GetStd();
msg.bkg_estimate = profile.GetBkgEstimate(mapping.Settings());
msg.ice_ring_score = profile.GetIceRingScore(mapping.Settings(),
msg.ice_ring_ratio = profile.GetIceRingRatio(mapping.Settings(),
config_.spot_finding.ice_ring_width_Q_recipA);
// Azimuthal integration only: no spots were looked for, so the radial channel is all the
// ice score has.
msg.ice_score = IceScore(msg.az_int_profile, msg.az_int_profile_std,
msg.az_int_profile_count, mapping.GetQBinCount(),
mapping.Settings(), msg.spots);
mapping.Settings(), msg.spots,
config_.spot_finding.ice_ring_width_Q_recipA);
msg.run_number = experiment_.GetRunNumber();
msg.run_name = experiment_.GetRunName();
@@ -3651,8 +3652,8 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
end_msg.bkg_estimate = plots.GetBkgEstimate();
end_msg.spindle_blind_fraction = plots.GetSpindleBlindFraction();
result.spot_resolution_estimate_A = plots.GetResolutionEstimate();
end_msg.ice_ring_score = plots.GetIceRingScoreArray();
end_msg.ice_ring_score_mean = plots.GetIceRingScore();
end_msg.ice_ring_ratio = plots.GetIceRingRatioArray();
end_msg.ice_ring_ratio_mean = plots.GetIceRingRatio();
end_msg.v_protein_score = plots.GetProteinScoreArray();
end_msg.v_ice_score = plots.GetIceScoreArray();
end_msg.protein_score = plots.GetProteinScore();
@@ -3720,24 +3721,24 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
// ring over the smooth radial background, measured on the peak-excluded profile so Bragg peaks
// cannot pose as ice). The score is logged either way, so a run that gates off still reports why.
// Ice is looked for on TWO channels, because it arrives in two forms. Fine-grained ice is a
// smooth powder ring and shows up in the radial profile (ice_ring_score). Ice in large
// smooth powder ring and shows up in the radial profile (ice_ring_ratio). Ice in large
// crystallites arrives as discrete reflections instead, leaves the profile flat, and is only
// visible as a pile-up of found SPOTS on the ring positions - measured against the same q width
// of ice-free flanks beside them, so the fall-off of spot density with resolution cancels. On
// the rotation battery the two channels barely overlap: the crystals with smooth ice read
// 2.1-2.4 / ~1.0, the ones whose spots are mostly ice read ~1.1 / 3.8-14.6, and a clean crystal
// reads 1.04 on both. Either channel alone is blind to half the cases.
const auto ice_score = plots.GetIceRingScore();
const auto ice_ring_ratio = plots.GetIceRingRatio();
const auto ice_spot_ratio = plots.GetIceRingSpotRatio();
const float ice_min_score = experiment_.GetScalingSettings().GetIceMinScore();
const float ice_min_spot_ratio = experiment_.GetScalingSettings().GetIceMinSpotRatio();
const bool ice_present = (!ice_score.has_value() || *ice_score >= ice_min_score)
const bool ice_present = (!ice_ring_ratio.has_value() || *ice_ring_ratio >= ice_min_score)
|| (ice_min_spot_ratio > 0.0f && ice_spot_ratio.has_value()
&& *ice_spot_ratio >= ice_min_spot_ratio);
if (experiment_.IsDetectIceRings() && !ice_present) {
logger.Info("Ice-ring handling: measured ice score {:.2f} < {:.2f} and spot ratio {:.2f} < "
"{:.2f}, no ice detected - ice-ring handling skipped entirely",
*ice_score, ice_min_score, ice_spot_ratio.value_or(NAN), ice_min_spot_ratio);
*ice_ring_ratio, ice_min_score, ice_spot_ratio.value_or(NAN), ice_min_spot_ratio);
} else if (experiment_.IsDetectIceRings()) {
const float ice_width = config_.spot_finding.ice_ring_width_Q_recipA;
size_t total = 0, flagged = 0;
@@ -3752,7 +3753,7 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
logger.Info("Ice-ring handling: ice score {:.2f} (gate {:.2f}), spot ratio {:.2f} (gate "
"{:.2f}); flagged {} of {} reflections on ice rings (half-width {:.3f} A^-1); "
"excluded from scaling, kept for merging",
ice_score.value_or(NAN), ice_min_score, ice_spot_ratio.value_or(NAN),
ice_ring_ratio.value_or(NAN), ice_min_score, ice_spot_ratio.value_or(NAN),
ice_min_spot_ratio, flagged, total, ice_width);
}
+3 -2
View File
@@ -1711,11 +1711,12 @@ static int RunRugnux(int argc, char **argv) {
// otherwise --scale re-scales a dataset the writing run had scaled without those reflections,
// and the per-image scales come out of a different fit than the ones in the file.
const float ice_width = SpotFindingSettings().ice_ring_width_Q_recipA;
// ...and gated the same way, on the per-image ice score the writing run stored in the file, so
// ...and gated the same way, on the per-image ice ring ratio the writing run stored in the file,
// so
// --scale reaches the same verdict on the same data as the pipeline that produced it.
double ice_sum = 0.0;
size_t ice_n = 0;
for (const float s : dataset->ice_ring_score)
for (const float s : dataset->ice_ring_ratio)
if (std::isfinite(s)) {
ice_sum += s;
++ice_n;
+8 -8
View File
@@ -547,10 +547,10 @@ TEST_CASE("AzimuthalIntegrationMapping_Threading_ConvertedGeometry_18Modules", "
CheckAzimuthalIntegrationMappingThreadingExact(x);
}
// The ice score on an explicit profile: flat means no ice (1.0), and a bump planted on a hexagonal
// The ice ring ratio on an explicit profile: flat means no ice (1.0), and a bump planted on a hexagonal
// ring is reported at its own height over the background. Uses the static entry point, which is what
// feeds the score the peak-excluded per-ring background instead of the plain profile.
TEST_CASE("AzimuthalIntegrationProfile_IceRingScore","[AzimuthalIntegration]") {
TEST_CASE("AzimuthalIntegrationProfile_IceRingRatio","[AzimuthalIntegration]") {
AzimuthalIntegrationSettings settings;
settings.QSpacing_recipA(0.01f).QRange_recipA(0.1f, 4.5f);
@@ -563,21 +563,21 @@ TEST_CASE("AzimuthalIntegrationProfile_IceRingScore","[AzimuthalIntegration]") {
};
std::vector<float> profile(q_bins, 100.0f);
CHECK(AzimuthalIntegrationProfile::IceRingScore(profile, q_bins, settings, 0.03f) == Catch::Approx(1.0f));
CHECK(AzimuthalIntegrationProfile::IceRingRatio(profile, q_bins, settings, 0.03f) == Catch::Approx(1.0f));
// A bump at the 2.249 A hexagonal ring, on a background the running median still reads as 100.
profile[bin_of(2.249f)] = 250.0f;
CHECK(AzimuthalIntegrationProfile::IceRingScore(profile, q_bins, settings, 0.03f) == Catch::Approx(2.5f));
CHECK(AzimuthalIntegrationProfile::IceRingRatio(profile, q_bins, settings, 0.03f) == Catch::Approx(2.5f));
// A bump of the same size well away from every ring is not ice and must not be reported.
std::vector<float> off_ring(q_bins, 100.0f);
off_ring[bin_of(2.500f)] = 250.0f;
CHECK(AzimuthalIntegrationProfile::IceRingScore(off_ring, q_bins, settings, 0.03f) == Catch::Approx(1.0f));
CHECK(AzimuthalIntegrationProfile::IceRingRatio(off_ring, q_bins, settings, 0.03f) == Catch::Approx(1.0f));
}
// A profile given per (q, azimuth) bin is averaged over azimuth first, so a ring seen in every sector
// scores the same as the equivalent 1-D profile.
TEST_CASE("AzimuthalIntegrationProfile_IceRingScore_Azimuthal","[AzimuthalIntegration]") {
TEST_CASE("AzimuthalIntegrationProfile_IceRingRatio_Azimuthal","[AzimuthalIntegration]") {
AzimuthalIntegrationSettings settings;
settings.QSpacing_recipA(0.01f).QRange_recipA(0.1f, 4.5f).AzimuthalBinCount(4);
@@ -591,6 +591,6 @@ TEST_CASE("AzimuthalIntegrationProfile_IceRingScore_Azimuthal","[AzimuthalIntegr
for (int az = 0; az < 4; az++)
sectors[static_cast<size_t>(az) * q_bins + ring] = 250.0f;
CHECK(AzimuthalIntegrationProfile::IceRingScore(sectors, q_bins, settings, 0.03f)
== Catch::Approx(AzimuthalIntegrationProfile::IceRingScore(flat, q_bins, settings, 0.03f)));
CHECK(AzimuthalIntegrationProfile::IceRingRatio(sectors, q_bins, settings, 0.03f)
== Catch::Approx(AzimuthalIntegrationProfile::IceRingRatio(flat, q_bins, settings, 0.03f)));
}
+70
View File
@@ -1483,3 +1483,73 @@ TEST_CASE("CBORSerialize_End_Transformations", "[CBOR]") {
CHECK(!chain[1].IsConstant());
CHECK(chain[2].IsConstant());
}
namespace {
// "ice_ring_ratio" replaced its predecessor "ice_ring_score", and the two spellings are the same
// length - so an old-format stream is made from a new one by substituting the key text in place,
// leaving the CBOR text-string length prefix correct. That is what lets one test drive the
// deserializer with a stream this serializer can no longer produce.
void RetireIceRingKeySpelling(std::vector<uint8_t> &buffer, size_t size) {
const std::string now = "ice_ring_ratio";
const std::string before = "ice_ring_score";
REQUIRE(now.size() == before.size());
for (size_t i = 0; i + now.size() <= size; i++)
if (std::equal(now.begin(), now.end(), buffer.begin() + i))
std::copy(before.begin(), before.end(), buffer.begin() + i);
}
// Serialize an image and an end message carrying the ice ring ratio, optionally rewriting the key
// to the retired spelling, and return what the deserializer makes of each.
std::pair<DataMessage, EndMessage> IceRingRatioRoundTrip(bool old_spelling) {
std::vector<uint16_t> pixels(512, 7);
const CompressedImage image(pixels, 256, 2);
std::vector<uint8_t> buffer(1024 * 1024);
CBORStream2Serializer image_serializer(buffer.data(), buffer.size());
DataMessage msg{.number = 11, .image = image};
msg.ice_ring_ratio = 2.75f;
REQUIRE_NOTHROW(image_serializer.SerializeImage(msg));
if (old_spelling)
RetireIceRingKeySpelling(buffer, image_serializer.GetBufferSize());
auto image_out = CBORStream2Deserialize(buffer.data(), image_serializer.GetBufferSize());
REQUIRE(image_out);
REQUIRE(image_out->data_message);
std::vector<uint8_t> end_buffer(1024 * 1024);
CBORStream2Serializer end_serializer(end_buffer.data(), end_buffer.size());
EndMessage end{.max_image_number = 3};
end.ice_ring_ratio = {1.0f, 2.5f, 4.25f};
end.ice_ring_ratio_mean = 2.5f;
REQUIRE_NOTHROW(end_serializer.SerializeSequenceEnd(end));
if (old_spelling)
RetireIceRingKeySpelling(end_buffer, end_serializer.GetBufferSize());
auto end_out = CBORStream2Deserialize(end_buffer.data(), end_serializer.GetBufferSize());
REQUIRE(end_out);
REQUIRE(end_out->end_message);
return {*image_out->data_message, *end_out->end_message};
}
}
// The spelling this serializer emits.
TEST_CASE("CBORDeserialize_IceRingRatio_NewSpelling", "[CBOR]") {
const auto [image, end] = IceRingRatioRoundTrip(false);
REQUIRE(image.ice_ring_ratio.has_value());
CHECK(image.ice_ring_ratio.value() == Catch::Approx(2.75f));
CHECK(end.ice_ring_ratio == std::vector<float>{1.0f, 2.5f, 4.25f});
REQUIRE(end.ice_ring_ratio_mean.has_value());
CHECK(end.ice_ring_ratio_mean.value() == Catch::Approx(2.5f));
}
// A stream from a producer that predates the rename. It must still decode, and into the same members:
// the writer turns these into the per-image datasets, and rugnux --mode scale reads them back to
// reproduce the ice gate the writing run applied. Silently losing them would not fail here - it would
// change which reflections leave the scale fit, months later.
TEST_CASE("CBORDeserialize_IceRingRatio_RetiredSpelling", "[CBOR]") {
const auto [image, end] = IceRingRatioRoundTrip(true);
REQUIRE(image.ice_ring_ratio.has_value());
CHECK(image.ice_ring_ratio.value() == Catch::Approx(2.75f));
CHECK(end.ice_ring_ratio == std::vector<float>{1.0f, 2.5f, 4.25f});
REQUIRE(end.ice_ring_ratio_mean.has_value());
CHECK(end.ice_ring_ratio_mean.value() == Catch::Approx(2.5f));
}
+8 -6
View File
@@ -9,6 +9,8 @@
namespace {
constexpr float TWO_PI = 6.283185307f;
// The pipeline's own ice band half-width (SpotFindingSettings::ice_ring_width_Q_recipA).
constexpr float ICE_W = 0.03f;
SpotToSave spot(float d_A, float intensity) {
return SpotToSave{.intensity = intensity, .d_A = d_A};
@@ -158,23 +160,23 @@ TEST_CASE("IceScoreSpots_ExcessOnTheIceRadii") {
const float q = q_lo + (q_hi - q_lo) * static_cast<float>(i) / 399.0f;
even.push_back(spot(TWO_PI / q, 1000.0f));
}
CHECK(IceScoreSpots(even, count, q_bins, settings) < 0.5f);
CHECK(IceScoreSpots(even, count, q_bins, settings, ICE_W) < 0.5f);
// The same frame with 10 extra spots planted on each hexagonal radius.
std::vector<SpotToSave> with_ice = even;
for (const float d: ICE_RING_RES_A)
for (int i = 0; i < 10; i++)
with_ice.push_back(spot(d, 1000.0f));
CHECK(IceScoreSpots(with_ice, count, q_bins, settings) > 0.5f);
CHECK(IceScoreSpots(with_ice, count, q_bins, settings, ICE_W) > 0.5f);
// Two spots that both happen to sit on a ring are not ice: the ratio term refuses them even
// though the Poisson tail alone would not.
std::vector<SpotToSave> two;
two.push_back(spot(ICE_RING_RES_A[0], 1000.0f));
two.push_back(spot(ICE_RING_RES_A[1], 1000.0f));
CHECK(IceScoreSpots(two, count, q_bins, settings) < 0.5f);
CHECK(IceScoreSpots(two, count, q_bins, settings, ICE_W) < 0.5f);
CHECK(IceScoreSpots({}, count, q_bins, settings) == 0.0f);
CHECK(IceScoreSpots({}, count, q_bins, settings, ICE_W) == 0.0f);
}
TEST_CASE("IceScore_TakesTheStrongerChannel") {
@@ -190,7 +192,7 @@ TEST_CASE("IceScore_TakesTheStrongerChannel") {
if (b >= 0 && b < q_bins)
powder[b] = 130.0f;
}
CHECK(IceScore(powder, sigma, count, q_bins, settings, {}) > 0.5f);
CHECK(IceScore(powder, sigma, count, q_bins, settings, {}, ICE_W) > 0.5f);
// Ice as discrete crystallites: the profile is flat and only the spot channel sees it.
const std::vector<float> flat(q_bins, 100.0f);
@@ -201,5 +203,5 @@ TEST_CASE("IceScore_TakesTheStrongerChannel") {
for (int i = 0; i < 10; i++)
textured.push_back(spot(d, 1000.0f));
CHECK(IceScoreRadial(flat, sigma, count, q_bins, settings) == 0.0f);
CHECK(IceScore(flat, sigma, count, q_bins, settings, textured) > 0.5f);
CHECK(IceScore(flat, sigma, count, q_bins, settings, textured, ICE_W) > 0.5f);
}
+1 -1
View File
@@ -268,7 +268,7 @@ std::shared_ptr<JFJochReaderDataset> JFJochHttpReader::UpdateDataset_i() {
dataset->bkg_estimate = GetPlot_i("bkg_estimate");
dataset->spindle_blind_fraction = GetPlot_i("spindle_blind_fraction");
dataset->ice_ring_score = GetPlot_i("ice_ring_score");
dataset->ice_ring_ratio = GetPlot_i("ice_ring_score");
dataset->spot_count = GetPlot_i("spot_count");
dataset->spot_count_ice_rings = GetPlot_i("spot_count_ice");
dataset->spot_count_low_res = GetPlot_i("spot_count_low_res");
+1 -1
View File
@@ -237,7 +237,7 @@ std::vector<float> JFJochViewerDatasetInfo::ExtractMetric(const JFJochReaderData
else if (val == 11) data = ds.image_scale_cc;
else if (val == 12) data = ds.integrated_reflections;
else if (val == 13) data = ds.indexing_lattice_count;
else if (val == 14) data = ds.ice_ring_score;
else if (val == 14) data = ds.ice_ring_ratio;
else if (val == 15) data = ds.spindle_blind_fraction;
else if (val >= 100) {
const int roi_index = (val - 100) / 4;
+5 -5
View File
@@ -53,7 +53,7 @@ HDF5DataFilePluginMX::HDF5DataFilePluginMX(const StartMessage &msg)
void HDF5DataFilePluginMX::OpenFile(HDF5File &data_file, const DataMessage &msg, size_t images_per_file) {
bkg_estimate.reserve(images_per_file);
ice_ring_score.reserve(images_per_file);
ice_ring_ratio.reserve(images_per_file);
protein_score.reserve(images_per_file);
ice_score.reserve(images_per_file);
spindle_blind_fraction.reserve(images_per_file);
@@ -102,8 +102,8 @@ void HDF5DataFilePluginMX::OpenFile(HDF5File &data_file, const DataMessage &msg,
void HDF5DataFilePluginMX::Write(const DataMessage &msg, uint64_t image_number) {
if (msg.bkg_estimate.has_value())
bkg_estimate[image_number] = msg.bkg_estimate.value();
if (msg.ice_ring_score.has_value())
ice_ring_score[image_number] = msg.ice_ring_score.value();
if (msg.ice_ring_ratio.has_value())
ice_ring_ratio[image_number] = msg.ice_ring_ratio.value();
if (msg.protein_score.has_value())
protein_score[image_number] = msg.protein_score.value();
if (msg.ice_score.has_value())
@@ -259,8 +259,8 @@ void HDF5DataFilePluginMX::WriteFinal(HDF5File &data_file) {
if (!bkg_estimate.empty())
data_file.SaveVector("/entry/MX/bkgEstimate", bkg_estimate.vec());
if (!ice_ring_score.empty())
data_file.SaveVector("/entry/MX/iceRingScore", ice_ring_score.vec());
if (!ice_ring_ratio.empty())
data_file.SaveVector("/entry/MX/iceRingRatio", ice_ring_ratio.vec());
if (!protein_score.empty())
data_file.SaveVector("/entry/MX/proteinScore", protein_score.vec());
if (!ice_score.empty())
+1 -1
View File
@@ -47,7 +47,7 @@ class HDF5DataFilePluginMX : public HDF5DataFilePlugin {
// bkg_estimate
AutoIncrVector<float> bkg_estimate{NAN};
AutoIncrVector<float> ice_ring_score{NAN};
AutoIncrVector<float> ice_ring_ratio{NAN};
AutoIncrVector<float> protein_score{NAN};
AutoIncrVector<float> ice_score{NAN};
// NaN = the frame had no value (CANNOT SAY), which is not a zero - see SpindleTrigger.
+3 -3
View File
@@ -1186,8 +1186,8 @@ void NXmx::Finalize(const EndMessage &end) {
SaveScalar(*hdf5_file, "/entry/MX/spindleLostUniqueFraction",
end.spindle_lost_unique_fraction.value());
}
if (end.ice_ring_score_mean) {
SaveScalar(*hdf5_file, "/entry/MX/iceRingScoreMean", end.ice_ring_score_mean.value());
if (end.ice_ring_ratio_mean) {
SaveScalar(*hdf5_file, "/entry/MX/iceRingRatioMean", end.ice_ring_ratio_mean.value());
}
if (end.protein_score) {
SaveScalar(*hdf5_file, "/entry/MX/proteinScoreMean", end.protein_score.value());
@@ -1282,7 +1282,7 @@ void NXmx::EndResultVectors(const EndMessage &end) {
SaveVectorIfMissing(*hdf5_file, "/entry/MX/proteinScore", end.v_protein_score);
SaveVectorIfMissing(*hdf5_file, "/entry/MX/iceScore", end.v_ice_score);
SaveVectorIfMissing(*hdf5_file, "/entry/MX/spindleBlindFraction", end.v_spindle_blind_fraction);
SaveVectorIfMissing(*hdf5_file, "/entry/MX/iceRingScore", end.ice_ring_score);
SaveVectorIfMissing(*hdf5_file, "/entry/MX/iceRingRatio", end.ice_ring_ratio);
SaveVectorIfMissing(*hdf5_file, "/entry/MX/profileRadius", end.profile_radius, "Angstrom^-1");
SaveVectorIfMissing(*hdf5_file, "/entry/MX/mosaicity", end.mosaicity, "deg");
SaveVectorIfMissing(*hdf5_file, "/entry/MX/bFactor", end.bFactor, "Angstrom^2");