Files
Jungfraujoch/reader/NXmxModules.h
leonarski_f a63676247e NXmx reader: derive missing beam centre, distance and pixel size from the module geometry; accept micron units
NXmx makes beam_center_x/y, distance and x_pixel_size optional - the detector
module's geometry places the detector. A file that states none of them (as
DIALS dxtbx.any2nexus writes it) was refused. Now, when absent, they are taken
from the first NXdetector_module (found by its fast_pixel_direction, whatever
the group is called): pixel (0, 0) is the pixel direction's offset plus the
translations along its depends_on chain, the beam centre is where +z meets the
module plane (in image pixels, data_origin added), the distance is the
perpendicular distance to that plane, the pixel size the fast step. Rotations
are left to the existing chain reader, so a tilted file round-trips exactly.

Length units are parsed in one place (NXmxLengthUnit_m), used by the master
reader and the module reader alike, and now accept m/mm/um, the micro sign and
Greek mu, micron(s) and spelled-out forms; sensor_thickness in "microns" was
refused before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3
(cherry picked from commit a1926aea754adb6ce6c3455f54ccaddd61fbb0de)
(cherry picked from commit 9049ad66ec)
2026-11-24 08:43:11 +01:00

38 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "../common/DetectorModules.h"
#include "../common/DetectorOrientation.h"
#include "../writer/HDF5Objects.h"
// Metres per one `units`, a length unit as NXmx states it ("m", "mm", "um", "microns", ...). No unit means
// metres - what every DECTRIS master and everything this system writes means by one. A unit not recognised is
// refused rather than guessed at: read as metres, a length in millimetres is a silent factor of a thousand.
double NXmxLengthUnit_m(const std::string &units, const std::string &name);
// The geometry the file's first NXdetector_module states, square to the beam: where the beam (+z from the
// sample) meets the module plane, in pixels of the image (the module's data_origin added), the distance from
// the sample to that plane, and the pixel size along the fast direction. NXmx makes beam_center_x/y, distance
// and x_pixel_size optional, the module geometry being what places the detector; a file that leaves them out
// is read from here. Rotations in the chain are not taken, as ReadDetectorRotationChain in
// HDF5MetadataSource.cpp reads them separately. Throws when the file has no module.
struct NXmxModuleGeometry {
float beam_x_pxl;
float beam_y_pxl;
float distance_m;
float pixel_size_m;
};
NXmxModuleGeometry ReadNXmxModuleGeometry(HDF5Object &file);
// The group of module n, "/entry/instrument/detector/module_<n>/" with n padded as the file pads it
// (module_3 or module_03), or empty when the file has no such module.
std::string NXmxModuleGroup(HDF5Object &file, size_t n);
// The modules an NXmx file states, as WriteNXmxModules (writer/NXmxModules.h) writes them: groups
// /entry/instrument/detector/module_0, module_1, ... (or module_00, module_01, ...). Their offsets are taken
// relative to the image's pixel (0, 0) and in the detector plane; a module standing out of that plane (an
// offset or pixel direction with a component along the detector normal) is refused. Fewer than two such groups: none.
DetectorModules ReadNXmxModules(HDF5Object &file, double pixel_size_m, const DetectorOrientation &orientation);