Analysis › Drift · version 5
Estimate drift from the selected localizations with COMET and subtract it from all of them.
Over a long acquisition the sample drifts by tens to hundreds of nanometres, and every localization is off by however far it had moved in its frame (the RCC page says more about where drift comes from and what it does to the image). COMET (Reinkensmeier et al. 2026) measures that drift from the localizations themselves – no beads, no fiducial markers – and subtracts it.
It does not make images. It asks a simpler question of the localizations directly: if the drift were known and taken out, a molecule seen early and the same structure seen late would sit on top of each other. So COMET looks for the drift curve that makes localizations from different times overlap as much as possible, and moves every localization by that curve. A precise localization counts for more in that overlap than an imprecise one, as in DME (Cnossen et al. 2021), so out-of-focus and dim localizations pull little on the result.
Every run also says how far to trust the curve, with a split-half error bar: it estimates the drift again from each half of the field and draws both halves beside the curve. Where they differ is noise. When the curve is no larger than that noise the text says so: there is then no drift to correct, and correcting it would only add noise.
Use it on fixed samples: anything that moves by itself is taken for drift. It needs a few thousand localizations in the selection at the least (it warns below 5000), and does better with many more. The drift is estimated from the selection – the localizations that pass the layer's filter (the lowest and highest values of attributes such as precision, set in the Render tab), inside the drawn ROI (region of interest) if there is one – and subtracted from every localization of the table, so a clean filter (bright, well-fitted localizations) helps the estimate and costs the corrected table nothing.
A sample that changes shape during imaging – it expands, or creeps differently in different places – or optics whose magnification drifts with temperature or focus, cannot be corrected by one shift per frame: a correction that is right in the middle of the field is wrong at its edges. For these, transformation fits a change of scale, a rotation, an affine transformation of x and y (with a scale of z of its own if wanted) or a full 3D one over time alongside the drift. The default is the shift alone.
In the comparisons made while it was developed, COMET was slightly the more precise of the two drift plugins, but it can take minutes where RCC takes seconds, and on a large dataset much longer. It says what a run will cost before it starts. The two share no code and almost no assumptions, so running both is a useful second opinion.
1. Blinks become molecules. A fluorophore that is on for five frames gives five localizations of the same molecule. They are first merged into one, at their precision-weighted mean position (merge blinks): merge blinks, also called grouping or linking, combines the localizations in consecutive frames that come from one blinking event into one localization. This removes the densest, shortest-range pairs of localizations, which makes the estimate much faster, and stops one bright molecule from counting as five independent measurements.
2. Neighbours. Every pair of localizations closer than max drift is found once, at the start. Only these pairs are ever compared: two localizations further apart than the largest drift cannot be the same structure seen at two times.
3. Overlap. Each localization is treated as a small Gaussian blob of width . For a trial drift curve, every localization is moved back by the drift of its own frame, and the overlap of each pair of blobs is added up. The overlap is largest when the drift curve is right, because then localizations of the same structure land on top of each other whatever time they were recorded at.
With precision weights (on by default) each blob is also as wide as its localization is uncertain, in each axis on its own: its localization precision is added to , and a blob keeps the same total amount however wide it is. Two precise localizations of a molecule then overlap strongly, and a dim or out-of-focus one – wide, and in z often three times wider than in x and y – spreads its little overlap thinly and pulls little on the curve. It is what used to need a hand-set filter on z.

Out-of-focus fits are often held at the edge of the z range the fit covers, whatever the drift: here 40% of the simulation's localizations were moved to z = ±400 nm and given the poor precision such fits have (30 nm laterally, 200 nm in z). Drawn is how far the z drift found with them lies from the z drift found without them. Counted like any other (COMET as published, orange) they hold the axial drift back by up to a few nm where it is largest; weighted by their precision (blue) they hardly count.
4. Coarse to fine. With small blobs the overlap has many small peaks, and an optimiser started far from the answer would stop at the nearest one. So the search starts with wide blobs, a third of max drift, where the overlap has one broad maximum near the answer, and narrows them by a factor 1.5 at a time down to target sigma, each step starting from the last one's answer.

