From c9ffe8d60e619b408792c09d053ac4e8c467f1e5 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 29 Nov 2025 15:53:36 +0100 Subject: [PATCH] SpotToSave: Add image number --- common/DiffractionSpot.cpp | 19 ++++++++++--------- common/DiffractionSpot.h | 2 +- common/SpotToSave.h | 1 + frame_serialize/CBORStream2Deserializer.cpp | 2 ++ frame_serialize/CBORStream2Serializer.cpp | 1 + image_analysis/spot_finding/SpotUtils.cpp | 2 +- image_analysis/spot_finding/SpotUtils.h | 6 ++++-- reader/JFJochHDF5Reader.cpp | 3 ++- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/common/DiffractionSpot.cpp b/common/DiffractionSpot.cpp index 67411559..0f71be57 100644 --- a/common/DiffractionSpot.cpp +++ b/common/DiffractionSpot.cpp @@ -65,16 +65,17 @@ void DiffractionSpot::ConvertToImageCoordinates(const DiffractionExperiment &exp this->y = c_out.y * (float) photons; } -SpotToSave DiffractionSpot::Export(const DiffractionGeometry &geometry) const { - auto d = geometry.PxlToRes(x / (float)photons, y / (float)photons); +SpotToSave DiffractionSpot::Export(const DiffractionGeometry &geometry, int64_t image_num) const { + auto d = geometry.PxlToRes(x / (float) photons, y / (float) photons); return { - .x = x / static_cast(photons), - .y = y / static_cast(photons), - .intensity = static_cast(photons), - .maxc = max_photons, - .d_A = d, - .ice_ring = false, - .indexed = false, + .x = x / static_cast(photons), + .y = y / static_cast(photons), + .intensity = static_cast(photons), + .maxc = max_photons, + .d_A = d, + .ice_ring = false, + .indexed = false, + .image = image_num }; } diff --git a/common/DiffractionSpot.h b/common/DiffractionSpot.h index 287e5e8e..f45ca71f 100644 --- a/common/DiffractionSpot.h +++ b/common/DiffractionSpot.h @@ -29,7 +29,7 @@ public: int64_t MaxCount() const; Coord RawCoord() const; void ConvertToImageCoordinates(const DiffractionExperiment& experiment, uint16_t module_number); - SpotToSave Export(const DiffractionGeometry &geometry) const; + SpotToSave Export(const DiffractionGeometry &geometry, int64_t image_num = 0) const; void AddPixel(uint32_t col, uint32_t line, int64_t photons); }; diff --git a/common/SpotToSave.h b/common/SpotToSave.h index f04e3043..ccdef978 100644 --- a/common/SpotToSave.h +++ b/common/SpotToSave.h @@ -14,6 +14,7 @@ struct SpotToSave { float d_A = 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; diff --git a/frame_serialize/CBORStream2Deserializer.cpp b/frame_serialize/CBORStream2Deserializer.cpp index 769bd11d..d64c5a26 100644 --- a/frame_serialize/CBORStream2Deserializer.cpp +++ b/frame_serialize/CBORStream2Deserializer.cpp @@ -418,6 +418,8 @@ namespace { s.l = GetCBORInt(map_value); else if (key == "dist_ewald") s.dist_ewald_sphere = GetCBORFloat(map_value); + else if (key == "image") + s.image = GetCBORInt(map_value); else cbor_value_advance(&map_value); } diff --git a/frame_serialize/CBORStream2Serializer.cpp b/frame_serialize/CBORStream2Serializer.cpp index 9272d3f4..5b335be1 100644 --- a/frame_serialize/CBORStream2Serializer.cpp +++ b/frame_serialize/CBORStream2Serializer.cpp @@ -207,6 +207,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, "image", spot.image); if (spot.indexed) { CBOR_ENC(mapEncoder, "h", spot.h); CBOR_ENC(mapEncoder, "k", spot.k); diff --git a/image_analysis/spot_finding/SpotUtils.cpp b/image_analysis/spot_finding/SpotUtils.cpp index ad1fb119..c5bac9f2 100644 --- a/image_analysis/spot_finding/SpotUtils.cpp +++ b/image_analysis/spot_finding/SpotUtils.cpp @@ -135,7 +135,7 @@ void SpotAnalyze(const DiffractionExperiment &experiment, std::vector spots_out; for (const auto &spot: spots) - spots_out.push_back(spot.Export(geom)); + spots_out.push_back(spot.Export(geom, output.number)); if (spot_finding_settings.high_res_gap_Q_recipA.has_value()) FilterSpuriousHighResolutionSpots(spots_out, spot_finding_settings.high_res_gap_Q_recipA.value()); diff --git a/image_analysis/spot_finding/SpotUtils.h b/image_analysis/spot_finding/SpotUtils.h index e07c7e5c..0404e2cf 100644 --- a/image_analysis/spot_finding/SpotUtils.h +++ b/image_analysis/spot_finding/SpotUtils.h @@ -28,7 +28,9 @@ void FilterSpuriousHighResolutionSpots(std::vector &spots, float thr // For 20 spots or more - take the 95% percentile best high resolution spot std::optional GetResolution(const std::vector &spots); -void SpotAnalyze(const DiffractionExperiment &experiment, const SpotFindingSettings &settings, - const std::vector &spots, DataMessage &message); +void SpotAnalyze(const DiffractionExperiment &experiment, + const SpotFindingSettings &settings, + const std::vector &spots, + DataMessage &message); #endif //JFJOCH_SPOTANALYSIS_H diff --git a/reader/JFJochHDF5Reader.cpp b/reader/JFJochHDF5Reader.cpp index 6b30301a..be9f2c0f 100644 --- a/reader/JFJochHDF5Reader.cpp +++ b/reader/JFJochHDF5Reader.cpp @@ -537,7 +537,8 @@ bool JFJochHDF5Reader::LoadImage_i(std::shared_ptr &dataset .x = x, .y = y, .intensity = spot_intensity.at(i), - .d_A = d + .d_A = d, + .image = image_number }; if (spot_indexed.size() > i) s.indexed = (spot_indexed.at(i) != 0);