Analysis › Drift · version 2
Choose a MINFLUX measurement's MBM beads again – leaving out those that wander, jump or are noisy – and correct the localizations with the drift the others agree on, in place of Imspector's.
A MINFLUX microscope keeps its sample in place with MBM (beam-line monitoring): a few beads fixed on the coverslip are measured every couple of seconds, and Imspector subtracts their mean displacement from every localization. That works while every bead sits still. A bead that comes loose, is lost and found again in another place, or is dim and noisy, moves every localization by its share of the mean – with four beads, a quarter of whatever it does. And the beads' own scatter goes into the correction undamped: in 3D a bead is measured to about 10 nm from one point to the next.
This plugin reads the beads' tracks from the file, leaves out the ones that disagree with the others, and fits one smooth curve to the rest. It then corrects the localizations from scratch with that curve, in place of Imspector's correction.
Use it on MINFLUX data from an Abberior .msr whose measurements recorded MBM beads (File > Open shows "MBM n beads" beside them). The beads are read from the file itself, so nothing else needs to be opened; a bead file opened beside the measurement (MBM beads as a file in File > Open) is corrected with it. The plugin reads the localizations of each file in the selection, whatever the layer shows, and corrects the whole of each file.
Two colours. A two-colour measurement can measure its beads in both colours (File > Open lists each bead once per colour, R0@638 and R0@560). The plugin takes every bead in every colour as a track of its own, each with its own offset, and fits one curve to them all, which it applies to both colours alike. So the beads' colour biases – tens of nanometres, and different for every bead in the file looked at – never enter the correction, and the offset between the two colours is the same after it as before: drift correction moves the sample, and leaves aligning the colours to the colour alignment.
Some files keep the beads only from before the measurement starts. There is then no track to correct with: the curve is flat after the beads' last point, and the plugin warns that the beads cover only part of the measurement.
1. The beads' tracks. Each measurement keeps, for each of its beads, a position every couple of seconds. They are on the same clock as the localizations.
2. One curve through all of them. Each bead sits at its own place, and all of them move together with the drift. So every bead's track is the same curve plus that bead's own place (its offset). The curve and the offsets are fitted together. The curve is a smooth spline with a value every knot spacing seconds, 8 s by default. A bead seen only part of the time counts for that part.
3. Each bead judged against the others. Each bead is compared with the curve the other beads give. Leaving it out matters when there are few: a bead inside the fit pulls the curve towards itself and hides part of its own error. Three numbers describe how a bead deviates:
A bead is left out when one of these is well above the other beads'. Then the curve is fitted again without it, and the beads are judged again, until nothing changes.

Five beads (thin lines) on the curve they agree on (black); bead R2 (red, dashed) jumps by 25 nm at 120 s and is left out. Right: each bead's deviation from the curve – the jump is plain, the others scatter by their precision.
4. The correction, from scratch. Every localization gets Imspector's uncorrected position (x_nc_nm) minus the new curve at its time. The beads' tracks are uncorrected, so the curve already holds everything Imspector corrected: it replaces Imspector's correction rather than adding to it. Running the plugin again gives the same table.

