Files
leonarski_f 3f8c72cd1e
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m9s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / Validation Battery (push) Successful in 47m56s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 26m51s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 10m33s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m49s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m10s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 32m0s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 32m49s
Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m57s
Build Packages / Build documentation (push) Successful in 47s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 29m33s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 21m36s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 24m26s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 30m56s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 32m3s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 30m50s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 28m52s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 25m22s
Build Packages / Unit tests (push) Successful in 1h44m43s
v1.0.0-rc.182 (#93)
* Rugnux: Fixed indexing of stills of a centred lattice with a known cell.
* jfjoch_broker (experimental): Live Rugnux processing of serial collections.
* Rugnux: Stills detector modules are placed from the data and written to `<prefix>_module_placement.json`; `--panel-refine` replaces `--refine-modules`.
* Rugnux: More reliable rotation processing - indexing, monoclinic setting, space-group choice and refinement of multi-domain twins.

Reviewed-on: #93
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-04 11:13:33 +01:00

90 lines
3.9 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "NXmxModules.h"
#include <cmath>
#include "../common/JFJochException.h"
namespace {
// A translation dataset as a vector in pixels of the internal frame (x = column, y = row, z = beam).
Coord ReadTranslation_px(HDF5Object &file, const std::string &path, double pixel_size_m, const RotMatrix &delta) {
HDF5DataSet ds(file, path);
std::vector<double> value;
ds.ReadVector(value);
const auto vec = ds.ReadAttrVec("vector");
if (value.empty() || vec.size() != 3)
throw JFJochException(JFJochExceptionCategory::HDF5, path + ": not a translation");
double scale = 1.0;
if (ds.AttrExists("units")) {
const std::string units = ds.ReadAttrStr("units");
if (units == "mm")
scale = 1e-3;
else if (units == "um" || units == "microns")
scale = 1e-6;
}
const double len_px = value[0] * scale / pixel_size_m;
// McStas -> internal is a half turn about z; the discrete image orientation is undone after it.
const Coord mcstas(static_cast<float>(-vec[0]), static_cast<float>(-vec[1]), static_cast<float>(vec[2]));
return delta.transpose() * (static_cast<float>(len_px) * mcstas);
}
} // namespace
std::string NXmxModuleGroup(HDF5Object &file, size_t n) {
// The index is written zero-padded to the width of the last one (module_00 ... module_15); the width is
// the one module 0 has.
for (size_t digits = 1; digits <= 3; digits++) {
const std::string first = "/entry/instrument/detector/module_" + std::string(digits - 1, '0') + "0/";
if (file.Exists(first + "data_origin")) {
std::string index = std::to_string(n);
if (index.size() < digits)
index.insert(0, digits - index.size(), '0');
const std::string base = "/entry/instrument/detector/module_" + index + "/";
return file.Exists(base + "data_origin") ? base : "";
}
}
return "";
}
DetectorModules ReadNXmxModules(HDF5Object &file, double pixel_size_m, const DetectorOrientation &orientation) {
const RotMatrix delta = orientation.Matrix();
std::vector<DetectorModule> out;
for (size_t n = 0;; n++) {
const std::string base = NXmxModuleGroup(file, n);
if (base.empty())
break;
const auto origin = file.ReadVector<int64_t>(base + "data_origin");
const auto size = file.ReadVector<int64_t>(base + "data_size");
if (origin.size() != 2 || size.size() != 2)
throw JFJochException(JFJochExceptionCategory::HDF5, base + ": only two-dimensional modules are read");
const Coord o = ReadTranslation_px(file, base + "module_offset", pixel_size_m, delta);
const Coord f = ReadTranslation_px(file, base + "fast_pixel_direction", pixel_size_m, delta);
const Coord s = ReadTranslation_px(file, base + "slow_pixel_direction", pixel_size_m, delta);
if (std::fabs(o.z) > 1e-3 || std::fabs(f.z) > 1e-6 || std::fabs(s.z) > 1e-6)
throw JFJochException(JFJochExceptionCategory::HDF5, base + ": a module out of the detector plane is not read");
DetectorModule m;
m.y0 = origin[0];
m.x0 = origin[1];
m.height = size[0];
m.width = size[1];
m.ox = o.x;
m.oy = o.y;
m.fx = f.x;
m.fy = f.y;
m.sx = s.x;
m.sy = s.y;
// The readout axes, where the writer says (writer/NXmxModules.cpp); else the module's own array.
if (file.Exists(base + "readout_fast_axis") && file.Exists(base + "readout_slow_axis")) {
m.fast = DirectionFromName(file.GetString(base + "readout_fast_axis"));
m.slow = DirectionFromName(file.GetString(base + "readout_slow_axis"));
}
out.push_back(m);
}
if (out.size() < 2)
return {};
return DetectorModules(out);
}