Files
Jungfraujoch/rugnux/RugnuxCommandLine.cpp
T
leonarski_fandClaude Fable 5 01e4f81e44
Build Packages / build:windows:cuda (push) Failing after 5m34s
Build Packages / build:viewer-tgz:cpu (push) Successful in 7m45s
Build Packages / build:viewer-tgz:cuda (push) Successful in 9m5s
Build Packages / build:windows:nocuda (push) Successful in 10m37s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 12m54s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 13m6s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 13m25s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 13m38s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 13m47s
Build Packages / build:rpm (rocky8) (push) Successful in 11m1s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 12m35s
Build Packages / XDS test (durin plugin) (push) Successful in 7m43s
Build Packages / Generate python client (push) Successful in 35s
Build Packages / Build documentation (push) Successful in 1m1s
Build Packages / Create release (push) Skipped
Build Packages / build:rpm (ubuntu2404) (push) Successful in 11m3s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 12m53s
Build Packages / build:rpm (rocky9) (push) Successful in 13m4s
Build Packages / DIALS test (push) Successful in 13m38s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m34s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 8m15s
Build Packages / Unit tests (push) Successful in 1h0m56s
Consolidate offline tools into rugnux; merge on by default
Fold jfjoch_azint and rugnux_scale into the single rugnux CLI, and flip
scaling/merging from opt-in to on-by-default.

- rugnux --azint-only replaces jfjoch_azint (reuses ProcessMode::
  AzimuthalIntegration; adds the correction toggles and geometry overrides
  the old tool carried).
- rugnux --scale replaces rugnux_scale (re-scale/merge stored reflections,
  same simpler scale/merge as before: no space-group search or rot3d
  defaults). Its workflow is folded into the CLI verbatim.
- Merging is now on by default for rotation and stills; --no-merge disables
  it, replacing -M/--scale-merge.

Also fix the batch ReadReflections reader so it works on rugnux's own
NXmxIntegrated _process.h5: read per-image reflections/mosaicity/lattice
from the master (global index) first, falling back to the source-data
locator for legacy/VDS datasets. Without this, both --scale and the former
rugnux_scale read zero reflections from an integrated snapshot.

RugnuxCommandLine now emits `rugnux --azint-only` and `--no-merge`; docs and
tests updated to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 14:09:15 +02:00

143 lines
5.3 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "RugnuxCommandLine.h"
#include "../common/DiffractionExperiment.h"
#include <sstream>
#include <vector>
namespace {
std::string quote_if_needed(const std::string &s) {
if (s.find_first_of(" \t\"'") == std::string::npos)
return s;
std::string out = "\"";
for (char c: s) {
if (c == '"' || c == '\\')
out += '\\';
out += c;
}
out += '"';
return out;
}
const char *indexing_alg_flag(IndexingAlgorithmEnum a) {
switch (a) {
case IndexingAlgorithmEnum::FFBIDX: return "ffbidx";
case IndexingAlgorithmEnum::FFT: return "fft";
case IndexingAlgorithmEnum::FFTW: return "fftw";
case IndexingAlgorithmEnum::None: return "none";
case IndexingAlgorithmEnum::Auto:
default: return "auto";
}
}
const char *refine_flag(GeomRefinementAlgorithmEnum r) {
switch (r) {
case GeomRefinementAlgorithmEnum::None: return "none";
case GeomRefinementAlgorithmEnum::OrientationOnly: return "orientation";
case GeomRefinementAlgorithmEnum::BeamCenter:
default: return "beam_and_lattice";
}
}
std::string num(double v) {
std::ostringstream o;
o << v;
return o.str();
}
}
std::string RugnuxCommandLine(const ProcessConfig &config,
const DiffractionExperiment &experiment,
const std::string &input_file) {
std::vector<std::string> args;
const bool azint = (config.mode == ProcessMode::AzimuthalIntegration);
args.emplace_back("rugnux");
if (azint)
args.emplace_back("--azint-only");
auto add = [&](const std::string &flag, const std::string &val) {
args.push_back(flag);
args.push_back(val);
};
if (!config.output_prefix.empty())
add("-o", config.output_prefix);
add("-N", std::to_string(config.nthreads));
if (config.start_image != 0)
add("-s", std::to_string(config.start_image));
if (config.end_image >= 0)
add("-e", std::to_string(config.end_image));
if (config.stride != 1)
add("-t", std::to_string(config.stride));
if (azint) {
const auto a = experiment.GetAzimuthalIntegrationSettings();
add("--azim-min-q", num(a.GetLowQ_recipA()));
add("--azim-max-q", num(a.GetHighQ_recipA()));
add("--azim-q-spacing", num(a.GetQSpacing_recipA()));
add("--azim-phi-bins", std::to_string(a.GetAzimuthalBinCount()));
add("--polarization-correction", a.IsPolarizationCorrection() ? "on" : "off");
add("--solid-angle-correction", a.IsSolidAngleCorrection() ? "on" : "off");
} else {
const auto &sf = config.spot_finding;
add("--spot-sigma", num(sf.signal_to_noise_threshold));
add("--spot-threshold", std::to_string(sf.photon_count_threshold));
add("--spot-high-resolution", num(sf.high_resolution_limit));
add("--max-spots", std::to_string(experiment.GetMaxSpotCount()));
const auto idx = experiment.GetIndexingSettings();
add("-X", indexing_alg_flag(idx.GetAlgorithm()));
add("-r", refine_flag(idx.GetGeomRefinementAlgorithm()));
if (const auto sg = experiment.GetSpaceGroupNumber())
add("-S", std::to_string(*sg));
if (const auto uc = experiment.GetUnitCell()) {
std::ostringstream o;
o << uc->a << "," << uc->b << "," << uc->c << "," << uc->alpha << "," << uc->beta << "," << uc->gamma;
add("-C", o.str());
}
if (const auto bw = experiment.GetBandwidthFWHM())
add("--bandwidth", num(*bw));
const auto bragg = experiment.GetBraggIntegrationSettings();
std::ostringstream radii;
radii << bragg.GetR1() << "," << bragg.GetR2() << "," << bragg.GetR3();
add("--integration-radius", radii.str());
if (config.rotation_indexing) {
if (config.two_pass_rotation)
add("-R", std::to_string(config.rotation_indexing_image_count));
else
args.emplace_back("--single-pass-rotation");
if (!config.reuse_rotation_spots)
args.emplace_back("--redo-rotation-spots");
} else if (experiment.GetGoniometer().has_value()) {
// rotation dataset processed as stills -> the user overrode the default with --force-still
args.emplace_back("--force-still");
}
// Merging is on by default; emit --no-merge only when it was turned off.
if (config.run_scaling) {
const auto sc = experiment.GetScalingSettings();
if (!sc.GetMergeFriedel())
args.emplace_back("-A");
if (sc.GetRefineB())
args.emplace_back("-B");
} else {
args.emplace_back("--no-merge");
}
}
args.push_back(input_file);
std::ostringstream cmd;
for (size_t i = 0; i < args.size(); i++) {
if (i)
cmd << ' ';
cmd << quote_if_needed(args[i]);
}
return cmd.str();
}