The drift as Imspector corrected it (orange: the mean of all five beads) and as this plugin does (black), against the simulated drift (grey, wide), in x, each about its mean. Imspector's carries a fifth of the jump from 120 s on, and the beads' scatter; the curve through the four good beads is 0.4 nm rms from the simulated drift.
5. Your own choice. Select beads... under the settings opens the bead selector: the beads in a table with their numbers, and their tracks. A bead can be included or excluded there by hand, whatever the rule says; the choice is written into by hand, so a chain or a batch makes it again.
Point i of bead b, at time t, is modelled as
with o_b the bead's offset and d a cubic B-spline with a coefficient every knot spacing. All offsets and coefficients are one linear least-squares problem, as in the fiducial correction, with the same small penalty on the coefficients' second differences (10^-3 of the mean data weight per coefficient). A constant can move from every offset into the curve; the curve is fixed at zero at the measurement's first bead point, which is where Imspector's own correction is zero too, so the corrected positions stay where Imspector put them up to the difference of the two curves.
A bead's numbers come from its residual about the fit of the other used beads, with its own offset fitted over its points:
For each of noise, wander and jump, a bead is out when its value exceeds the median of the used beads by more than robust sigmas times their robust standard deviation (1.4826 MAD) and by more than margin. The margin is there because a few beads that agree have a tiny spread: without it, a bead 0.3 nm noisier than the other three would count as bad. Rejecting and refitting repeat until the set of beads no longer changes, at most 10 times; if fewer than min beads would be left, the least deviant come back. A choice by hand is never overruled.
Each measurement is fitted on its own, since Imspector finds its beads anew for each and reuses the names. The curves of a merged file's measurements are laid end to end; each covers its measurement's localizations as well as its beads, held flat beyond the beads. The curve is sampled every eighth of the knot spacing (at most every 0.5 s) and interpolated linearly at each localization's time_s.
On a real 3D measurement with four beads, all of Imspector's beads with no rejection give a curve 0.7 nm (x, y) and 0.08 nm (z) rms from Imspector's correction with a knot every 8 s, against 2.6 nm with a knot every 2 s, which follows every point of the beads' scatter.
| setting | default | what it does |
|---|---|---|
knot spacingknot_s | 8 s | The drift is a spline with a coefficient this often. 8 s follows changes of drift over tens of seconds and averages the beads' scatter over about four points each. Shorter follows faster drift and more of the scatter; below the beads' period (2 s) the curve has nothing to fix it between points. 0.5 to 1000 s |
start fromstart | Imspector's beads | The beads the automatic choice may use. Imspector's beads begins from the beads Imspector used, which is what its correction was made from; all beads lets the rule consider the ones Imspector set aside as well. Choices: Imspector's beads; all beads |
rejection – MadRule's numbers as a part of a plugin's settings. | ||
robust sigmasrejection.k | 3 | A bead is out where its noise, wander or jump is this many robust standard deviations above the others'. Larger keeps more beads. With a handful of beads the spread is uncertain, and margin usually decides. |
marginrejection.margin_nm | 2 nm | And above the others' median by at least this. A bead is never rejected for being less than this worse than the others' median. Set it from the precision of the beads: about the beads' noise, 2 nm by default. |
min beadsrejection.min_beads | 2 | Never fewer beads than this. At least two beads are needed to tell which one moved. 1 to 100 |
by handbeads | – | Beads in or out whatever the rule says, as 'R0 out, R3 in'; Select beads... writes it. Written by the bead selector; it can be typed too. With several measurements in the selection a bead's name starts with its measurement's label up to the first underscore ( |
correct zuse_z | auto | Auto: if the measurement is 3D. On auto, z is corrected for a 3D measurement. Off leaves z as Imspector corrected it. |
reference (more)reference | as estimated | As estimated: zero at each measurement's first bead point, as Imspector's. as estimated keeps each measurement's curve at zero at its first bead point, as Imspector's; first frame and last frame set it to zero at the first or the last time of the measurement. Choices: as estimated; first frame; last frame |
The corrected table, as one undo step; x_nc_nm and the other uncorrected attributes stay as they were, so the plugin can be run again with other beads. The text says how many beads there were, how many were used, how many the rule left out and how many were chosen by hand, then the range of the drift. The figures are the drift curve and, per measurement, the beads on it and each bead's deviation. A good result has every used bead scattering evenly about zero on the right; a used bead whose deviation has a step or a slope is one to exclude by hand.
With the bead file open beside its measurement, its beads are also named in the table (bead_id) and kept as a region table ("per bead_id: MBM drift correction"): per bead its name, noise_nm, wander_nm, jump_nm, coverage, n, whether it was used and its state as the bead list shows it, and its offset per axis. The summaries and Math parser read them there. The beads are still chosen here and in the bead selector, not by the region filter: a bead is judged against the curve of the others, which changes with the choice.