The serial pre-pass runs once on the first stills_prepass_images frames (new rugnux live setting, default 1000, 100-20000, reset to 1000 by POST /initialize) instead of the doubling stages (500 -> ... -> 2000 frames, stop at 200 geometry frames). One decision: with a cell and at least RUGNUX_LIVE_GEOMETRY_MIN_FRAMES (50) strong frames among them, the beam centre, distance and cell are refined on them; otherwise the header geometry is used exactly as given - the rugnux pre-pass then neither fits nor tries a centre (ProcessConfig::stills_geometry_min_frames), and StillsGPUAnalysis applies beam/distance/cell only where the fit ran. The X-ray-only steps (saturation, shadow, defective pixels, polarization, background ring, powder rings) run as before on the start of the window; the background beam-centre estimate is reported, not applied, when the geometry is kept. Log and live-status notes say "Geometry refined from K of N frames" or "Fewer than 50 strong frames in the first N: header geometry used". Where the hold (at most half of the image buffer) fills before N frames, the pre-pass runs on those held and says so. The first N images are always analysed under stills_downsample. Rotation is unaffected. Two fixes in the stills geometry: - The refit (bundle indexed again at the fitted geometry) was skipped on every modular detector whenever the modules were not being placed, i.e. always live: placing_modules now also needs refine_modules. Offline, where the first fit places the modules and so skips its refit, the fit is run again from the placed geometry, as after a centre the trial moved. - The local beam-centre grid no longer adopts a chance maximum: it moves the centre only from one that puts spots on the lattice. OpenAPI: rugnux_settings/rugnux_status.stills_prepass_images; C++ model, frontend client and python client docs regenerated; frontend settings field. jfjoch_stills_gpu_replay and jfjoch_fpga_stills_test take -P <images>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3
73 lines
3.2 KiB
C++
73 lines
3.2 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "StillsPrePass.h"
|
|
|
|
#include "../common/JFJochException.h"
|
|
#include "../reader/JFJochReader.h"
|
|
#include "../reader/JFJochStartMessageReader.h"
|
|
#include "../rugnux/RugnuxLive.h"
|
|
|
|
namespace {
|
|
// The held images as a collection of their own, numbered from 0 as the collection numbers them.
|
|
class HeldImageReader : public JFJochReader {
|
|
const std::map<int64_t, std::shared_ptr<HeldImage>> &images;
|
|
uint64_t number_of_images;
|
|
|
|
bool LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset, DataMessage &message,
|
|
std::vector<uint8_t> &, int64_t image_number, bool) override {
|
|
const auto it = images.find(image_number);
|
|
if (!dataset || it == images.end())
|
|
return false;
|
|
message = it->second->message;
|
|
return true;
|
|
}
|
|
public:
|
|
HeldImageReader(const StartMessage &start, const std::map<int64_t, std::shared_ptr<HeldImage>> &in_images)
|
|
: images(in_images), number_of_images(in_images.empty() ? 0 : in_images.rbegin()->first + 1) {
|
|
SetStartMessage(DatasetFromStartMessage(start, default_experiment));
|
|
}
|
|
|
|
[[nodiscard]] uint64_t GetNumberOfImages() const override { return number_of_images; }
|
|
void Close() override {}
|
|
|
|
bool ReadRawImage(int64_t image_number, JFJochReaderRawImage &ret) override {
|
|
const auto it = images.find(image_number);
|
|
if (it == images.end())
|
|
return false;
|
|
ret.image = it->second->message.image;
|
|
return true;
|
|
}
|
|
|
|
std::vector<SpotToSave> ReadSpots(int64_t) const override { return {}; }
|
|
};
|
|
}
|
|
|
|
StillsPrePassResult RunStillsPrePass(const StartMessage &start, const std::map<int64_t, std::shared_ptr<HeldImage>> &images,
|
|
int nthreads, std::optional<int64_t> max_spot_count) {
|
|
HeldImageReader reader(start, images);
|
|
const auto dataset = reader.GetDataset();
|
|
const RugnuxLiveSetup setup = MakeRugnuxStillsPrePassSetup(*dataset, nthreads, max_spot_count);
|
|
|
|
Rugnux rugnux(reader, setup.experiment, *dataset->pixel_mask, setup.config);
|
|
const ProcessResult result = rugnux.Run();
|
|
Rugnux::ReleasePinnedPool();
|
|
|
|
return StillsPrePassResult{
|
|
// Where the beam lands: a tilt the run refined moves its PONI, not this
|
|
.beam_x_pxl = static_cast<float>(result.used_direct_beam_x_pxl),
|
|
.beam_y_pxl = static_cast<float>(result.used_direct_beam_y_pxl),
|
|
.distance_mm = result.used_distance_mm,
|
|
.mask = rugnux.GetPixelMask(),
|
|
.images = images.size(),
|
|
.geometry_frames = result.stills_geometry_frames,
|
|
.background_centre = result.background_beam_centre,
|
|
.cell = rugnux.GetExperiment().GetUnitCell(),
|
|
.max_spot_count = rugnux.GetExperiment().GetMaxSpotCount(),
|
|
.polarization = rugnux.GetExperiment().GetPolarizationFactor(),
|
|
.integration = rugnux.GetExperiment().GetBraggIntegrationSettings(),
|
|
.run_width = rugnux.GetStillsRunWidth(),
|
|
.window = rugnux.GetStillsWindow()
|
|
};
|
|
}
|