Center finding¶
COSEDA estimates the per-frame beam center without indexing using Friedel symmetry and temporal trends. This chapter focuses on the Beamstop pipeline; see Center refinement for the follow-up smoothing stage.
This stage requires peak finding to have run first (
nPeaks,peakXPosRaw,peakYPosRawmust exist in the HDF5).
Inputs¶
COSEDA working file (
<dataset>.h5) with:entry/data/images(frames)entry/data/peakXPosRaw,peakYPosRaw,nPeaks(from peak finding)optional
entry/data/index(mapping raw → kept frames, written by Strip HDF5)
Dataset
.iniwith center-finding parameters (see below)
How it works¶
Batching. Split usable frames into ≥4 contiguous batches (size configurable).
Per batch, iterate:
Select frames with at least
min_peaks; keep peaks withinresolution_limit(px) from the current center.Detect Friedel pairs: peak pairs whose vectors about the center almost cancel, [ \left|(\mathbf{p}_i-\mathbf{c}) + (\mathbf{p}_j-\mathbf{c})\right| < \tau. ]
Collect deviation vectors (\boldsymbol{\delta} = (\delta_x,\delta_y)) from accepted pairs.
Robustly cluster deviations (DBSCAN) to reject outliers; fit a single-component Gaussian to the main cluster.
Update the batch center by half the fitted mean. Stop when the mean step is small or no stable cluster forms.
Drift model. Anchor each batch center to the batch’s mean original frame index. Fit a linear drift for X and Y vs. frame index. If the fit passes a quality threshold (or forced), interpolate per-frame centers; otherwise, use piecewise constants per batch. You can also skip the linear fit entirely (
centerfinding_skip_linear_fit) to always keep per-batch means.Write out. Store per-frame
center_x,center_yin HDF5. Export diagnostics (NPZ) for the GUI.
Parallelism. Batches run independently via Dask; if Dask fails, COSEDA automatically falls back to sequential processing.
Parameters (INI [Parameters])¶
Beamstop method
Key |
Description |
|---|---|
|
Friedel pairing threshold τ |
|
Discard frames with fewer peaks than this |
|
Radial cutoff; only peaks within this radius are considered |
|
Inlier fraction for DBSCAN clustering |
|
DBSCAN neighborhood radius for clustering Friedel-pair deviations. Falls back to |
|
Optional initial center guess; defaults to frame centre if absent |
|
Accept linear drift regardless of R² (ignored when skip is true) |
|
Bypass linear drift fitting entirely; use per-batch means (takes precedence over force) |
|
Cap on Friedel pairs collected per frame (default |
|
Frames per batch; auto-raised to ensure ≥4 batches |
Required keys check: the runner hard-fails if any of
centerfinding_tolerance,centerfinding_min_peaks,centerfinding_min_samples_fraction,centerfinding_resolution_limitis missing.
centerfinding_dbscan_eps only affects the clustering of Friedel-pair deviations. It does not change the Friedel-pair search radius; that is controlled by centerfinding_tolerance.
Using the GUI¶
Open the Find Centers window from the toolbar or menu.
Select the method (Beamstop or Direct) from the drop-down.
Set the required parameters. Hover over any field for a tooltip explanation.
Optionally enter initial center guesses (Center guess x/y). If left empty, the frame centre is used as the starting point. You can also click directly on the main viewer to pick coordinates.
Set the Batch Size (default 3000 frames per batch).
Click Save Current (or Save All) under Save Settings to persist settings into the
.ini.Click Find Current (one dataset) or Find All (all workspace datasets) under Find Centers to run.
After completion, review the preview panel: batch deviation clouds, mean batch centers, and the fitted drift lines are shown. Use the run selector dropdown to switch between past runs.
A Stop button is available during processing to cancel after the currently submitted Dask batches complete.
After this stage completes, proceed to the Refine Centers window (documented in the next chapter).
CLI¶
from coseda.centerfinding.findcenters_beamstop import quartering_batch
ini = "/path/to/dataset.ini"
# Beamstop stage (batched; uses Dask if configured)
quartering_batch(input_path=ini, usedask=True, batch_size=1000)
# Refinement stage: see docs/howto/workflow/6_centerrefinement.md
Outputs¶
HDF5:
entry/data/center_x,center_y(px, per frame)entry/data/det_shift_x_mm,det_shift_y_mm(mm, per frame)
Diagnostics (per run; used by the GUI):
findcenters_*/*.npz(deviation clouds, batch centers, drift fit)
Refinement outputs (LOWESS NPZ, detector shifts) are described in docs/howto/workflow/6_centerrefinement.md.