rugnux: _process.h5 keeps each image's XFEL pulse ID and event code
The per-image XFEL identifiers Jungfraujoch records for a pulsed source
(/entry/xfel/pulseID, uint64, and /entry/xfel/eventCode, uint32) were not
carried through reprocessing: the reader did not read them and rugnux built
its per-image messages without them, so a _process.h5 lost the pulse ID of
every image. Merging a pump-probe run by pulse ID needs them next to the
integrated reflections.
- The HDF5 reader reads /entry/xfel/pulseID and eventCode from the master
(VDS, integrated, _process.h5) or, for a legacy master, from its data
files, and passes them on per image. Several inputs read as one keep them
where every input has them.
- rugnux copies them into the messages of the image pass that writes the
_process.h5, so /entry/xfel/{pulseID,eventCode}[i] there belongs to image
i of the file - the index of /entry/MX/...[i], /entry/reflections/image_<i>
and the source image /entry/detector/number[i] - including under -s/-e and
a stride.
- A pulsed-source start message now asks for the /entry/xfel datasets in the
VDS master: the flag was never set, so a broker master held them only in
its data files.
Test: Rugnux_ProcessFileKeepsXfelIds (a pulsed VDS input, images 1, 4, 7 of
ten processed; IDs checked in order in the _process.h5 and on read-back).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdL4qBGYRiSXSGXfCLu
This commit is contained in:
1 parent
4b47037b89
commit
ab649aad87
7 files changed
+112
-3
No files matched your search
@@ -761,6 +761,10 @@ void DiffractionExperiment::FillMessage(StartMessage &message) const {
|
||||
message.write_master_file = dataset.IsWriteNXmxHDF5Master();
|
||||
message.overwrite = file_writer.IsOverwriteExistingFiles();
|
||||
message.file_format = file_writer.GetFileFormat();
|
||||
// The receiver records the pulse ID and event code of every image of a pulsed source; the master then
|
||||
// carries them too (/entry/xfel), not only the data files.
|
||||
if (IsPulsedSource())
|
||||
message.xfel_pulse_id = true;
|
||||
message.ring_current_mA = dataset.GetRingCurrent_mA();
|
||||
message.sample_temperature_K = dataset.GetSampleTemperature_K();
|
||||
message.fluorescence_spectrum = dataset.GetFluorescenceSpectrum();
|
||||
|
||||
+12
-2
@@ -113,7 +113,8 @@ dataset and writes its results to a master file named **`<prefix>_process.h5`**.
|
||||
**integrated** format, but instead of copying the images its `/entry/data/data` is a *virtual
|
||||
dataset that links back to the original image files* (`hdf5_source_data` →
|
||||
`NXmx::LinkToData_ProcessingVDS`). The result is a compact, self-describing companion file that
|
||||
holds *all* the derived analysis (everything in §4) plus a virtual view
|
||||
holds *all* the derived analysis (everything in §4, including the XFEL pulse IDs of §4.8 when the
|
||||
input has them) plus a virtual view
|
||||
of the raw images — without duplicating terabytes of data.
|
||||
|
||||
This is a particularly FAIR-friendly artefact: it can be shared or archived alongside (or instead
|
||||
@@ -566,7 +567,16 @@ A convenience NXcollection in the data file (note: distinct from the standard
|
||||
|
||||
### 4.8 `/entry/xfel` — pulsed-source metadata
|
||||
|
||||
`[n_images]` vectors `pulseID` and `eventCode`, written for pulsed sources (e.g. SwissFEL).
|
||||
`[n_images]` vectors `pulseID` (uint64) and `eventCode` (uint32), written for pulsed sources (e.g.
|
||||
SwissFEL): the XFEL pulse ID and the event code of each image, as the detector's timing receiver
|
||||
recorded them. A pulse ID of `UINT64_MAX` marks an image whose modules disagreed on it. They are written to
|
||||
the data files and, for a VDS master, mapped into the master as well.
|
||||
|
||||
In a `_process.h5`, `/entry/xfel/pulseID` and `/entry/xfel/eventCode` hold the IDs of the images
|
||||
processed, in the file's own image order: entry `i` belongs to the image whose analysis is at index `i`
|
||||
(`/entry/MX/...[i]`, `/entry/reflections/image_<i>`), the source image `/entry/detector/number[i]`. With
|
||||
a subset or a stride (`-s`/`-e`/`--stride`) only the processed images are there; several inputs read as
|
||||
one keep them only where every input has them.
|
||||
|
||||
### 4.9 Other collections
|
||||
|
||||
|
||||
@@ -572,6 +572,9 @@ HDF5MetadataSource::OpenResult HDF5MetadataSource::Open(const std::string &filen
|
||||
else
|
||||
dataset->efficiency = std::vector<float>(number_of_images, 1.0);
|
||||
|
||||
dataset->xfel_pulse_id = master_file->ReadOptVector<uint64_t>("/entry/xfel/pulseID");
|
||||
dataset->xfel_event_code = master_file->ReadOptVector<uint64_t>("/entry/xfel/eventCode");
|
||||
|
||||
if (master_file->Exists("/entry/roi"))
|
||||
dataset->roi = master_file->FindLeafs("/entry/roi");
|
||||
|
||||
@@ -735,6 +738,11 @@ HDF5MetadataSource::OpenResult HDF5MetadataSource::Open(const std::string &filen
|
||||
number_of_images, fimages);
|
||||
}
|
||||
|
||||
ReadVector(dataset->xfel_pulse_id, data_file, "/entry/xfel/pulseID",
|
||||
number_of_images, fimages);
|
||||
ReadVector(dataset->xfel_event_code, data_file, "/entry/xfel/eventCode",
|
||||
number_of_images, fimages);
|
||||
|
||||
if (data_file.Exists("/entry/MX")) {
|
||||
if (data_file.Exists("/entry/MX/peakCountUnfiltered"))
|
||||
ReadVector(dataset->spot_count,
|
||||
@@ -1468,6 +1476,10 @@ void HDF5MetadataSource::FillPerImage(DataMessage &message, int64_t requested_im
|
||||
message.indexing_lattice_count = dataset->indexing_lattice_count[image_number];
|
||||
if (dataset->bkg_estimate.size() > image_number)
|
||||
message.bkg_estimate = dataset->bkg_estimate[image_number];
|
||||
if (dataset->xfel_pulse_id.size() > image_number)
|
||||
message.xfel_pulse_id = dataset->xfel_pulse_id[image_number];
|
||||
if (dataset->xfel_event_code.size() > image_number)
|
||||
message.xfel_event_code = dataset->xfel_event_code[image_number];
|
||||
// NaN is how the file stores a frame with no value; the optional must come back absent, not
|
||||
// carrying a NaN, because absence is the CANNOT-SAY trigger state and a value is not.
|
||||
if (dataset->spindle_blind_fraction.size() > image_number
|
||||
|
||||
@@ -47,6 +47,10 @@ JFJochMultiReader::JFJochMultiReader(std::vector<std::unique_ptr<JFJochReader>>
|
||||
auto dataset = std::make_shared<JFJochReaderDataset>(*first);
|
||||
std::vector<uint32_t> mask = first->pixel_mask->GetMask();
|
||||
dataset->efficiency.clear();
|
||||
dataset->xfel_pulse_id.clear();
|
||||
dataset->xfel_event_code.clear();
|
||||
// The XFEL IDs are kept only where every input has one for each of its images.
|
||||
bool xfel_ids = true;
|
||||
|
||||
for (size_t k = 0; k < inputs.size(); k++) {
|
||||
const auto d = inputs[k]->GetDataset();
|
||||
@@ -74,10 +78,19 @@ JFJochMultiReader::JFJochMultiReader(std::vector<std::unique_ptr<JFJochReader>>
|
||||
auto efficiency = d->efficiency;
|
||||
efficiency.resize(n, 1.0f);
|
||||
dataset->efficiency.insert(dataset->efficiency.end(), efficiency.begin(), efficiency.end());
|
||||
xfel_ids = xfel_ids && d->xfel_pulse_id.size() == n && d->xfel_event_code.size() == n;
|
||||
if (xfel_ids) {
|
||||
dataset->xfel_pulse_id.insert(dataset->xfel_pulse_id.end(), d->xfel_pulse_id.begin(), d->xfel_pulse_id.end());
|
||||
dataset->xfel_event_code.insert(dataset->xfel_event_code.end(), d->xfel_event_code.begin(), d->xfel_event_code.end());
|
||||
}
|
||||
number_of_images += n;
|
||||
}
|
||||
|
||||
// Per-image results a previous run stored in the first input's file are not the whole run's.
|
||||
if (!xfel_ids) {
|
||||
dataset->xfel_pulse_id.clear();
|
||||
dataset->xfel_event_code.clear();
|
||||
}
|
||||
dataset->spot_count.clear();
|
||||
dataset->spot_count_indexed.clear();
|
||||
dataset->spot_count_low_res.clear();
|
||||
|
||||
@@ -64,6 +64,9 @@ struct JFJochReaderDataset {
|
||||
std::vector<float> indexing_result;
|
||||
std::vector<float> indexing_lattice_count;
|
||||
std::vector<float> bkg_estimate;
|
||||
// The XFEL pulse ID and event code of each image (/entry/xfel), where the file records them.
|
||||
std::vector<uint64_t> xfel_pulse_id;
|
||||
std::vector<uint64_t> xfel_event_code;
|
||||
// NaN entries are frames with no value (CANNOT SAY), not zeros.
|
||||
std::vector<float> spindle_blind_fraction;
|
||||
std::vector<float> ice_ring_score;
|
||||
|
||||
@@ -220,6 +220,10 @@ void Rugnux::ImagePass(PipelineLocals &p) {
|
||||
msg.original_number = image_idx;
|
||||
if (dataset->efficiency.size() > image_idx)
|
||||
msg.image_collection_efficiency = dataset->efficiency[image_idx];
|
||||
if (dataset->xfel_pulse_id.size() > image_idx)
|
||||
msg.xfel_pulse_id = dataset->xfel_pulse_id[image_idx];
|
||||
if (dataset->xfel_event_code.size() > image_idx)
|
||||
msg.xfel_event_code = dataset->xfel_event_code[image_idx];
|
||||
total_uncompressed_bytes += msg.image.GetUncompressedSize();
|
||||
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
@@ -329,6 +333,10 @@ void Rugnux::ImagePass(PipelineLocals &p) {
|
||||
msg.original_number = image_idx;
|
||||
if (dataset->efficiency.size() > image_idx)
|
||||
msg.image_collection_efficiency = dataset->efficiency[image_idx];
|
||||
if (dataset->xfel_pulse_id.size() > image_idx)
|
||||
msg.xfel_pulse_id = dataset->xfel_pulse_id[image_idx];
|
||||
if (dataset->xfel_event_code.size() > image_idx)
|
||||
msg.xfel_event_code = dataset->xfel_event_code[image_idx];
|
||||
total_uncompressed_bytes += msg.image.GetUncompressedSize();
|
||||
|
||||
const bool count_crowding = crowding_at && ordinal % crowding_stride == 0;
|
||||
|
||||
+60
-1
@@ -23,7 +23,8 @@
|
||||
namespace {
|
||||
// Write a small VDS dataset of `n` flat images and return nothing (prefix_master.h5 +
|
||||
// prefix_data_000001.h5 land in the test working directory).
|
||||
void WriteTestDataset(const std::string &prefix, int n, bool rotation = false) {
|
||||
// `pulsed`: an XFEL run, image i with pulse ID 1000 + 7 i and event code i % 4.
|
||||
void WriteTestDataset(const std::string &prefix, int n, bool rotation = false, bool pulsed = false) {
|
||||
RegisterHDF5Filter();
|
||||
|
||||
DiffractionExperiment x(DetJF(1));
|
||||
@@ -34,6 +35,9 @@ namespace {
|
||||
x.Compression(CompressionAlgorithm::NO_COMPRESSION);
|
||||
x.BeamX_pxl(512).BeamY_pxl(256).DetectorDistance_mm(150).IncidentEnergy_keV(WVL_1A_IN_KEV)
|
||||
.FrameTime(std::chrono::microseconds(500), std::chrono::microseconds(10));
|
||||
if (pulsed)
|
||||
x.PulsedSource(true).NumTriggers(n).ImagesPerTrigger(1);
|
||||
REQUIRE(x.GetImageNum() == n);
|
||||
|
||||
std::vector<int16_t> image(x.GetPixelsNum(), 5);
|
||||
StartMessage start_message;
|
||||
@@ -44,6 +48,10 @@ namespace {
|
||||
DataMessage message{};
|
||||
message.image = CompressedImage(image, x.GetXPixelsNum(), x.GetYPixelsNum());
|
||||
message.number = i;
|
||||
if (pulsed) {
|
||||
message.xfel_pulse_id = 1000 + 7 * i;
|
||||
message.xfel_event_code = i % 4;
|
||||
}
|
||||
REQUIRE_NOTHROW(file_set.WriteHDF5(message));
|
||||
generator.Add(message);
|
||||
}
|
||||
@@ -95,6 +103,57 @@ TEST_CASE("Rugnux_AzInt", "[HDF5][Full]") {
|
||||
REQUIRE(H5Fget_obj_count(H5F_OBJ_ALL, H5F_OBJ_ALL) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Rugnux_ProcessFileKeepsXfelIds", "[HDF5][Full]") {
|
||||
// The pulse ID and event code of each processed image go into the _process.h5 at the image's place in
|
||||
// it, the place its reflections are stored at: here images 1, 4 and 7 of ten (-s 1 -e 9, stride 3).
|
||||
WriteTestDataset("process_xfel_in", 10, false, true);
|
||||
{
|
||||
// The master of a pulsed-source run carries them too, not only its data file.
|
||||
HDF5ReadOnlyFile file("process_xfel_in_master.h5");
|
||||
CHECK(file.ReadOptVector<uint64_t>("/entry/xfel/pulseID").size() == 10);
|
||||
}
|
||||
|
||||
JFJochHDF5Reader reader;
|
||||
REQUIRE_NOTHROW(reader.ReadFile("process_xfel_in_master.h5"));
|
||||
auto dataset = reader.GetDataset();
|
||||
REQUIRE(dataset);
|
||||
REQUIRE(dataset->xfel_pulse_id.size() == 10);
|
||||
CHECK(dataset->xfel_pulse_id[9] == 1063);
|
||||
|
||||
ProcessConfig config;
|
||||
config.mode = ProcessMode::AzimuthalIntegration;
|
||||
config.nthreads = 2;
|
||||
config.start_image = 1;
|
||||
config.end_image = 9;
|
||||
config.stride = 3;
|
||||
ProcessFileSink sink("process_xfel_out");
|
||||
config.image_sink = &sink;
|
||||
|
||||
Rugnux process(reader, dataset->experiment, *dataset->pixel_mask, config);
|
||||
ProcessResult result;
|
||||
REQUIRE_NOTHROW(result = process.Run());
|
||||
CHECK(result.images_processed == 3);
|
||||
|
||||
{
|
||||
HDF5ReadOnlyFile file("process_xfel_out_process.h5");
|
||||
CHECK(file.ReadOptVector<uint64_t>("/entry/xfel/pulseID") == std::vector<uint64_t>{1007, 1028, 1049});
|
||||
CHECK(file.ReadOptVector<uint32_t>("/entry/xfel/eventCode") == std::vector<uint32_t>{1, 0, 3});
|
||||
CHECK(file.ReadOptVector<uint64_t>("/entry/detector/number") == std::vector<uint64_t>{1, 4, 7});
|
||||
}
|
||||
{
|
||||
// ... and read back with the process file.
|
||||
JFJochHDF5Reader out;
|
||||
REQUIRE_NOTHROW(out.ReadFile("process_xfel_out_process.h5"));
|
||||
CHECK(out.GetDataset()->xfel_pulse_id == std::vector<uint64_t>{1007, 1028, 1049});
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
remove("process_xfel_in_master.h5");
|
||||
remove("process_xfel_in_data_000001.h5");
|
||||
remove("process_xfel_out_process.h5");
|
||||
REQUIRE(H5Fget_obj_count(H5F_OBJ_ALL, H5F_OBJ_ALL) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Rugnux_ProcessFileWithoutImages", "[HDF5][Full]") {
|
||||
// A reader with no single HDF5 file to link to (here several inputs read as one) gets a _process.h5
|
||||
// with the per-image analysis and no /entry/data/data, which reads back with its images' metadata
|
||||
|
||||
Reference in new issue
Block a user