Build Packages / Create release (push) Successful in 24s
Build Packages / build:viewer:macos-arm64:nocuda (push) Successful in 3m29s
Build Packages / build:rugnux:macos-arm64:nocuda (push) Successful in 2m43s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 8m27s
Build Packages / build:rugnux:linux-x86_64:cuda (push) Successful in 9m53s
Build Packages / build:viewer:linux-x86_64:nocuda (push) Successful in 9m58s
Build Packages / build:viewer:linux-x86_64:cuda (push) Successful in 11m22s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 13m39s
Build Packages / build:viewer:windows-x86_64:nocuda (push) Successful in 18m37s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 16m32s
Build Packages / build:viewer:windows-x86_64:cuda (push) Successful in 24m11s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m30s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 19m3s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m23s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m41s
Build Packages / Generate python client (push) Successful in 50s
Build Packages / Build documentation (push) Successful in 1m16s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 21m0s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 18m38s
Build Packages / build:rugnux:windows-x86_64:cuda (push) Successful in 14m33s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 17m55s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 18m38s
Build Packages / Unit tests (push) Successful in 1h46m14s
* jfjoch_broker: Optional per-dataset authentication - statistics, images and plots can require a bearer token, which jfjoch_viewer supports. * jfjoch_viewer: Dark mode and a theme-matched colour scheme, a magnifier panel, and simpler contrast and background controls. * Rugnux: Multiple performance improvements on GPU and CPU (CPU-only processing up to 40% faster, faster image decoding on ARM), with unchanged results. * Rugnux: `--model` rigid-body refinement runs on the GPU, and the model-validation check is faster and more reliable. * Rugnux: Improved scaling and merging - error model, outlier rejection, absorption correction and French-Wilson amplitudes now agree more closely with XDS and ctruncate. * Rugnux: Improved integration - radial background on powder and ice rings, crowded rotation data keep their reflections, and CPU-only builds integrate large unit cells as GPU builds do. * Rugnux: More robust detector geometry - measured beam centre, X-ray bandwidth and goniometer rate, and geometry refinement accepted only on significant evidence. * Rugnux: Merged files are written in the standard setting, or in the setting of a reference MTZ, structure-factor mmCIF or model, with its free-R flags. * Rugnux: Richer report - ice and powder rings, further lattices, superstructure candidates and mosaicity, with warnings worded as prompts to check. * Rugnux: Clear error messages when a data set needs more GPU or host memory than is available. Reviewed-on: #83 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
177 lines
7.5 KiB
C++
177 lines
7.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 <cmath>
|
|
|
|
#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", "[portable]") {
|
|
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", "[portable]") {
|
|
// 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_MultiTurn") {
|
|
// One continuous 540 degree sweep, 2700 frames of 0.2 deg, whose headers write the start angle
|
|
// modulo 360: from frame 1476 on, every angle repeats one the first revolution already had. The
|
|
// second and third revolutions must occupy fresh slots, not land on top of the first.
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 2700; i++)
|
|
angles.push_back(std::fmod(65.0 + 0.2 * i, 360.0));
|
|
const auto l = sweep::Place(Series(angles, 0.2), "test");
|
|
REQUIRE(l.files.size() == 2700);
|
|
CHECK(l.present == 2700);
|
|
CHECK(l.start_deg == Catch::Approx(65.0));
|
|
CHECK(l.increment_deg == Catch::Approx(0.2));
|
|
// The sweep really is 540 degrees wide, and no frame was dropped on top of another.
|
|
CHECK(l.increment_deg * static_cast<double>(l.files.size() - 1) == Catch::Approx(539.8));
|
|
CHECK(l.files.back() == "f2699.cbf");
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_MultiTurnWithReadbackNoise") {
|
|
// The same sweep as a real header writes it: the recorded angles come from 32-bit floats, so
|
|
// each is a few parts in 100000 off the grid. Estimating the step from ONE recorded difference
|
|
// scales that noise by the frame number - the series it was measured on drifted a quarter of a
|
|
// step by frame 1924 and was refused as scattered.
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 2700; i++)
|
|
angles.push_back(std::fmod(static_cast<double>(static_cast<float>(65.0 + 0.2 * i)), 360.0));
|
|
const auto l = sweep::Place(Series(angles, 0.2), "test");
|
|
REQUIRE(l.files.size() == 2700);
|
|
CHECK(l.present == 2700);
|
|
CHECK(l.increment_deg == Catch::Approx(0.2).epsilon(1e-6));
|
|
CHECK(l.start_deg == Catch::Approx(65.0).epsilon(1e-6));
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_MultiTurnGapped") {
|
|
// Past 360 AND missing frames: the two have to work together, because a gap is what the step
|
|
// guess has to survive and a full turn is what the step count has to carry through.
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 2000; i++)
|
|
if (i % 7 != 3)
|
|
angles.push_back(std::fmod(10.0 + 0.25 * i, 360.0));
|
|
const auto l = sweep::Place(Series(angles, 0.25), "test");
|
|
CHECK(l.files.size() == 2000);
|
|
CHECK(l.present == angles.size());
|
|
CHECK(l.increment_deg == Catch::Approx(0.25));
|
|
CHECK(l.files[3].empty());
|
|
CHECK(l.files[1999] == "f" + std::to_string(angles.size() - 1) + ".cbf");
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_ConcatenatedSweepsStillRefused") {
|
|
// Two 90 degree sweeps of one crystal in one directory. Unlike a sweep that runs past 360, this
|
|
// one goes BACK: the second series returns to angles the first already covered without having
|
|
// stepped forward through a whole turn to get there.
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 90; i++) angles.push_back(0.5 * i);
|
|
for (int i = 0; i < 90; i++) angles.push_back(0.5 * i);
|
|
CHECK_THROWS_AS(sweep::Place(Series(angles, 0.5), "test"), JFJochException);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
TEST_CASE("SweepLayout_StepFinerThanTheOscillationWidth") {
|
|
// The header field is the oscillation WIDTH, and a series can step by far less than it exposes -
|
|
// or, on some writers, hold the whole sweep's range in that field. Taking it for the step
|
|
// rejected every inter-frame difference as jitter: the sweep then read as one that never turns
|
|
// and was laid out end to end, every frame past the first at the wrong angle.
|
|
std::vector<double> angles;
|
|
for (int i = 0; i < 100; i++)
|
|
angles.push_back(30.0 + 0.1 * i);
|
|
|
|
const auto wedges = sweep::Place(Series(angles, 1.0), "test"); // 1 deg wedges, 0.1 deg apart
|
|
REQUIRE(wedges.files.size() == 100);
|
|
CHECK(wedges.present == 100);
|
|
CHECK(wedges.start_deg == Catch::Approx(30.0));
|
|
CHECK(wedges.increment_deg == Catch::Approx(0.1));
|
|
|
|
const auto total = sweep::Place(Series(angles, 10.0), "test"); // the field holds the range
|
|
REQUIRE(total.files.size() == 100);
|
|
CHECK(total.present == 100);
|
|
CHECK(total.increment_deg == Catch::Approx(0.1));
|
|
}
|