Files
Jungfraujoch/tools/jfjoch_indexing_test.cpp

79 lines
3.1 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "../reader/JFJochHDF5Reader.h"
#include "../image_analysis/indexing/IndexerFactory.h"
#include "../common/Logger.h"
#include "../image_analysis/RotationIndexer.h"
#include "../writer/FileWriter.h"
#include "../image_analysis/indexing/AnalyzeIndexing.h"
int main(int argc, char** argv) {
Logger logger("jfjoch_indexing_test");
if (argc != 2) {
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Usage: ./jfjoch_indexing_test <file>");
}
JFJochHDF5Reader reader;
reader.ReadFile(argv[1]);
if (!reader.GetDataset())
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Error opening file");
DiffractionExperiment experiment(reader.GetDataset()->experiment);
experiment.SetUnitCell({});
experiment.IndexingAlgorithm(IndexingAlgorithmEnum::FFT);
experiment.FilePrefix("output");
StartMessage msg;
experiment.FillMessage(msg);
// FileWriter fw(msg);
IndexerThreadPool indexer(experiment.GetIndexingSettings());
auto geom = experiment.GetDiffractionGeometry();
RotationIndexer rot_index(experiment, indexer);
int cnt = 0;
int cnt_2 = 0;
for (int i = 0; i < reader.GetNumberOfImages(); i++) {
auto img = reader.LoadImage(i);
if (!img)
continue;
DataMessage msg = img->ImageData();
auto img_res = rot_index.ProcessImage(i, msg.spots);
if (img_res ) {
auto img_latt = img_res->lattice;
DiffractionExperiment x(experiment);
x.DetectorDistance_mm(img_res->geom.GetDetectorDistance_mm())
.BeamX_pxl(img_res->geom.GetBeamX_pxl())
.BeamY_pxl(img_res->geom.GetBeamY_pxl());
cnt++;
if (AnalyzeIndexing(msg, x, img_latt))
cnt_2++;
}
if (i % 200 == 0)
logger.Info("Image {} {} {}", i, cnt, cnt_2);
}
auto latt_1 = rot_index.Finalize(false);
if (latt_1) {
auto uc = latt_1->lattice.GetUnitCell();
logger.Info("Unit cell {} {} {} {} {} {}", uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma);
logger.Info("Latt1 {} {} {}", latt_1->lattice.Vec0().x, latt_1->lattice.Vec0().y, latt_1->lattice.Vec0().z);
logger.Info("Latt1 {} {} {}", latt_1->lattice.Vec1().x, latt_1->lattice.Vec1().y, latt_1->lattice.Vec1().z);
logger.Info("Latt1 {} {} {}", latt_1->lattice.Vec2().x, latt_1->lattice.Vec2().y, latt_1->lattice.Vec2().z);
}
auto latt_2 = rot_index.Finalize(true);
if (latt_2) {
auto uc = latt_2->lattice.GetUnitCell();
logger.Info("Unit cell {} {} {} {} {} {}", uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma);
logger.Info("Latt1 {} {} {}", latt_2->lattice.Vec0().x, latt_2->lattice.Vec0().y, latt_2->lattice.Vec0().z);
logger.Info("Latt1 {} {} {}", latt_2->lattice.Vec1().x, latt_2->lattice.Vec1().y, latt_2->lattice.Vec1().z);
logger.Info("Latt1 {} {} {}", latt_2->lattice.Vec2().x, latt_2->lattice.Vec2().y, latt_2->lattice.Vec2().z);
}
}