Analysis › After fit · version 1
z and its error from the widths of an elliptical Gaussian fit, by a calibration of the widths in z.
A cylindrical lens in the detection path gives a molecule's image astigmatism: wide in x when the molecule is above the focus, wide in y when it is below, and round in between. How elongated the spot is says how high the molecule is. Reading that height from the two widths of an elliptical Gaussian is the original way of 3D localization microscopy (Huang et al. 2008, doi:10.1126/science.1153529), and it is what this plugin does: it writes z_nm and its uncertainty z_err_nm onto every localization.
It needs the widths: fit with Gaussian 2D and elliptical ticked, which writes sigma_x_nm and sigma_y_nm and their errors. And it needs to know how the widths change with z, a calibration: measured on beads in the PSF calibration window with the method elliptical Gaussian, or typed. For simulated frames the simulator's own curves can be typed (the defaults are its defaults), and Fit this in Simulate types them in.
Gaussian 2D runs it by itself once the fit is done: with elliptical ticked, its *after the fit* offers astigmatic z, with these settings under z calibration. It runs there before any drift correction, so that the drift is corrected in z as well.
Use it for a quick 3D view of astigmatic data, or when no spline calibration is at hand. A spline fit (Spline 3D) uses the measured PSF itself, every pixel of it, and is more precise: an elliptical Gaussian is not quite the shape of a defocused spot, and two widths say less than the whole image.
1. The calibration. Each width follows the curve of a defocused Gaussian beam: narrowest at its own focus and growing on either side,
where is the narrowest width,
the height at which that axis is in focus and
the focal depth, how far from focus the width has grown by
. The cylindrical lens puts the two foci apart: x in focus above the round spot, y below. A calibration from beads adds Huang's two terms for what a real objective does far from focus (In detail). Its z is 0 where the spot is round.

Simulated astigmatic frames fitted with the elliptical Gaussian: each spot's two widths (blue x, red y) at its true height, on the calibration's curves. The widths follow the curves, and the scatter about them is what limits z.
2. z from both widths. For each localization the plugin looks for the height whose two widths on the curves are closest to the two it measured, each weighted by how well the fit measured it (sigma_x_err_nm, sigma_y_err_nm). Both widths are used, not only how elongated the spot is, so a spot that is too wide in both directions – two molecules overlapping, a molecule far out of focus – is recognised: it matches no height.
3. The error. z_err_nm is small where the widths change fast with z and were measured well, and large for a dim spot, whose widths are uncertain. A spot whose widths match no height gets a correspondingly larger error, and one whose best height is the end of the calibrated range – whose true z could be anywhere beyond it – gets the whole range as its error. So a filter on z_err_nm in the Render tab removes them without a flag attribute of their own.

The z found from the widths against the true z, the isolated spots of the same simulation: on the line, with no offset and no change of scale. The bars are each one's z_err_nm.
The curves. One per axis,
with for the plain beam (typed curves have them under more). Far from focus the polynomial under the root can turn negative with
and
; it is held at
there, so the width and its slope stay finite. z = 0 is where
– a calibration from beads is moved there after its fit – and the calibration carries the range of z it is trusted over: the beads' range, or z range for typed curves.
The estimate. For widths with errors
, z minimises
within the range. The errors are the fit's CRLB (Cramér-Rao lower bound: the precision the fitter expects from the photons, the background and the PSF), which Gaussian 2D writes for the elliptical fit. Huang et al. minimised a distance between the square roots of the widths instead, an unweighted stand-in for these weights.
The minimum is found in two steps, vectorised over the whole table. The start is a lookup of , the quantity SMAP looked z up by: tabulated on 2001 points of the range, it is one-to-one with z on a stretch around the round spot (for the plain curves with equal depths, everywhere – it is linear in z), and one interpolation gives every localization a start. The few whose value lies beyond that stretch start from a grid search on 201 points. Six Gauss-Newton steps then refine each start, no step longer than a tenth of the range. A million localizations take about 0.6 s; a grid search for all of them took 3.5 s.
The error. From the CRLB through the curves' slopes,
With two widths and one unknown, at the minimum follows a chi-squared distribution with one degree of freedom when the curves describe the spot;
is multiplied by
where that exceeds 1 (Birge's ratio). On fitted simulated frames this leaves
z_err_nm about a fifth larger than the scatter of z about the truth: a little conservative, and much larger for a spot whose widths disagree. A z that ends on an end of the range gets the range's width as its error, as does a row without widths; their z is the end, or NaN. All errors are capped at the range's width.
Without width errors – a table from a fitter that did not write them – every width gets one error, estimated from the residuals at the minimum: the median of with one degree of freedom is 0.455, so
. The result line says so, with the value.
Which table. The localizations, whatever the layer shows: z is computed for each from its own widths, and a grouped layer's blinks then take the mean z and the combined error, as any fitted z. Every row is computed, not only the filtered ones.
| setting | default | what it does |
|---|---|---|
calibrationcalibration | from a file | A file from the PSF calibration window (elliptical Gaussian), or the curves typed. from a file for real data, made from beads in the PSF calibration window (its Use in Astigmatic z puts the file into Gaussian 2D's after the fit, with elliptical and astigmatic z ticked). typed for simulated frames, or curves taken from elsewhere. Choices: from a file; typed |
filepath | – | An astigmatic z calibration (.h5). A file the PSF calibration window's elliptical Gaussian method saved, |
| curves – One curve per axis, s(z) = s0 sqrt(1 + u^2 + A u^3 + B u^4), u = (z - focus) / depth. The defaults are the simulator's: widths of 130 nm, x in focus at +300 nm and y at −300 nm, focal depths of 400 nm. | ||
width xtyped.sigma_x_nm | 130 nm | s0: the narrowest the spot gets in x. at least 1 nm |
focus xtyped.focus_x_nm | 300 nm | The z where x is narrowest; z = 0 is the round spot. |
depth xtyped.depth_x_nm | 400 nm | How far from its focus the x width has grown by sqrt(2). at least 1 nm |
width ytyped.sigma_y_nm | 130 nm | s0: the narrowest the spot gets in y. at least 1 nm |
focus ytyped.focus_y_nm | -300 nm | The z where y is narrowest. |
depth ytyped.depth_y_nm | 400 nm | How far from its focus the y width has grown by sqrt(2). at least 1 nm |
A x (more)typed.a_x | 0 | Huang's cubic term in x. |
B x (more)typed.b_x | 0 | Huang's quartic term in x. |
A y (more)typed.a_y | 0 | Huang's cubic term in y. |
B y (more)typed.b_y | 0 | Huang's quartic term in y. |
z rangetyped.z_range_nm | 800 nm | +- this: where the curves are trusted. Keep it to the heights the curves describe. Too narrow, and molecules beyond it end on its edge with a large error; too wide, and far out of focus the two widths grow alike and say little about z. at least 10 nm |
z scalez_scale | 1 | True z per apparent z: about 0.7-0.8 for an oil objective imaging in water, 1 for none. Beads on the coverslip measure how the widths change as the objective moves. For a molecule in water above the coverslip, seen through an oil objective, the index mismatch (refractive-index mismatch: oil and water bend light differently) moves the focus less than the objective moves, so its apparent z is compressed; this factor stretches it back. Typical values are 0.7–0.8 for oil into water; 1 for simulated data or an index-matched sample. Both |
z_nm and z_err_nm on every localization, replacing any the table had. The result line gives the median error, how many localizations ended on an edge of the range (or had no widths) and how many have widths that match no height (, which one in 370 good spots reaches by chance).
The figure has two panels: the widths of the localizations at the z found, over the calibration's curves – a good fit has them along the curves, with the spots that match no height away from both – and a histogram of z, the localizations with an error under a tenth of the range in grey, the rest in orange. A pile of orange at the ends of the range means molecules beyond the calibration: a calibration from a longer stack, or a narrower filter on z_err_nm, is the answer.