Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 9m1s
Build Packages / build:windows:nocuda (push) Successful in 17m30s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 17m40s
Build Packages / build:windows:cuda (push) Successful in 19m6s
Build Packages / build:viewer-tgz:cpu (push) Successful in 19m33s
Build Packages / build:viewer-tgz:cuda (push) Successful in 22m6s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 24m27s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 27m36s
Build Packages / build:rugnux:windows (push) Successful in 10m46s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 20m0s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 28m55s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 22m7s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 25m28s
Build Packages / build:rpm (rocky9) (push) Successful in 23m43s
Build Packages / build:rpm (rocky8) (push) Successful in 27m55s
Build Packages / Generate python client (push) Successful in 44s
Build Packages / Build documentation (push) Successful in 1m19s
Build Packages / Create release (push) Skipped
Build Packages / XDS test (durin plugin) (push) Successful in 11m28s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 24m21s
Build Packages / DIALS test (push) Successful in 25m16s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 11m29s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 27m14s
Build Packages / XDS test (neggia plugin) (push) Successful in 8m18s
Build Packages / Unit tests (push) Successful in 1h25m13s
--max-spots was a fixed 1000, and on a rotation sweep it sets the DENOMINATOR of
the per-frame acceptance gate, which admits a frame when at least a fifth of its
spots index. Detections are not all reflections: on a strongly diffracting
crystal with heavy solvent background there are 2372 a frame, 1416 of them on
ice bands, and only 178 index - so a budget that takes essentially the whole
list puts the entire frame population on the gate (median indexed fraction
0.271, tenth percentile 0.218) and the run integrates 83% of its images. The
same run with a smaller budget gains 211 frames and loses none, and the frames
it gains are the ones with the MOST detections. That is how a larger budget
integrates fewer images.
So measure it: over the first pass's validation frames, with the sweep's lattice
known, tally each spot by rank as +1 if it lies on the lattice and take the
budget at
argmax over N of n_indexed(N) - 0.20 * n_counted(N)
which rises exactly while spots at that depth index better than the gate's own
floor and falls after. The 0.20 is that floor, not a new constant - it is lifted
out of the function-local it already lived in. It means: as deep into the
intensity-ordered list as the image is still showing reflections of THIS crystal.
The argmax alone would not do. Under the null that spots index at the same rate
at every depth the tally is a driftless random walk, whose maximum is positive
whatever the data, so a bare argmax shortens every dataset. The budget therefore
has to clear the walk's own noise: the quantity it acts on is the fall from the
peak to the end of the list, which is that walk read backwards, and the
reflection principle gives its null law in closed form -
P(fall > z*sqrt(g(1-g)T)) = 2(1-Phi(z)). That already pays for the search over
ranks, so nothing further is owed to multiple comparisons. One false cut in a
thousand measurements - a twelfth of one over a 39-crystal two-pass corpus -
fixes z at 3.29. The level was chosen before the rule was written and was not
revisited afterwards.
Battery, same build, one changed default: 36/39 space groups in both arms, none
lost, and 36 of the 39 crystals BIT-IDENTICAL. Two move materially - the strong
crystal by +17.4% observations and +35.9 points of CC1/2 at 1.58 A, its indexing
rate 83.4 -> 95.1%, and another by +93.5% observations with completeness
76.6 -> 98.4%. The significance requirement is what makes that list clean: it
removed the one crystal the unguarded rule regressed, and with it two of the
five gains, whose peaks do not clear 3.29 sigma on 60 frames. The lever for
those is the sample and not the threshold - power grows as the root of the frame
count while the bar stays where it is.
Rotation only, and the first-pass lattice search always sees the full list: a
fixed --max-spots 250 would have been much cheaper to write and fails a battery
crystal outright, starving the de-novo FFT into a wrong cell that indexes 7 of
60 frames. Stills never reach the code path - verified bit-identical merged
reflections on a serial set - and --max-spots N still pins it, as does the
library default the broker and the FPGA use.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FBumeJVx4oeXxiBRpkrE5H
122 lines
6.2 KiB
C++
122 lines
6.2 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../image_analysis/spot_finding/SpotUtils.h"
|
|
#include "../image_analysis/indexing/AnalyzeIndexing.h"
|
|
|
|
TEST_CASE("FilterSpuriousHighResolutionSpots") {
|
|
std::vector<SpotToSave> spots;
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 18.0, .indexed = false});
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 20.0, .indexed = false});
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 30.0, .indexed = false});
|
|
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 6.0, .indexed = false});
|
|
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 2.0, .indexed = false});
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 1.9, .indexed = false});
|
|
spots.push_back(SpotToSave{.x = 1, .y = 2, .intensity = 3, .d_A = 1.3, .indexed = false});
|
|
|
|
FilterSpuriousHighResolutionSpots(spots, 1.57); // roughly 0.25 in 1/d
|
|
|
|
REQUIRE(spots.size() == 4);
|
|
// Spots are sorted by resolution
|
|
CHECK(spots[0].d_A == Catch::Approx(30.0));
|
|
CHECK(spots[1].d_A == Catch::Approx(20.0));
|
|
CHECK(spots[2].d_A == Catch::Approx(18.0));
|
|
CHECK(spots[3].d_A == Catch::Approx(6.0));
|
|
}
|
|
|
|
|
|
TEST_CASE("GetResolution") {
|
|
// Eleven equally strong spots at 1/d^2 = 0.1, 0.2, ... 1.1. Walking in from the highest-resolution
|
|
// one, four of the eleven are the first to carry 30% of the weight, so the quantile is the fourth
|
|
// spot in, 1/d^2 = 0.8. The estimate is that resolution taken 2.25x further in 1/d.
|
|
std::vector<SpotToSave> spots;
|
|
for (int i = 1; i <= 11; i++)
|
|
spots.push_back(SpotToSave{.intensity = 100.0f, .d_A = 1.0f / std::sqrt(0.1f * static_cast<float>(i))});
|
|
const auto d = GetResolution(spots);
|
|
REQUIRE(d.has_value());
|
|
CHECK(*d == Catch::Approx(1.0 / (2.25 * std::sqrt(0.8))).epsilon(1e-4));
|
|
|
|
// The answer is not limited to what a detector records. Keeping only the five spots a detector
|
|
// reaching 1/d^2 = 0.5 would have recorded leaves the quantile at 0.4, and the estimate still
|
|
// extrapolates 2.25x past it instead of stopping at the cut.
|
|
const std::vector<SpotToSave> cut(spots.begin(), spots.begin() + 5);
|
|
CHECK(*GetResolution(cut) == Catch::Approx(1.0 / (2.25 * std::sqrt(0.4))).epsilon(1e-4));
|
|
|
|
// Ice-flagged spots take no part, however strong they are.
|
|
std::vector<SpotToSave> with_ice = spots;
|
|
with_ice.push_back(SpotToSave{.intensity = 1e6f, .d_A = 0.5f, .ice_ring = true});
|
|
CHECK(*GetResolution(with_ice) == Catch::Approx(*d));
|
|
|
|
// A weak high-resolution spot moves the answer far less than a strong one, which is the point of
|
|
// weighting by sqrt(I) rather than counting: the old order statistic would follow it entirely.
|
|
std::vector<SpotToSave> with_spur = spots;
|
|
with_spur.push_back(SpotToSave{.intensity = 1.0f, .d_A = 0.5f});
|
|
CHECK(*GetResolution(with_spur) == Catch::Approx(*d).epsilon(0.02));
|
|
|
|
// Too few spots to have a fall-off at all.
|
|
CHECK_FALSE(GetResolution(std::vector<SpotToSave>(3)).has_value());
|
|
}
|
|
|
|
TEST_CASE("SpotBudgetFromEvidence") {
|
|
// One image's worth of spots, repeated over 60 frames as the first pass does: the first 100 index
|
|
// and the next 100 do not. Every indexed spot adds 1 - 0.2 and every unindexed one takes 0.2 away,
|
|
// so the running tally rises to rank 100 and falls after it.
|
|
std::vector<SpotToSave> spots(200);
|
|
for (size_t i = 0; i < spots.size(); i++)
|
|
spots[i].indexed = i < 100;
|
|
|
|
constexpr int frames = 60;
|
|
std::vector<int64_t> indexed(spots.size(), 0), counted(spots.size(), 0);
|
|
for (int f = 0; f < frames; f++)
|
|
AddSpotBudgetEvidence(spots, false, indexed, counted);
|
|
CHECK(SpotBudgetFromEvidence(indexed, counted) == 100);
|
|
|
|
// Spots that go on indexing all the way down: the tally never falls, so there is nothing to cut.
|
|
for (auto &s: spots)
|
|
s.indexed = true;
|
|
std::vector<int64_t> all_hit(spots.size(), 0), all_seen(spots.size(), 0);
|
|
for (int f = 0; f < frames; f++)
|
|
AddSpotBudgetEvidence(spots, false, all_hit, all_seen);
|
|
CHECK(SpotBudgetFromEvidence(all_hit, all_seen) == 0);
|
|
|
|
// A budget already cut to its peak has no fall left in it, so a second measurement takes nothing
|
|
// further off: the rule does not ratchet down on repetition.
|
|
CHECK(SpotBudgetFromEvidence({indexed.begin(), indexed.begin() + 100},
|
|
{counted.begin(), counted.begin() + 100}) == 0);
|
|
|
|
// Ice-flagged spots take no part, so a run of them neither ends the budget nor moves it: the peak
|
|
// stays at the last indexed non-ice rank before them.
|
|
std::vector<SpotToSave> with_ice(300);
|
|
for (size_t i = 0; i < with_ice.size(); i++) {
|
|
with_ice[i].ice_ring = (i >= 100 && i < 160);
|
|
with_ice[i].indexed = i < 100;
|
|
}
|
|
std::vector<int64_t> ice_indexed(with_ice.size(), 0), ice_counted(with_ice.size(), 0);
|
|
for (int f = 0; f < frames; f++)
|
|
AddSpotBudgetEvidence(with_ice, false, ice_indexed, ice_counted);
|
|
CHECK(SpotBudgetFromEvidence(ice_indexed, ice_counted) == 100);
|
|
|
|
// Nothing indexes: no rank carries evidence and there is no budget to report.
|
|
for (auto &s: spots)
|
|
s.indexed = false;
|
|
std::vector<int64_t> none_indexed(spots.size(), 0), none_counted(spots.size(), 0);
|
|
for (int f = 0; f < frames; f++)
|
|
AddSpotBudgetEvidence(spots, false, none_indexed, none_counted);
|
|
CHECK(SpotBudgetFromEvidence(none_indexed, none_counted) == 0);
|
|
|
|
// The case a bare argmax gets wrong: the spots index at exactly the gate's own fraction at every
|
|
// depth, so there is no depth at which the list stops being reflections. The tally still has a
|
|
// maximum - it always does - but the fall from it is inside the counting noise, and nothing is cut.
|
|
std::vector<SpotToSave> flat(1000);
|
|
for (size_t i = 0; i < flat.size(); i++)
|
|
flat[i].indexed = (i % 5 == 0);
|
|
std::vector<int64_t> flat_indexed(flat.size(), 0), flat_counted(flat.size(), 0);
|
|
for (int f = 0; f < frames; f++)
|
|
AddSpotBudgetEvidence(flat, false, flat_indexed, flat_counted);
|
|
CHECK(SpotBudgetFromEvidence(flat_indexed, flat_counted) == 0);
|
|
}
|