The overlap between the first and the last 1000 frames of a simulated acquisition, as the last ones are shifted in x (the other axes held at their true values). At every width the maximum sits at or near the true drift between the two (dashed); wide blobs give a broad hill that is easy to climb from far away, narrow ones a sharp peak that pins the answer down.
5. A smooth curve in time. By default (fit spline) the drift is a smooth curve with one adjustable point every knot spacing frames (2000), and the overlap is maximised over those points directly. Every localization is moved by the drift of its own frame; there are no time windows. Drift is slow creep, so a few tens of numbers describe an acquisition of tens of thousands of frames, and each is constrained by all the localizations near it in time.
With fit spline off, the method is COMET as published: the acquisition is cut into time windows (window size, 500 frames by default), one drift is fitted per window, and a curve through the windows' values gives the drift of every frame. This follows faster changes and can check each window (quality control), at the price of a noisier curve.

The drift estimated from the simulation, against the drift that was put in (grey, with the frame-to-frame jitter of the simulation). The spline at its default 2000-frame knots (blue) follows the slow course of the drift and smooths over wiggles shorter than its knot spacing; the time-window fit (orange, dashed) follows more of them and is noisier. Only differences between frames are measured, so the curves are compared after removing their mean.
6. Correcting. The drift of each frame is subtracted from x_nm, y_nm and z_nm (or the pixel attributes) of every localization in that frame, whether or not it was selected.
7. The error bar. With error bar on (the default), the field is cut in two at its middle, and the drift is estimated again from each half on its own. The two halves hold different molecules, so whatever they disagree on is chance: the noise of the curve. Both are drawn dashed beside the curve, and the text gives the noise in nm. Where the curve moves no more than about its noise, there is no drift to speak of.

Left: the simulation's drift as estimated (solid), with the estimates from each half of the field (dashed); they agree to about a nanometre, which is the noise the text reports. Right: the same on a simulation with no drift at all. The curve still wanders by a few nm – that is its noise, as the halves show – and the text says that there is no drift above the noise.
8. A sample that changes size. With a transformation, each frame also gets a small linear transformation about the middle of the data – a change of scale, a rotation, or the full affine one – and its parameters are smooth curves in time too, with the drift's knots or, with transformation knots, their own. Every localization is moved by the transformation and the drift of its own frame, and the overlap is maximised over both at once. The overlap of a pair is measured in units of the two frames' own scale: otherwise shrinking everything towards the middle would make every pair overlap more, and the fit would collapse the image.

