Analysis › After fit · version 1
z from a 4Pi fit's interference phase: the cavity's phase followed in time, and each phase put on the fringe its envelope z makes most probable.
In a 4Pi microscope two objectives, one above and one below the sample, collect the light of each molecule. The two beams interfere, and how bright the molecule is in each of the four camera images depends on the interference phase. The phase changes by a full turn every time the molecule moves by one fringe period in z, about 260 nm. A 4Pi fit measures it to a few hundredths of a radian, which is z to 1-3 nm. But it gives z only within the fringe: a phase cannot tell one fringe from the next.
The fit also measures z from the shape of the spot, the envelope: how wide or how elongated the spot is. With the astigmatism of these microscopes this envelope z is unambiguous, but only good to tens of nm. This plugin puts the two together. For every localization it takes the z that the phase allows on the fringe nearest the envelope's z. It writes that as z_nm, with the phase's precision as z_err_nm. The method is the one of Huang et al. 2016 (doi:10.1016/j.cell.2016.06.016), on the IAB model of the fit (Li et al. 2020, doi:10.1364/OL.397754).
Two things make it more than a rounding:
fringe_probability. A wrong fringe puts the molecule a whole period, about 260 nm, above or below where it is: a ghost. Filtering on the probability removes the likely ghosts.It needs a table from the 4Pi fit, with phase_rad, phase_err_rad and the envelope's z_env_nm and z_env_err_nm. It also needs the phase's slope in z, which comes from the 4Pi model.
1. The cavity's phase. A molecule at height z has the phase . Here
is
over the fringe period, with the sign of the model, and
is the cavity's phase in that frame. The envelope's z gives a rough
, so
is a rough
for each localization. Averaged over the many molecules of a time window, the roughness averages out, and the cavity's phase is known to a few hundredths of a radian. Between windows it is interpolated.

The cavity's phase measured in windows of 500 frames (blue), on a simulation where it drifted steadily with a random walk on top (grey). Each window's estimate comes from about 500 molecules.
2. The fringe. With the cavity's phase taken off, each localization's phase allows a ladder of heights, one per fringe, a period apart. The plugin takes the one nearest the envelope's z. How near, compared with the envelope's error, says how probable that fringe is against its neighbours.

The phase with the cavity's phase taken off, against the envelope's z, for the same simulation. The molecules lie on stripes: one turn of phase per fringe period, with the slope of the model (red). The envelope's z decides which stripe a molecule is on.
3. z. The height on that fringe is z_nm. Its error, z_err_nm, is the phase's error over : a few nm, where the envelope alone gave tens.

z from the phase against the true z (left): on the line, apart from the few on a wrong fringe, whole periods off. The error of each against the truth (right), against the envelope's alone (grey): the phase's z is several times sharper.
The cavity's phase. In each window of time window frames,
with and
the fit's errors of the phase and the envelope's z. This is the maximum-likelihood mean of angles spread about one direction (a von Mises spread). A localization whose envelope z is unsure by more than a fringe is weighted down to almost nothing. The error of each window's phase is
. Here
is the length of the weighted mean of the unit vectors, and
is the effective count.
Windows with fewer than 20 localizations are skipped. smoothing above 1 averages the sums of that many neighbouring windows; the sums are averaged, not the angles, so nothing jumps at . The window phases are unwrapped along time. They are interpolated linearly between window centres, and continued with the end windows' slope before the first and after the last. Held constant there instead, a drift of 1.5 rad per window left 0.18 rad of error in the first and last half windows. Each file of the table is done on its own, since each has its own cavity.
The fringe. The candidates are . The probability of each is proportional to
, normalised over the two fringes on either side of the nearest. Here
is the envelope's error. The fit's error is the CRLB, the least the envelope z can scatter. A model that does not fit the data perfectly scatters more, and every probability would then be too confident. So the scatter of
about the chosen z, in units of its error, is measured first. 1.4826 times the median absolute deviation is used, which the few wrong fringes do not move. Where that is above one, the errors are scaled up by it. The result line reports the factor. On the simulation above, 1.3 % of the localizations were on a wrong fringe, and the probabilities predicted 1.1 %.
The error. z_err_nm is . It does not include the error of the cavity's phase, 0.04 rad on the simulation, which is common to a whole window. On the simulation the scatter of z on the right fringe was 3.8 nm, where the phase alone predicted 2.9 nm.
Refining the period. The fringe period of the model comes from beads moved by the stage. A dye a little redder than the beads, or a sample whose refractive index differs from the immersion's, has another period. refine period looks for the slope , within 10 % of the model's, at which the phases of each window line up best. It scores
, with each term divided by
. The envelope's own noise shrinks every term by that factor, more for a steeper slope. Left alone, it biased the answer low, to about 0.99 of the true slope on simulations; with the correction the answer was within 0.3 %. Only localizations with
take part. The answer is only as good as the envelope's z scale, since that is what the phases are compared with. The z it gives is
, so a z that is right needs a right envelope.
Which table. The localizations, whatever the layer shows. The plugin reads z_env_nm and its error. On a table that has not been through it, it reads z_nm and z_err_nm, which the 4Pi fit writes as the envelope's. The envelope's values are kept as z_env_nm, so a second run with other settings starts from the fit again. The cavity's phase is written per localization as cavity_phase_rad.
| setting | default | what it does |
|---|---|---|
calibrationslope | as fitted | The phase's slope in z: kept with the table by the 4Pi fit, or read from a 4Pi model file. as fitted reads the slope the 4Pi fit kept with the table. Use from a model file for a table from elsewhere, naming the 4Pi model it was fitted with. Choices: as fitted; from a model file |
modelpath | – | A 4Pi model (.h5): this program's or uiPSF v1's. A 4Pi model of this program's, or a uiPSF v1 |
time windowwindow_frames | 1000 frames | The cavity's phase is measured over this many frames. Each window needs a few hundred localizations with a usable envelope z: 250 give the cavity's phase to about 0.05 rad. It also needs to be short enough that the cavity drifts by much less than a radian within it. At 0.04 rad/s and 40 frames per second, 1000 frames are a radian. at least 10 frames |
smoothingsmoothing | 1 windows | Average each window with its neighbours, this many in all. Use 3-5 when the windows are short and sparse. It averages the drift over that many windows, so a fast change is followed later. at least 1 windows |
refine periodrefine_period | off | Find the fringe period that the data agree with best. Leave it off when the model's beads were taken with the dye's filter in a sample of the immersion's index. Turn it on to check that the period fits the data: the result line gives both periods. |
z scale (more)z_scale | 1 | True z per apparent z: 1 when sample and immersion index match. With an oil objective imaging into water, the stage's z and the sample's differ by about 0.7-0.8. The silicone objectives and index-matched buffer of the Ries-lab 4Pi need 1. at least 0.01 |
z_nm, z_err_nm: z from the phase, on the most probable fringe.fringe_probability: the probability that the fringe is the right one. Filter it in the Render tab, at 0.9 or 0.99, to remove likely ghosts.z_env_nm, z_env_err_nm: the envelope's z, as the fit gave it.cavity_phase_rad: the cavity's phase in the localization's frame.The figure on the left is the stripes of the second figure above. Clean, separate stripes mean a good result. Stripes smeared sideways mean an envelope z too poor to choose between fringes. Stripes that bend away from the red line mean a wrong period: try refine period. On the right is the cavity's phase in each window. It should be smooth. A window that jumps away from its neighbours had too few localizations.
The result line gives the expected fraction of wrong fringes, the mean of 1 - fringe_probability. It also gives how much more the envelope's z scattered than its error said. A factor well above 1.5 means the model does not describe the data well.