Files
Jungfraujoch/tests/RotationIndexerTest.cpp
Filip Leonarski 47e3e075d7
Some checks failed
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 12m15s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 12m55s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 13m5s
Build Packages / Generate python client (push) Successful in 18s
Build Packages / build:rpm (rocky8) (push) Successful in 13m22s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 13m24s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (ubuntu2204) (push) Successful in 13m24s
Build Packages / Build documentation (push) Successful in 33s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 13m53s
Build Packages / build:rpm (rocky9) (push) Successful in 14m16s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 6m50s
Build Packages / Unit tests (push) Failing after 53m49s
jfjoch_tests: Add RotationIndexer test (work in progress)
2025-12-01 15:56:59 +01:00

71 lines
2.4 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include <catch2/catch_all.hpp>
#include <iostream>
#include "../image_analysis/RotationIndexer.h"
#include "../image_analysis/bragg_integration/BraggPrediction.h"
TEST_CASE("RotationIndexer") {
DiffractionExperiment exp_i;
exp_i.IncidentEnergy_keV(WVL_1A_IN_KEV)
.BeamX_pxl(1000)
.BeamY_pxl(1000)
.PoniRot1_rad(0.01)
.PoniRot2_rad(0.02)
.DetectorDistance_mm(200);
IndexingSettings settings;
settings.RotationIndexing(true).RotationIndexingAngularStride_deg(1.0).RotationIndexingMinAngularRange_deg(30.0);
exp_i.ImportIndexingSettings(settings);
// Base lattice (non-pathological)
CrystalLattice latt_base(40, 50, 80, 90, 95, 90);
// Rotation axis: around X with 1 deg per image
GoniometerAxis axis("omega", 0.0f, 1.0f, Coord(1,0,0), std::nullopt);
exp_i.Goniometer(axis);
BraggPredictionSettings prediction_settings{
.high_res_A = 1.5,
.ewald_dist_cutoff = 0.002
};
IndexerThreadPool indexer_thread_pool(exp_i.GetIndexingSettings());
RotationIndexer indexer(exp_i, indexer_thread_pool);
BraggPrediction prediction;
int cnt = 0;
// Predict reflections for images at 0-30 deg.
for (int img = 0; img < 50; ++img) {
std::vector<SpotToSave> spots;
// For a rotated image, per-image lattice is obtained as Multiply(rot.transpose())
const RotMatrix rot = axis.GetTransformation(img);
const CrystalLattice latt_img = latt_base.Multiply(rot.transpose());
const auto n = prediction.Calc(exp_i, latt_img, prediction_settings);
for (int i = 0; i < n; ++i) {
const auto& r = prediction.GetReflections().at(i);
SpotToSave s{};
s.x = r.predicted_x;
s.y = r.predicted_y;
s.image = img; // provide image index for rotation-aware refinement
s.intensity = 1.0f; // minimal positive value
s.ice_ring = false;
s.indexed = true;
spots.push_back(s);
}
if (indexer.ProcessImage(img, spots).has_value())
cnt++;
}
CHECK (cnt == 20);
auto ret = indexer.Finalize(false);
REQUIRE(ret);
CHECK(ret->search_result.centering == 'P');
CHECK(ret->search_result.system == gemmi::CrystalSystem::Monoclinic);
}