A simulated sample that grows steadily by 1% (10 000 ppm) over the acquisition, about the middle of its 9 µm field: its edges move outwards by 45 nm while it also drifts. The scale change COMET finds with transformation "xy scale" (blue) follows the one put in (grey), within a few hundred ppm – a nanometre or two at the edge of the field – and least well at the two ends, where the spline has data on one side only. Like the drift, only changes are measured, so both are drawn about their mean.
Before it starts, the plugin estimates in a fraction of a second how long the run will take and how much memory it needs. Both follow from the number of neighbour pairs, which grows with the square of the number of localizations and steeply with max drift. If the answer is more than five minutes, or more than half the computer's memory, it asks first, and offers an alternative: RCC over a few time windows to take out the bulk of the drift in seconds, then COMET within 50 nm of what is left.
Which table. The localizations, whatever the layer shows. The estimate is made from those the layer's filter and the ROI select – the bounds applied to each localization, also on a layer that merges blinks – and the correction is applied to every localization of the file, selected or not.
Several files. Files opened together keep their own frame numbers, so one curve over two of them would average frame 100 of one with frame 100 of the other. Each file the selection holds gets a drift curve of its own, estimated from its localizations and subtracted from its localizations only. A file the selection does not hold (the layer shows only the others) is left as it was. The result then draws a curve per file, under its name. To correct pieces of one acquisition with one curve, make them one file first with Combine files.
The blinks the estimate merges for itself (merge blinks) are merged with the session's merge settings – the distance and dark frames of the Render tab's merge settings... – unless within and dark frames are set here; a session that merges by precision lends its largest distance, at most. Without a session (a script) they are 50 nm and 1 frame, the session's own defaults. The merged blinks are thrown away afterwards.
The cost. With the position of localization
(x, y and z, with z zero for a 2D table),
its frame,
the drift and
axis
of the corrected separation
, the overlap is
summed over the pairs with in the uncorrected positions,
the max drift. The blob widths are
and
,
the z width (1 by default), and
is localization
's precision in axis
:
xy_err_nm for x and y, z_err_nm for z. Each term is the overlap of two Gaussians, whose separation has the variance in each axis, as a density: it integrates to the same whatever the precisions, so a precise pair is tall and narrow and an imprecise one low and wide. With precision weights off, the
are zero; with
as well this is COMET's
. The weights take the precisions of what the estimate runs on – the merged blinks', with merge blinks – with z's zero where z is not corrected or the table has no
z_err_nm, and a missing value replaced by the median. A table without xy_err_nm is run unweighted, and the run says so. The weights are for the spline fit of the shift alone: the time-window fit and a transformation run unweighted. This is DME's weighting, a Gaussian per pair from the two precisions; DME's cost differs otherwise – the logarithm of a sum over each localization's neighbours rather than one sum over pairs. The pair list is built once with a KD-tree and not updated as the drift changes, so must be at least as large as the drift between any two times: a pair that starts further apart is never seen.
does not change when the same constant is added to the drift of every frame, so only differences are determined.
and its gradient are computed by a compiled, multithreaded kernel and minimised with L-BFGS-B, stopping when the relative change of the cost falls below ftol (
; the gradient tolerance is
), with every parameter bounded to
. With approximate kernel on, pairs whose exponent
is above 9 are skipped – further apart than
, for one width and no precisions: each contributes less than
of a coincident pair, and once
is small they are most of the pairs.
The spline. With frames and knot spacing
, the drift in each axis is a clamped cubic B-spline
with its knots evenly spaced over frames to
. The optimiser's variables are the
coefficients
; the kernel returns the gradient with respect to the drift of every frame, and the chain rule to the coefficients is one sparse matrix product. A B-spline cannot overshoot its coefficients, so the curve does not ring between knots the way an interpolating spline through noisy estimates can. A spline penalty
adds
per axis to the cost.
The widths are (default
), then
, one full L-BFGS-B at each, ending with the one at
: with the defaults 100, 67, 44 and 30 nm. The spline fit always runs on the CPU and always uses the
cutoff.
The error bar (error bar). The selected localizations are cut at the median of x or of y, whichever they spread further along – DME's split – and the whole estimate, passes and blink merging included, is run on each half with the same settings. Each half's curve is moved to the mean of the whole curve. The noise per axis is the root mean square over frames of the difference between the two halves' curves, each made zero mean, divided by 2: each half has half the data, so its noise is times the whole's, and the difference of two such is
times that again. An axis whose curve has a root mean square about its mean below twice its noise is reported as having no drift above the noise. On simulations with no drift, that ratio had a median of 1.0 and was at most 1.7 over 144 axes; with drift it is in the tens. A transformation has no error bar: the halves have different centres. The error bar measures noise only. A bias common to both halves – drift beyond max drift, or junk that does not follow the drift – does not show in it.
Time windows (fit spline off). The windows are, by window unit: window size consecutive frames that contain localizations; or frames accumulated until a window holds at least window size localizations; or window size windows, each with about the same share of the localizations. Each window has one drift vector
, and a localization's
is that of its window. max locs / window keeps a random subset of each window. The width schedule is COMET's own: after each successful L-BFGS-B at width
, the run stops if
and the median squared change of the parameters over that step was larger than over the step before (or
nm); otherwise
is divided by 1.5. So it can end below target sigma. Before each step the window drifts are smoothed with a running mean over smoothing windows. Finally a curve through the windows' values, placed at the mean frame of each window's localizations, gives every frame: a cubic spline (cubic) or a Catmull-Rom spline, which is held at the second and second-to-last window's value beyond them.
Quality control (time windows only). After the fit, each window's overlap with its neighbours in other windows is computed with the fitted drift, , and with none,
, both per pair. A window whose lift
is at most min lift is discarded, and the curve through the remaining windows bridges it.
Two passes. Two stage runs the estimate on merged blinks, subtracts it, and then runs it again on every localization with max drift set to fine radius , starting at
and ending at
; the two drifts add. RCC first runs RCC over RCC windows windows (merging blinks as set here), subtracts it, and runs COMET on what is left; again the two add. In both, the second pass searches a small radius, which is what makes it fast. The fit in each pass is the one asked for, the spline or the time windows.
Compared with the paper. Reinkensmeier et al. 2026 present COMET as working directly on 2D or 3D localizations and following drift with a finer time resolution than image cross-correlation. The default here gives some of that time resolution up on purpose: the drift is a smooth B-spline with a coefficient every 2000 frames, not one value per time window, which was less noisy on a real dataset. fit spline off is the time-window fit of the paper's software; Differences from COMET and SMAP lists the other changes.
A transformation over time (transformation). Each frame has a matrix besides the drift, and a localization at
in frame
is corrected to
, with
the midpoint of the bounding box of the localizations the estimate used. The drift is free, so
does not change the correction, only how it is split between drift and transformation. The matrix is
over the model's generators
: for xy scale the identity on x and y; for xy scale + rotation that and the rotation generator, which together make
exactly a scaled rotation; for xy affine the four entries of x and y; for xy affine + z scale those and
, so that nothing turns about the x or y axis, which neither a sample nor a lens does; for 3D affine all nine. In the xy models z is only shifted. Each
is a clamped cubic B-spline like the drift's, over transformation knots frames (the drift's knot spacing on auto).
In the cost, the difference of a pair's corrected positions is divided, in x and y, by , the geometric mean of the two frames' scales in the plane (
the 2 x 2 block), and in z by the same mean of z's scale: 1 where z is only shifted,
in xy affine + z scale. In 3D affine, where the matrix mixes the axes, all three are divided by the mean of
. Without it the overlap grows as everything shrinks, and the optimum is the image collapsed onto its middle. With it, a transformation common to both frames of a pair cancels from the scale, and only its change between frames is measured, as only the change of the drift is. So the spline coefficients of every
are kept at zero sum, by optimising in an orthonormal basis of the zero-sum vectors. For L-BFGS-B the variables are each
times the half-width of the data along the axis its generator multiplies – how far it moves the outermost localizations, in nm – so that they and the drift's coefficients are of one size; they share the drift's bound
and the spline penalty. Along z that half-width is a few hundred nm, not the field's ten µm.
A transformation penalty adds
to the cost, with
the variables in nm,
the half-width of parameter
's axis and
the largest,
the overlap at the first evaluation of the width step,
the number of variables. It is a pull on the relative change
, the same for every parameter, towards no change: in nm an entry acting on a thin z is held
– a thousand times, for 600 nm of depth in a 20 µm field – harder than one acting across the field. The kernel returns the gradient with respect to
,
and the scale factor of every frame, and the chain rule through
and the splines is done per frame. A frame whose
is refused (its cost is infinite). The time-window fit has no transformation.
Reference first or last frame makes the identity and the drift zero there: the correction becomes
applied after the estimated one. Two passes (two stage, RCC first) compose: the second correction is applied after the first, which for shifts alone is the sum.
The cost estimate. The pairs within are counted with a KD-tree on a fixed random sample of at most 60 000 of the selected localizations and scaled by
. With merge blinks on, a stretch of frames from the middle of the acquisition is merged first, and the fraction it keeps is the fraction the whole table is expected to keep. From the pair count
, the time is
, plus 0.3 µs per localization of the table, with
cost evaluations per width in the schedule above, and twice that with the error bar; the memory is 24 bytes per pair. The constants were measured on one computer, so the answer is an order of magnitude, and it is only used to decide whether to ask.
The ones shown without more are the ones worth looking at. Several settings under more apply only to the time-window fit and are ignored while fit spline is on; their tooltips say so.
| setting | default | what it does |
|---|---|---|
window unit (more)segmentation_mode | frames | What window size counts; time-window fit only. Choices: frames; localizations; windows |
window sizesegmentation_var | 500 | Frames or localizations per time window, or the number of windows; time-window fit only. A window must hold enough localizations to show the structure – a few thousand is a good target – and the acquisition must give at least a few tens of windows. With window unit set to localizations, windows get longer as the sample bleaches. at least 1 |
max driftmax_drift_nm | 300 nm | The largest drift expected; also the radius within which localizations are paired. The setting that decides the running time. Set it to what the stage actually drifts over the whole acquisition, not a safe-looking round number: the pair count, and with it the time and memory, grows steeply with it. Too small, and the drift beyond it cannot be found at all. RCC, or a first run with blinks merged, is a quick way to find out how large the drift is. at least 1 nm |
target sigmatarget_sigma_nm | 30 nm | The finest width of the overlap Gaussian, where refinement stops. Smaller sharpens the last step, but the overlap then has more small maxima for the optimiser to stop in. The time-window fit can end below it (see In detail). at least 0.1 nm |
initial sigma (more)initial_sigma_nm | auto | The width the refinement starts from; auto: a third of max drift. It must be wide enough that the overlap has a single maximum within reach of zero drift, which is why it scales with max drift. |
smoothing (more)boxcar_width | 1 windows | Running mean over this many windows between refinement steps; 1 is none; time-window fit only. A running mean over windows also flattens real, fast drift. 1 to 1000 windows |
interpolation (more)interpolation | cubic | The curve from the window estimates to every frame; time-window fit only. Choices: cubic; catmull-rom |
max locs / window (more)max_locs_per_segment | auto | A random subset of at most this many per window; auto: all; time-window fit only. Fewer per window is roughly quadratically faster and less precise; on real data 2000 per window was ten times faster and moved the drift by 2.5 nm rms. The subset is drawn with a fixed seed per window, so a run repeats exactly. at least 1 |
ftol (more)optimizer_ftol | 1e-07 | Relative change of the cost at which the optimizer stops. COMET's own tolerance is about |
approximate kernel (more)approximate_kernel | on | Skip pairs more than 6 sigma apart; the spline fit always does. |
ftol coarse (more)optimizer_ftol_coarse | auto | Ftol for the steps above the target sigma; auto: ftol; time-window fit only. Loosening it is measured to be a bad trade: faster, but the early steps can land in the wrong maximum, and the fine steps cannot undo that. |
quality control (more)quality_control | off | Discard time windows whose fit does not beat no correction; needs fit spline off. Useful for spotting a window that failed. The spline fit has no windows, and the run refuses the combination. |
min lift (more)min_lift | 0 | How much a window's fit must improve its overlap over no correction to be kept. 0 keeps every window whose fit is better than no correction at all. |
merge blinksgroup | on | Merge the localizations of one blink into one before estimating. Merging blinks made a real estimate 20 to 35 times faster. On real data it also gave a less noisy drift curve, because the repeated localizations of one molecule are not independent measurements. |
within (more)group_dx_nm | auto | How close localizations in consecutive frames must be to be merged; auto: the session's merge settings. |
dark frames (more)group_dt | auto | How many dark frames a blink may skip; auto: the session's merge settings. |
two stage (more)two_stage | off | A grouped pass, then an ungrouped one within fine radius. It suits a large dataset where a single pass over every localization is slow: the pass over merged blinks gets within a few nanometres, and the pass over every localization refines that over a small radius. |
fine radius (more)two_stage_radius_nm | 30 nm | The max drift of the second, ungrouped pass. Well above what the first pass leaves, which is a few nanometres. |
RCC first (more)rcc_prepass | off | Correlate rendered time windows to take out the bulk of the drift, then run COMET over a small max drift. It is the lever when the estimate would otherwise take hours: RCC's cost does not depend on how far it looks, COMET's does. |
RCC windows (more)rcc_prepass_windows | 10 | The time windows RCC correlates. at least 2 |
RCC max drift (more)rcc_prepass_max_drift_nm | auto | Auto: RCC's own default. When the plugin offers RCC first before a long run, it puts the max drift that was asked for here and uses 50 nm for COMET. |
fit splinespline | on | Fit the drift as a smooth curve in time rather than one value per time window. |
knot spacingspline_knot_frames | 2000 frames | Frames between the spline's coefficients. 2000 frames was the best choice on a real 46 000-frame dataset: finer knots were noisier without being sharper, and there was no sign of over-smoothing up to 4000. Drift that changes faster wants a smaller spacing. The noise grows by about |
spline penalty (more)spline_penalty | 0 | Extra penalty on the curve's bending; 0 is none. Rarely needed: the knot spacing already sets how smooth the curve is. On real data a large penalty flattened genuine early drift rather than removing an artefact. |
transformationtransformation | shift | What changes over time besides the position; spline fit only. Leave it at shift unless the sample or the optics change during the acquisition: a drift-corrected image that is sharp in the middle and smeared at the edges, or a local correction (in a small ROI) that works where the global one does not. Start with the fewest parameters that describe the change. On a simulated 20 µm field with 30 000 localizations, scale and rotation came back to within 150 ppm (1.5 nm at the edge of the field); the more parameters, the more an uneven density of localizations can pull on them. For a sample that changes along z too, xy affine + z scale is the first step beyond the xy models, 3D affine the most free; on a few hundred nanometres of depth, z's entries are determined to about a nanometre, which in ppm is thousands (see transformation penalty). The fit costs about twice as long as the shift alone. Choices: shift; xy scale; xy scale + rotation; xy affine; xy affine + z scale; 3D affine |
transformation knots (more)transformation_knot_frames | auto | Frames between the transformation's spline coefficients; auto: the knot spacing. A change of the optics is slow, often much slower than the drift of the stage; fewer coefficients for it are fewer parameters to determine from the same data. at least 10 frames |
transformation penalty (more)transformation_penalty | 0 | Pulls the transformation towards none where the data say little; 0 is none. For a thin sample in xy affine + z scale or 3D affine. Measured in nm, z is as well determined as x and y: the z entries wander by a few thousand ppm of a few hundred nm of depth, which is a nanometre, and the correction is as good with them as without. The penalty keeps them near 1 when that matters to the reading: on a simulated 600 nm deep, 20 µm wide sample, |
correct zuse_z | auto | Auto: if the table has z. |
precision weightsprecision_weights | on | Widen each pair's Gaussian by the two localizations' precisions, so imprecise ones count less; needs xy_err_nm, and z_err_nm for z. Leave it on. On simulations it lowered the error by 10-20% in every axis, and in z by a fifth where a fifth of the localizations were out-of-focus fits pinned in z, by half where two fifths were – within a nanometre of what a hand-set filter on z gave. Off is COMET as published, for a table whose precisions cannot be trusted. |
z width (more)sigma_z_factor | 1 x lateral | The overlap Gaussian's width in z as a multiple of its lateral width; 1 is one width for all axes. One width for x, y and z is right at the default target sigma: 30 nm is already wider than most z precisions, and making z three times wider made the axial error worse on simulations (1.1 to 1.8 nm, and 4.6 to 15 nm with pinned out-of-focus fits). It helps only with a target sigma near the lateral precision (8 nm: 1.8 to 1.2 nm), where the precision weights do as well. 0.1 to 20 x lateral |
error barsplit_half | on | Estimate again from each half of the field and show both: how far they differ is twice the curve's noise. It doubles the run. Turn it off for a large ungrouped estimate where the time matters more than knowing the noise. |
reference (more)reference | as estimated | The frame the drift is zero at; first or last frame for consecutive files. Choices: as estimated; first frame; last frame |
A good result is a smooth curve of plausible size, a few hundred nanometres at most, well above its noise, with halves that follow it, and an image that is visibly sharper after correction. A noise of a nanometre or two is typical; a curve that wanders by a few nanometres with a noise of the same size is noise, and no drift above the noise says so. A curve that sits flat at twice max drift has run into the optimiser's bound, and max drift was too small. Sharp excursions that come straight back usually mean the data at that time had too little to go on: merge blinks, filter more cleanly, or compare with RCC.
SMAP has no COMET. Its nearest relative there is the DME drift correction, which also works on the localizations rather than on images.
The estimator is COMET 1.1.0 (github.com/gpufit/Comet), vendored with its cost function and optimiser. Around it, this plugin differs from upstream COMET in these ways: