grid scan: a crystal is grown out of its seeds, so one weak grid point no longer splits it

A crystal in the corpus was reported as two because the grid point joining its halves
scored 0.498 - two thousandths under the threshold. That is an artefact of putting a
hard edge through a continuous quantity, not a gap in a crystal.

The patch search is now hysteresis. A patch is labelled at a lower grow threshold
(0.35) and kept only if it holds a cell above the seed threshold (0.50), which is the
same thing as growing out of the seeds in one pass of the labeller rather than two. A
cell between the two levels joins a crystal that already exists but can never start
one, so no lowering of the grow threshold can turn a background into a crystal - and
the negatives are safe by construction, since water peaks at 0.146 and ice at 0.490,
both under the seed level.

Both halves of the small-patch rule read the GROWN patch - the count includes the
cells growth added and the peak is the patch's best cell wherever it lies - which is
stated at the test, because a reader will otherwise wonder whether a grown cell can
rescue a patch no seed would have admitted. It cannot: the patch is discarded before
that test unless it holds a seed.

The reported extents are those of the grown patch, so they reach the 0.35 contour. Over
the corpus that is major_um x1.04 and n_images x1.07 at the median (x1.11 and x1.14 at
the mean, +7% cells overall), and the cells it adds are spread fairly evenly over
0.35-0.50 rather than piled at the bottom - a crystal edge sampled at one grid step, not
bleed into a neighbour that never diffracted. The patch mean falls with them, and can now
sit below the seed threshold; the peak beside it is what the admission was decided on.
RASTER_REPORT_VERSION is 3, because N_CELLS and the extents are a different measurement
under the same names.

The corpus table is unchanged: 17/17 protein, 0/4 water, 0/3 ice, 10/10 heldout. The
split heals into one crystal, and one raster's five patches become three.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFEJG6WBQv8th4UJFNe53N
This commit is contained in:
leonarski_fandClaude Opus 5 committed 2026-09-08 07:34:36 +02:00
1 parent cdb60c2916
commit 273591af11
7 files changed
+90 -10

No files matched your search

+39 -1
View File
@@ -59,7 +59,7 @@ TEST_CASE("RasterReport_Render", "[Diagnostics]") {
// The keys are the interface a battery greps; pin the spellings and the values that say what
// the run saw.
CHECK(report.find("RASTER_REPORT_VERSION= 2\n") != std::string::npos);
CHECK(report.find("RASTER_REPORT_VERSION= 3\n") != std::string::npos);
CHECK(report.find("INPUT_FILE= test_master.h5\n") != std::string::npos);
CHECK(report.find("GRID_SIZE= 5 4\n") != std::string::npos);
CHECK(report.find("GRID_STEP_UM= 20.00 16.00\n") != std::string::npos);
@@ -69,6 +69,7 @@ TEST_CASE("RasterReport_Render", "[Diagnostics]") {
CHECK(report.find("IMAGES_SCORED= 20\n") != std::string::npos);
CHECK(report.find("IMAGES_ABOVE_THRESHOLD= 4\n") != std::string::npos);
CHECK(report.find("ICE_ABOVE_THRESHOLD= 0\n") != std::string::npos);
CHECK(report.find("GROW_SCORE_THRESHOLD= 0.35\n") != std::string::npos);
CHECK(report.find("MIN_BLOB_CELLS= 3\n") != std::string::npos);
CHECK(report.find("DECISIVE_PROTEIN_SCORE= 0.60\n") != std::string::npos);
CHECK(report.find("MAX_CRYSTALS= 0\n") != std::string::npos);
@@ -232,3 +233,40 @@ TEST_CASE("RasterReport_OneDecisiveCellIsACrystal", "[Diagnostics]") {
CHECK(AnalyzeGridScan(big, grid, settings.beam_size_x_um, settings.beam_size_y_um,
settings.analysis).crystals.size() == 1);
}
TEST_CASE("RasterReport_HysteresisHealsASplit", "[Diagnostics]") {
// The case this exists for, taken from the corpus: one crystal whose middle grid point fell two
// thousandths under the seed threshold, which broke it into two crystals that were never two.
const GridScanSettings grid = WideGrid();
ScanResult scan = WideScan({});
for (int64_t x = 2; x <= 8; x++)
scan.images[2 * WIDE_NX + x].protein_score = 0.85f;
scan.images[2 * WIDE_NX + 5].protein_score = 0.498f; // above the grow level, under the seed
RasterSettings settings = TestSettings();
const GridScanResult healed = AnalyzeGridScan(scan, grid, settings.beam_size_x_um,
settings.beam_size_y_um, settings.analysis);
REQUIRE(healed.crystals.size() == 1);
CHECK(healed.crystals[0].n_images == 7); // the bridging cell is part of the crystal
// Growing no further than the seed level is the behaviour hysteresis replaced, and it splits.
settings.analysis.grow_score_threshold = settings.analysis.protein_score_threshold;
const GridScanResult split = AnalyzeGridScan(scan, grid, settings.beam_size_x_um,
settings.beam_size_y_um, settings.analysis);
CHECK(split.crystals.size() == 2);
}
TEST_CASE("RasterReport_GrowthCannotStartOnItsOwn", "[Diagnostics]") {
// A patch that reaches the grow level and never the seed level is not a crystal however large it
// is or however low the grow level is set - which is what makes the level safe to lower.
const GridScanSettings grid = WideGrid();
const ScanResult scan = WideScan({{1, 1, 0.45f}, {8, 2, 0.40f}});
RasterSettings settings = TestSettings();
CHECK(AnalyzeGridScan(scan, grid, settings.beam_size_x_um, settings.beam_size_y_um,
settings.analysis).crystals.empty());
settings.analysis.grow_score_threshold = 0.05f;
CHECK(AnalyzeGridScan(scan, grid, settings.beam_size_x_um, settings.beam_size_y_um,
settings.analysis).crystals.empty());
}