From 83f467d4dcebc4493d985d8f455d28849fd27212 Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Fri, 5 Jun 2026 14:17:19 +0200 Subject: [PATCH] Add mechanics to save per spot lattice information (WIP) --- common/DiffractionSpot.cpp | 5 +++-- common/SpotToSave.h | 8 ++++---- docs/CBOR.md | 1 + frame_serialize/CBORStream2Deserializer.cpp | 2 ++ frame_serialize/CBORStream2Serializer.cpp | 1 + image_analysis/indexing/AnalyzeIndexing.cpp | 5 +++-- reader/JFJochHDF5Reader.cpp | 13 +++++++++++-- writer/HDF5DataFilePluginMX.cpp | 6 +++++- writer/HDF5DataFilePluginMX.h | 1 + writer/HDF5NXmx.cpp | 5 +++-- 10 files changed, 34 insertions(+), 13 deletions(-) diff --git a/common/DiffractionSpot.cpp b/common/DiffractionSpot.cpp index a3e7789c..5e6a8857 100644 --- a/common/DiffractionSpot.cpp +++ b/common/DiffractionSpot.cpp @@ -82,9 +82,10 @@ std::optional DiffractionSpot::Export(const DiffractionGeometry &geo .phi = phi, .intensity = static_cast(photons), .maxc = max_photons, + .lattice = -1, + .image = image_num, .d_A = d, .ice_ring = false, - .indexed = false, - .image = image_num + .indexed = false }; } diff --git a/common/SpotToSave.h b/common/SpotToSave.h index 114a9995..d866acbc 100644 --- a/common/SpotToSave.h +++ b/common/SpotToSave.h @@ -11,13 +11,13 @@ struct SpotToSave { float phi = 0; float intensity = 0; int64_t maxc = 0; + int64_t lattice = -1; // -1 non indexed + int64_t image = 0; + int64_t h = 0, k = 0, l= 0; float d_A = 0.0; + float dist_ewald_sphere = 0.0; bool ice_ring = false; bool indexed = false; - int64_t image = 0; - - int64_t h = 0, k = 0, l= 0; - float dist_ewald_sphere = 0.0; Coord ReciprocalCoord(const DiffractionGeometry &experiment) const; }; diff --git a/docs/CBOR.md b/docs/CBOR.md index 4fe098ee..58fb8bb9 100644 --- a/docs/CBOR.md +++ b/docs/CBOR.md @@ -136,6 +136,7 @@ See [DECTRIS documentation](https://github.com/dectris/documentation/tree/main/s | - maxc | int64 | max count (photons) | | | | - ice_ring | bool | spot in resolution range for ice rings | | | | - indexed | bool | indexed solution | | | +| - latt | int64 | Lattice to which the peak belongs (negative number = not indexed) | | | | reflections | Array(object) | Reflections: | | | | - h | int64 | Miller index | | | | - k | int64 | Miller index | | | diff --git a/frame_serialize/CBORStream2Deserializer.cpp b/frame_serialize/CBORStream2Deserializer.cpp index fff2fa91..e566beb9 100644 --- a/frame_serialize/CBORStream2Deserializer.cpp +++ b/frame_serialize/CBORStream2Deserializer.cpp @@ -446,6 +446,8 @@ namespace { s.ice_ring = GetCBORBool(map_value); else if (key == "indexed") s.indexed = GetCBORBool(map_value); + else if (key == "latt") + s.lattice = GetCBORInt(map_value); else if (key == "h") s.h = GetCBORInt(map_value); else if (key == "k") diff --git a/frame_serialize/CBORStream2Serializer.cpp b/frame_serialize/CBORStream2Serializer.cpp index 8f3cde3c..0d2eae87 100644 --- a/frame_serialize/CBORStream2Serializer.cpp +++ b/frame_serialize/CBORStream2Serializer.cpp @@ -224,6 +224,7 @@ inline void CBOR_ENC(CborEncoder &encoder, const SpotToSave& spot) { CBOR_ENC(mapEncoder, "maxc", spot.maxc); CBOR_ENC(mapEncoder, "ice_ring", spot.ice_ring); CBOR_ENC(mapEncoder, "indexed", spot.indexed); + CBOR_ENC(mapEncoder, "latt", spot.lattice); CBOR_ENC(mapEncoder, "image", spot.image); if (spot.indexed) { CBOR_ENC(mapEncoder, "h", spot.h); diff --git a/image_analysis/indexing/AnalyzeIndexing.cpp b/image_analysis/indexing/AnalyzeIndexing.cpp index 8d02357b..a8a682c8 100644 --- a/image_analysis/indexing/AnalyzeIndexing.cpp +++ b/image_analysis/indexing/AnalyzeIndexing.cpp @@ -354,9 +354,10 @@ bool AnalyzeIndexing(DataMessage &message, if (ok(uc.a) && ok(uc.b) && ok(uc.c) && ok(uc.alpha) && ok(uc.beta) && ok(uc.gamma)) { message.indexing_result = true; assert(indexed_spots.size() == message.spots.size()); - for (int i = 0; i < message.spots.size(); i++) + for (int i = 0; i < message.spots.size(); i++) { message.spots[i].indexed = indexed_spots[i]; - + message.spots[i].lattice = 0; + } message.profile_radius = FitProfileRadius(message.spots); message.spot_count_indexed = nspots_indexed; message.indexing_lattice = latt; diff --git a/reader/JFJochHDF5Reader.cpp b/reader/JFJochHDF5Reader.cpp index 0a4e4dce..2df28081 100644 --- a/reader/JFJochHDF5Reader.cpp +++ b/reader/JFJochHDF5Reader.cpp @@ -785,6 +785,13 @@ static void ReadSpotsFromFiles(HDF5Object &master_file, "/entry/MX/peakL", {master_image, 0}, {source_image, 0}, {1, spot_count} ); + + auto spot_lattice = ReadVectorMasterFirst( + master_file, source_file, + "/entry/MX/peakLattice", + {master_image, 0}, {source_image, 0}, {1, spot_count} + ); + auto spot_dist_ewald_sphere = ReadVectorMasterFirst( master_file, source_file, "/entry/MX/peakDistEwaldSphere", @@ -800,8 +807,8 @@ static void ReadSpotsFromFiles(HDF5Object &master_file, .x = x, .y = y, .intensity = spot_intensity.at(i), - .d_A = geom.PxlToRes(x, y), - .image = image_number + .image = image_number, + .d_A = geom.PxlToRes(x, y) }; if (spot_indexed.size() > i) s.indexed = (spot_indexed.at(i) != 0); @@ -815,6 +822,8 @@ static void ReadSpotsFromFiles(HDF5Object &master_file, s.dist_ewald_sphere = spot_dist_ewald_sphere.at(i); if (spot_ice.size() > i) s.ice_ring = (spot_ice.at(i) != 0); + if (spot_lattice.size() > i) + s.lattice = spot_lattice.at(i); message.spots.emplace_back(s); } diff --git a/writer/HDF5DataFilePluginMX.cpp b/writer/HDF5DataFilePluginMX.cpp index 7f7ab6bb..e49ac866 100644 --- a/writer/HDF5DataFilePluginMX.cpp +++ b/writer/HDF5DataFilePluginMX.cpp @@ -72,6 +72,7 @@ void HDF5DataFilePluginMX::OpenFile(HDF5File &data_file, const DataMessage &msg, spot_h.reserve(max_spots * images_per_file); spot_k.reserve(max_spots * images_per_file); spot_l.reserve(max_spots * images_per_file); + spot_lattice.reserve(max_spots * images_per_file); spot_dist_ewald.reserve(max_spots * images_per_file); if (indexing) spot_indexed.reserve(max_spots * images_per_file); @@ -118,7 +119,8 @@ void HDF5DataFilePluginMX::Write(const DataMessage &msg, uint64_t image_number) spot_h.resize(max_spots * (max_image_number + 1)); spot_k.resize(max_spots * (max_image_number + 1)); spot_l.resize(max_spots * (max_image_number + 1)); - spot_dist_ewald.resize(max_spots * (max_image_number + 1)); + spot_lattice.resize(max_spots * (max_image_number + 1), -1); + spot_dist_ewald.resize(max_spots * (max_image_number + 1), NAN); if (indexing) spot_indexed.resize(max_spots * (max_image_number + 1)); @@ -134,6 +136,7 @@ void HDF5DataFilePluginMX::Write(const DataMessage &msg, uint64_t image_number) spot_int[max_spots * image_number + i] = msg.spots[i].intensity; if (indexing) { spot_indexed[max_spots * image_number + i] = msg.spots[i].indexed; + spot_lattice[max_spots * image_number + i] = msg.spots[i].lattice; spot_h[max_spots * image_number + i] = msg.spots[i].h; spot_k[max_spots * image_number + i] = msg.spots[i].k; spot_l[max_spots * image_number + i] = msg.spots[i].l; @@ -204,6 +207,7 @@ void HDF5DataFilePluginMX::WriteFinal(HDF5File &data_file) { data_file.SaveVector("/entry/MX/peakDistEwaldSphere", spot_dist_ewald, {(hsize_t) (max_image_number + 1), max_spots}); data_file.SaveVector("/entry/MX/peakIndexed", spot_indexed, {(hsize_t) (max_image_number + 1), max_spots}); + data_file.SaveVector("/entry/MX/peakLattice", spot_lattice, {(hsize_t) (max_image_number + 1), max_spots}); } } diff --git a/writer/HDF5DataFilePluginMX.h b/writer/HDF5DataFilePluginMX.h index 2c441561..c239de96 100644 --- a/writer/HDF5DataFilePluginMX.h +++ b/writer/HDF5DataFilePluginMX.h @@ -15,6 +15,7 @@ class HDF5DataFilePluginMX : public HDF5DataFilePlugin { std::vector spot_int; std::vector spot_indexed; std::vector spot_ice_ring; + std::vector spot_lattice; std::vector spot_h; std::vector spot_k; std::vector spot_l; diff --git a/writer/HDF5NXmx.cpp b/writer/HDF5NXmx.cpp index 5a45a78c..45d6849f 100644 --- a/writer/HDF5NXmx.cpp +++ b/writer/HDF5NXmx.cpp @@ -126,12 +126,13 @@ void NXmx::LinkToData_VDS(const StartMessage &start, const EndMessage &end) { VDS(start, "/entry/MX/peakXPosRaw",{total_images, start.max_spot_count}, HDF5DataType(0.0f)); VDS(start, "/entry/MX/peakYPosRaw",{total_images, start.max_spot_count}, HDF5DataType(0.0f)); VDS(start, "/entry/MX/peakTotalIntensity",{total_images, start.max_spot_count}, HDF5DataType(0.0f)); - VDS(start, "/entry/MX/peakIceRingRes", {total_images, start.max_spot_count}, HDF5DataType((uint8_t) 0)); + VDS(start, "/entry/MX/peakIceRingRes", {total_images, start.max_spot_count}, HDF5DataType(static_cast(0))); VDS(start, "/entry/MX/nPeaks", {total_images}, HDF5DataType((uint32_t) 0)); } if (start.indexing_algorithm != IndexingAlgorithmEnum::None) { - VDS(start, "/entry/MX/peakIndexed", {total_images, start.max_spot_count}, HDF5DataType((uint8_t) 0)); + VDS(start, "/entry/MX/peakIndexed", {total_images, start.max_spot_count}, HDF5DataType(static_cast(0))); + VDS(start, "/entry/MX/peakLattice", {total_images, start.max_spot_count}, HDF5DataType(static_cast(-1))); VDS(start, "/entry/MX/peakH", {total_images, start.max_spot_count}, HDF5DataType((int32_t) 0)); VDS(start, "/entry/MX/peakK", {total_images, start.max_spot_count}, HDF5DataType((int32_t) 0)); VDS(start, "/entry/MX/peakL", {total_images, start.max_spot_count}, HDF5DataType((int32_t) 0));