Build Packages / build:viewer-tgz:cpu (push) Successful in 11m45s
Build Packages / build:viewer-tgz:cuda (push) Successful in 17m11s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 18m59s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 21m9s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 24m51s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 25m1s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 21m32s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 17m49s
Build Packages / build:rpm (rocky8) (push) Successful in 23m8s
Build Packages / build:rpm (rocky9) (push) Successful in 20m8s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 20m4s
Build Packages / XDS test (durin plugin) (push) Successful in 10m53s
Build Packages / Generate python client (push) Successful in 28s
Build Packages / Create release (push) Skipped
Build Packages / Build documentation (push) Successful in 1m30s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 23m22s
Build Packages / DIALS test (push) Successful in 18m9s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m55s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 8m56s
Build Packages / Unit tests (push) Successful in 1h54m52s
Build Packages / build:windows:nocuda (push) Canceled after 0s
Build Packages / build:windows:cuda (push) Canceled after 0s
The powder panel could only calibrate the image on screen. Calibration is now a third page beside MX and AzInt, so the dataset button runs it over every image the same way it runs the other two - which is the point, since a powder ring is measured far better by summing a run than by one frame. The page carries the calibrant and the method (rings or spots); the interactive Guess/Refine buttons stay where they were and now share the one calibrant selection, so there is no second combo to drift. analyzeDataset() carries the ProcessMode rather than a bool: a third state was coming, and two bools would have had one combination that cannot be valid. The calibrant list gains ICE, which it could not offer before: the widget worked in unit cells, and hexagonal ice has none that generates its rings correctly (P6_3/mmc would include systematically absent ones). FindCenter now takes the ring list its first line used to derive, so the interactive path gets ice as well. The result window leads with the residual rms rather than the fitted sigma. The sigma is a formal scatter estimate and understates a bad fit badly - measured on ice, 0.215 px reported against a 1.70 px residual - while the rms separates a usable fit from one that has locked onto the wrong thing. A rings run needs the profile binned in azimuth; below four sectors it returns nothing at all. The viewer raises the count to 32 exactly as the CLI does, and says so in the panel and in the job dialog rather than doing it silently. Also fixes a CLI inconsistency this comparison exposed: rugnux's calibration branch never applied the standard offline analysis defaults, so it measured the rings in a profile built with the file's polarization factor while every other mode - and the viewer - uses 0.99. Found because the two disagreed by 0.005 px in PONI x, and confirmed by reproducing the viewer exactly with --polarization 0.99. With it applied the CLI and the viewer write byte-identical .poni files on LaB6 by rings, LaB6 by spots, and an iced dataset over 1800 images. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
112 lines
4.8 KiB
C++
112 lines
4.8 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "PowderCalibrationWidget.h"
|
|
#include <QPushButton>
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include "../../common/JFJochMath.h"
|
|
|
|
#include "../image_analysis/geom_refinement/AssignSpotsToRings.h"
|
|
#include "../image_analysis/geom_refinement/Calibrants.h"
|
|
|
|
PowderCalibrationWidget::PowderCalibrationWidget(QWidget *parent) : QWidget(parent) {
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
calibrantCombo = new QComboBox(this);
|
|
updateCalibrantList();
|
|
|
|
// How a whole-dataset run measures the rings. The two buttons below always work from the spots of
|
|
// the image on screen, so this only takes effect for "Analyze dataset".
|
|
methodCombo = new QComboBox(this);
|
|
methodCombo->addItem("Rings (summed profile)", static_cast<int>(CalibrationMethod::Rings));
|
|
methodCombo->addItem("Spots (pooled spot lists)", static_cast<int>(CalibrationMethod::Spots));
|
|
methodCombo->setToolTip("How \"Analyze dataset\" measures the powder rings: rings sums the "
|
|
"(q x azimuth) azimuthal profile over every image and fits the ring arcs in it; "
|
|
"spots pools the found spots and fits those.");
|
|
|
|
auto findBeamCenterButton = new QPushButton("Guess detector calibration", this);
|
|
connect(findBeamCenterButton, &QPushButton::clicked,this, &PowderCalibrationWidget::findBeamCenterClicked);
|
|
|
|
auto optimizeBeamCenterButton = new QPushButton("Refine detector calibration", this);
|
|
connect(optimizeBeamCenterButton, &QPushButton::clicked,this, &PowderCalibrationWidget::optimizeBeamCenterClicked);
|
|
|
|
auto calibrantRingsButton = new QPushButton("Display calibrant rings", this);
|
|
connect(calibrantRingsButton, &QPushButton::clicked, this, [this]() {
|
|
QVector<float> d_rings;
|
|
for (float q : GetCalibrantRings())
|
|
d_rings.append(2 * PI / q);
|
|
emit ringsFromCalibration(d_rings);
|
|
});
|
|
|
|
auto refine_row = new QGridLayout();
|
|
refine_row->setSpacing(12);
|
|
refine_row->addWidget(new QLabel("Calibrant:"),0,0);
|
|
refine_row->addWidget(calibrantCombo,0,1);
|
|
refine_row->addWidget(findBeamCenterButton,1, 0);
|
|
refine_row->addWidget(optimizeBeamCenterButton,1, 1);
|
|
|
|
refine_row->addWidget(calibrantRingsButton,2, 0);
|
|
|
|
refine_row->addWidget(new QLabel("Dataset method:"),3,0);
|
|
refine_row->addWidget(methodCombo,3,1);
|
|
|
|
auto hint = new QLabel("The two buttons fit the image on screen; \"Analyze dataset\" fits the whole "
|
|
"run and writes a .poni.", this);
|
|
hint->setWordWrap(true);
|
|
hint->setStyleSheet("color: gray;");
|
|
|
|
layout->addLayout(refine_row);
|
|
layout->addWidget(hint);
|
|
setLayout(layout);
|
|
}
|
|
|
|
std::vector<float> PowderCalibrationWidget::GetCalibrantRings() const {
|
|
// The combo lists the shared calibrant table (in its order), then the current sample's own cell,
|
|
// which is not a powder standard but is what a single-crystal image's spots actually sit on.
|
|
const int idx = calibrantCombo->currentIndex();
|
|
const auto &table = Calibrants();
|
|
if (idx >= 0 && idx < static_cast<int>(table.size()))
|
|
return CalibrantRings(table[idx].name);
|
|
if (sample_cell)
|
|
return CalculateXtalRings(sample_cell.value());
|
|
return CalibrantRings(table.front().name);
|
|
}
|
|
|
|
CalibrationSelection PowderCalibrationWidget::Selection() const {
|
|
return {calibrantCombo->currentText(), GetCalibrantRings(),
|
|
static_cast<CalibrationMethod>(methodCombo->currentData().toInt())};
|
|
}
|
|
|
|
void PowderCalibrationWidget::updateCalibrantList() {
|
|
calibrantCombo->clear();
|
|
|
|
for (const auto &c : Calibrants())
|
|
calibrantCombo->addItem(QString::fromStdString(c.name));
|
|
if (sample_cell)
|
|
calibrantCombo->addItem(QString("Current sample (%1 %2 %3 %4 %5 %6)")
|
|
.arg(QString::number(sample_cell->a, 'f', 1))
|
|
.arg(QString::number(sample_cell->b, 'f', 1))
|
|
.arg(QString::number(sample_cell->c, 'f', 1))
|
|
.arg(QString::number(sample_cell->alpha, 'f', 1))
|
|
.arg(QString::number(sample_cell->beta, 'f', 1))
|
|
.arg(QString::number(sample_cell->gamma, 'f', 1)));
|
|
calibrantCombo->setCurrentIndex(0);
|
|
}
|
|
|
|
void PowderCalibrationWidget::loadImage(std::shared_ptr<const JFJochReaderImage> image) {
|
|
if (image)
|
|
sample_cell = image->Dataset().experiment.GetUnitCell();
|
|
updateCalibrantList();
|
|
}
|
|
|
|
void PowderCalibrationWidget::findBeamCenterClicked() {
|
|
const std::vector<float> rings = GetCalibrantRings();
|
|
emit findBeamCenter(QVector<float>(rings.begin(), rings.end()), true);
|
|
}
|
|
|
|
void PowderCalibrationWidget::optimizeBeamCenterClicked() {
|
|
const std::vector<float> rings = GetCalibrantRings();
|
|
emit findBeamCenter(QVector<float>(rings.begin(), rings.end()), false);
|
|
}
|