A series of one file per image was laid out end to end: the rotation start came from the first file and the step from the difference between the first two, so a series with frames missing came out compressed - one 179.8 degree deposited sweep of 1108 files out of 1800 was read as 111 degrees, and every frame past the first gap was analysed at the wrong spindle angle. Indexing then found a lattice that took 4% of the validation spots, and two other gapped series aborted outright with "it is not this crystal's lattice". Every one of these formats writes each image's own start angle in its own header, so the sweep is fully recoverable. The new reader/SweepLayout places each frame at the slot its own angle puts it in and leaves a missing frame as a gap - a slot with no file, which ReadRawImage reports as nothing to read, which every image loop in the pipeline already passes over. The goniometer's start + increment * image_number is then the true angle of every image, and the sweep range, the per-10-degree delta-CC1/2 batches and the sweep-quality ledger all read the rotation the headers describe. The rotation step is the smallest move between two frames that really are adjacent, not the first pair. The three readers shared this code by duplication; it is now written once. The same place refuses what is not a sweep rather than averaging it into one: headers that disagree about the detector distance, the beam centre, the wavelength or the oscillation width, angles that do not sit on a single step (a folder of screening shots), or two frames claiming the same angle - each naming the frames. A series that does not turn at all is left exactly as it was. A directory holding fewer files than its own numbering spans is also reported, with both counts: that is the signal that a sweep was not unpacked or copied whole, which otherwise shows up only as a resolution nobody can explain. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nW6FNRP1bBJJ8pfHiByAT
97 lines
3.5 KiB
C++
97 lines
3.5 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../common/JFJochException.h"
|
|
#include "../reader/SweepLayout.h"
|
|
|
|
namespace {
|
|
|
|
// A series of frames all taken at the same instrument setting, at the angles given.
|
|
std::vector<sweep::Frame> Series(const std::vector<double> &angles, double increment) {
|
|
std::vector<sweep::Frame> out;
|
|
out.reserve(angles.size());
|
|
for (size_t i = 0; i < angles.size(); i++)
|
|
out.push_back({"f" + std::to_string(i) + ".cbf", angles[i], increment, 0.2, 1000, 1000, 1.0});
|
|
return out;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("SweepLayout_Contiguous") {
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 100; i++)
|
|
angles.push_back(20.0 + 0.1 * i);
|
|
const auto l = sweep::Place(Series(angles, 0.1), "test");
|
|
CHECK(l.files.size() == 100);
|
|
CHECK(l.present == 100);
|
|
CHECK(l.start_deg == Catch::Approx(20.0));
|
|
CHECK(l.increment_deg == Catch::Approx(0.1));
|
|
for (size_t i = 0; i < l.files.size(); i++)
|
|
CHECK(l.files[i] == "f" + std::to_string(i) + ".cbf");
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_Gapped") {
|
|
// Frames 3, 4 and 7 of a ten-frame sweep never made it into the archive. The sweep is still ten
|
|
// steps wide and every frame keeps its own angle.
|
|
const auto l = sweep::Place(Series({0.0, 0.1, 0.2, 0.5, 0.6, 0.8, 0.9}, 0.1), "test");
|
|
REQUIRE(l.files.size() == 10);
|
|
CHECK(l.present == 7);
|
|
CHECK(l.increment_deg == Catch::Approx(0.1));
|
|
CHECK(l.files[2] == "f2.cbf");
|
|
CHECK(l.files[3].empty());
|
|
CHECK(l.files[4].empty());
|
|
CHECK(l.files[5] == "f3.cbf");
|
|
CHECK(l.files[7].empty());
|
|
CHECK(l.files[9] == "f6.cbf");
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_PastFullTurn") {
|
|
// A writer that starts over at 0 rather than counting on past 360.
|
|
const auto l = sweep::Place(Series({359.7, 359.8, 359.9, 0.0, 0.1}, 0.1), "test");
|
|
CHECK(l.files.size() == 5);
|
|
CHECK(l.present == 5);
|
|
CHECK(l.increment_deg == Catch::Approx(0.1));
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_Reversed") {
|
|
const auto l = sweep::Place(Series({10.0, 9.5, 9.0, 8.0}, 0.5), "test");
|
|
REQUIRE(l.files.size() == 5);
|
|
CHECK(l.increment_deg == Catch::Approx(-0.5));
|
|
CHECK(l.files[3].empty());
|
|
CHECK(l.files[4] == "f3.cbf");
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_Stills") {
|
|
// Nothing turns: the files are the images, and the header's nominal increment stands.
|
|
const auto l = sweep::Place(Series({45.0, 45.0, 45.0}, 0.1), "test");
|
|
CHECK(l.files.size() == 3);
|
|
CHECK(l.present == 3);
|
|
CHECK(l.start_deg == Catch::Approx(45.0));
|
|
CHECK(l.increment_deg == Catch::Approx(0.1));
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_ScreeningImagesRefused") {
|
|
// Five shots at scattered angles are not a sweep, and must not be laid out as one.
|
|
CHECK_THROWS_AS(sweep::Place(Series({0.0, 90.0, 45.0, 300.0, 270.0}, 0.5), "test"),
|
|
JFJochException);
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_MovedDetectorRefused") {
|
|
auto frames = Series({0.0, 0.1, 0.2, 0.3}, 0.1);
|
|
frames[2].distance_m = 0.3;
|
|
CHECK_THROWS_AS(sweep::Place(frames, "test"), JFJochException);
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_SecondWavelengthRefused") {
|
|
auto frames = Series({0.0, 0.1, 0.2, 0.3}, 0.1);
|
|
frames[3].wavelength_A = 1.9;
|
|
CHECK_THROWS_AS(sweep::Place(frames, "test"), JFJochException);
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_RepeatedAngleRefused") {
|
|
// Two sweeps of the same crystal concatenated: the second covers angles the first already has.
|
|
CHECK_THROWS_AS(sweep::Place(Series({0.0, 0.1, 0.2, 0.1, 0.2}, 0.1), "test"), JFJochException);
|
|
}
|