The offline per-image scaling table had bare numeric columns. Prefix it with a '#' comment header (image_number scale_G bfactor_Ang2 mosaicity_deg wedge_deg cc_to_merge cc_n) so it is self-describing; numpy.loadtxt / gnuplot skip the comment line, so existing consumers are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ScalingResult.h"
|
|
#include <cmath>
|
|
#include <fstream>
|
|
|
|
#include "../../common/JFJochException.h"
|
|
|
|
ScalingResult::ScalingResult(size_t n)
|
|
: image_scale_g(n, NAN),
|
|
mosaicity_deg(n, NAN),
|
|
image_bfactor_Ang2(n, NAN),
|
|
rotation_wedge_deg(n, NAN),
|
|
image_cc(n, NAN),
|
|
image_cc_n(n, 0) {}
|
|
|
|
ScalingResult::ScalingResult(const std::vector<IntegrationOutcome> &v)
|
|
: image_scale_g(v.size(), NAN),
|
|
mosaicity_deg(v.size(), NAN),
|
|
image_bfactor_Ang2(v.size(), NAN),
|
|
rotation_wedge_deg(v.size(), NAN),
|
|
image_cc(v.size(), NAN),
|
|
image_cc_n(v.size(), 0) {
|
|
for (int i = 0; i < v.size(); i++) {
|
|
image_scale_g[i] = v[i].image_scale_g.value_or(NAN);
|
|
mosaicity_deg[i] = v[i].mosaicity_deg.value_or(NAN);
|
|
image_bfactor_Ang2[i] = v[i].image_scale_b_factor_Ang2.value_or(NAN);
|
|
rotation_wedge_deg[i] = v[i].image_scale_wedge_deg.value_or(NAN);
|
|
image_cc[i] = v[i].image_scale_cc.value_or(NAN);
|
|
image_cc_n[i] = v[i].image_scale_cc_n.value_or(0);
|
|
}
|
|
}
|
|
|
|
void ScalingResult::SaveToFile(const std::string &filename) {
|
|
const std::string img_path = filename + "_image.dat";
|
|
std::ofstream img_file(img_path, std::ofstream::out | std::ofstream::trunc);
|
|
if (!img_file) {
|
|
throw JFJochException(JFJochExceptionCategory::FileWriteError,
|
|
"Cannot open " + img_path + " for writing");
|
|
}
|
|
|
|
// Header so the columns are self-describing (lines starting with '#' are comments for gnuplot/numpy).
|
|
img_file << "# image_number scale_G bfactor_Ang2 mosaicity_deg wedge_deg cc_to_merge cc_n\n";
|
|
|
|
for (size_t i = 0; i < image_scale_g.size(); ++i) {
|
|
img_file << i
|
|
<< " " << image_scale_g[i]
|
|
<< " " << image_bfactor_Ang2[i]
|
|
<< " " << mosaicity_deg[i]
|
|
<< " " << rotation_wedge_deg[i]
|
|
<< " " << image_cc[i]
|
|
<< " " << image_cc_n[i]
|
|
<< "\n";
|
|
}
|
|
|
|
img_file.close();
|
|
}
|
|
|