Files
Jungfraujoch/image_analysis/scale_merge/ScaleAndMerge.h
Filip Leonarski 64002f1e29
Some checks failed
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 11m14s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 10m43s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 11m35s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 9m20s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 10m23s
Build Packages / Generate python client (push) Successful in 39s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 11m24s
Build Packages / Create release (push) Has been skipped
Build Packages / Build documentation (push) Successful in 1m0s
Build Packages / build:rpm (rocky8) (push) Successful in 10m35s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 10m35s
Build Packages / build:rpm (rocky9) (push) Successful in 11m17s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 9m9s
Build Packages / Unit tests (push) Failing after 1h18m57s
v1.0.0-rc.129 (#36)
This is an UNSTABLE release. The release has significant modifications and bug fixes, if things go wrong, it is better to revert to 1.0.0-rc.124.

* jfjoch_broker: Significant improvements in TCP image socket, as a viable alternative for ZeroMQ sockets (only a single port on broker side, dynamically change number of writers, acknowledgments for written files)
* jfjoch_broker: Delta phi is calculated also for still data in Bragg prediction
* jfjoch_broker: Image pusher statistics are accessible via the REST interface
* jfjoch_writer: Supports TCP image socket and for these auto-forking option

Reviewed-on: #36
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-03-05 22:13:12 +01:00

94 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <vector>
#include <cstdint>
#include <optional>
#include "../../common/Reflection.h"
#include "gemmi/symmetry.hpp"
struct ScaleMergeOptions {
int max_num_iterations = 100;
double max_solver_time_s = 1.0;
double image_number_rounding = 1.0;
double min_sigma = 1e-3;
// Symmetry canonicalization of HKL prior to merging/scaling.
// If not set, the routine uses raw HKL as-is.
std::optional<gemmi::SpaceGroup> space_group;
// If true, treat Friedel mates as equivalent (merge anomalous pairs).
// If false, keep them separate by including a sign flag in the HKL key.
bool merge_friedel = true;
// --- Kabsch(XDS)-style partiality model ---
// Rotation range (wedge) used in partiality calculation.
// Set to 0 to disable partiality correction.
std::optional<double> wedge_deg;
// --- Mosaicity (user input in degrees; internally converted to radians) ---
double mosaicity_init_deg = 0.17;
double mosaicity_min_deg = 1e-3;
double mosaicity_max_deg = 2.0;
std::vector<double> mosaicity_init_deg_vec;
// --- Optional: regularize per-image scale k towards 1 (Kabsch-like) ---
bool regularize_scale_to_one = true;
double scale_regularization_sigma = 0.05;
double min_partiality_for_merge = 0.2;
bool smoothen_g = true;
bool smoothen_mos = true;
double d_min_limit_A = 0.0;
int64_t image_cluster = 1;
bool refine_wedge = false;
enum class PartialityModel {Fixed, Rotation, Unity, Still} partiality_model = PartialityModel::Fixed;
};
struct MergedReflection {
int h;
int k;
int l;
double I;
double sigma;
double d = 0.0;
};
/// Per-resolution-shell merging statistics
struct MergeStatisticsShell {
float d_min = 0.0f; ///< High-resolution limit of this shell (Å)
float d_max = 0.0f; ///< Low-resolution limit of this shell (Å)
float mean_one_over_d2 = 0; ///< Mean 1/d² in shell
int total_observations = 0; ///< Total number of (corrected) observations
int unique_reflections = 0; ///< Number of unique HKLs with observations
double rmeas = 0.0; ///< Redundancy-independent merging R-factor
double mean_i_over_sigma = 0.0; ///< Mean I/σ(I) of the merged reflections
double completeness = 0.0; ///< Fraction of possible reflections observed (0 if unknown)
int possible_reflections = 0;///< Theoretical number of reflections in this shell (0 if unknown)
};
/// Overall + per-shell merging statistics
struct MergeStatistics {
std::vector<MergeStatisticsShell> shells;
MergeStatisticsShell overall; ///< Statistics over all shells combined
};
struct ScaleMergeResult {
std::vector<MergedReflection> merged;
std::vector<float> image_scale_g;
std::vector<float> mosaicity_deg;
/// Per-shell and overall merging statistics (populated after merging)
MergeStatistics statistics;
};
ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector<std::vector<Reflection>>& observations,
const ScaleMergeOptions& opt = {});