After the fit

Analysis › After fit · version 1

What a fitter runs once its last frame is in – astigmatic z, drift correction, colours, a chain – on the open localizations.

What it does

A fit is rarely the end. An astigmatic fit wants its widths turned into z, almost every acquisition wants the drift taken out, and a two-colour fit wants each localization given its colour. None of that can be done while the frames are still coming in: a drift curve is measured across the whole acquisition, and the colours are told apart by a histogram of the whole sample.

So every fitter has a section after the fit, folded at the foot of its form, whose title says which steps are on. Once the last frame is fitted, the fitter runs these steps over the whole table, and only then saves the file. The file on disk is then the finished table, not a raw fit somebody has to remember to correct.

This plugin is the same section on its own: the same settings, run on the localizations that are open. You rarely open it by itself. Inside every fitter's after the fit there is a button, Run these now, which runs it on the open localizations without fitting again. Use it when a step was not ticked during the fit, or to try other settings. It is one step of the undo and one line of the history, under the name After the fit.

How it works

The steps, in this order. Each one is a plugin of its own, with that plugin's settings, so a fit that finishes itself and a table finished by hand give the same numbers:

  1. astigmatic z – z from the widths of an elliptical Gaussian (Astigmatic z). It comes first, so that a drift correction after it can correct z too.
  2. 4Pi z – z from the interference phase of a 4Pi fit, unwrapped by its envelope z (4Pi z). Also before the drift correction, for the same reason.
  3. overlay channels – for two dyes each seen in one half of a split camera: the second half's localizations moved onto the first by a registration from beads (Overlay channels). Before the drift correction, because the drift is the same in both halves and is best measured on the overlaid table.
  4. drift correction – none, RCC or COMET.
  5. assign colours – a colour per localization from how its photons split between the two channels (Assign colours).
  6. then chain – a saved chain: plugins in order, with their settings, that run as one. It is for whatever else your lab does to every fit. A chain is made with the + of the Analysis tab and its Save chain, and is what the batch window runs over many files.

Only what applies is shown. Each step appears only where the fit can give it what it needs. Assign colours appears only in the two-colour fitters (Gaussian 2D 2C, Spline 3D 2C). Astigmatic z appears only in Gaussian 2D, and only while its elliptical is ticked. 4Pi z appears only in Spline 4Pi. Overlay channels appears only in a one-colour fitter whose channels reads two channels. A step's settings appear below it only while the step is on: tick assign colours and colour assignment appears; choose COMET and only COMET drift is shown.

What the table cannot take is passed over. When this plugin runs on the open localizations, it looks at the table rather than at a fitter. Colours need two channels' photons (photons_ch0 and photons_ch1, or MINFLUX's dcr). Astigmatic z needs sigma_x_nm and sigma_y_nm. 4Pi z needs phase_rad and phase_err_rad. The overlay needs camera_channel, which a fit on two channels writes. A step whose attributes are missing is skipped without a word, so the default assign colours does nothing to a one-colour table.

A step that fails is a line in the output. These steps run after a fit that may have taken twenty minutes. A colour histogram with one peak, or a drift estimate on too few localizations, must not cost that fit. So a step that fails says why in the output, the steps after it still run, and the table is saved.

In detail

Inside a fitter the steps run on the table as the fit made it, with every localization and no filter. The drift steps merge blinks as the Render tab's merge blinks does, for the distance and dark frames they leave on auto. Each step that changed the table goes into the file's history with the settings it used. The streamed file is written once more with the finished table when any step changed it.

From the button, the steps get the session's localizations: all of them, every file, whatever the layers show. Drift is estimated per file, as when RCC or COMET is run on its own.

A chain is read from its file each time it runs, so a chain saved a moment ago is the one that runs. It runs with the values saved in the file. A chain with a fitting step in it is refused, because it would open the movie and fit it again. The other steps still run.

Parameters

settingdefaultwhat it does
astigmatic z
astigmatic_z
offZ from the widths of the elliptical Gaussian, before any drift correction so that it can correct z (Analysis/After fit/Astigmatic z).

The calibration under z calibration is the one Astigmatic z uses: a file from the PSF calibration window, method elliptical Gaussian, or curves typed in. Saving such a calibration in that window puts it here, in Gaussian 2D, with elliptical and astigmatic z ticked.

z calibration
   calibration
   astigmatic.calibration
from a fileA file from the PSF calibration window (elliptical Gaussian), or the curves typed. Choices: from a file; typed
   file
   astigmatic.path
–An astigmatic z calibration (.h5).
curves – One curve per axis, s(z) = s0 sqrt(1 + u^2 + A u^3 + B u^4), u = (z - focus) / depth.
      width x
      astigmatic.typed.sigma_x_nm
130 nms0: the narrowest the spot gets in x. at least 1 nm
      focus x
      astigmatic.typed.focus_x_nm
300 nmThe z where x is narrowest; z = 0 is the round spot.
      depth x
      astigmatic.typed.depth_x_nm
400 nmHow far from its focus the x width has grown by sqrt(2). at least 1 nm
      width y
      astigmatic.typed.sigma_y_nm
130 nms0: the narrowest the spot gets in y. at least 1 nm
      focus y
      astigmatic.typed.focus_y_nm
-300 nmThe z where y is narrowest.
      depth y
      astigmatic.typed.depth_y_nm
400 nmHow far from its focus the y width has grown by sqrt(2). at least 1 nm
      A x (more)
      astigmatic.typed.a_x
0Huang's cubic term in x.
      B x (more)
      astigmatic.typed.b_x
0Huang's quartic term in x.
      A y (more)
      astigmatic.typed.a_y
0Huang's cubic term in y.
      B y (more)
      astigmatic.typed.b_y
0Huang's quartic term in y.
      z range
      astigmatic.typed.z_range_nm
800 nm+- this: where the curves are trusted. at least 10 nm
   z scale
   astigmatic.z_scale
1True z per apparent z: about 0.7-0.8 for an oil objective imaging in water, 1 for none. at least 0.01
4Pi z
fourpi_z
onZ from the interference phase of a 4Pi fit, unwrapped by its envelope z (Analysis/After fit/4Pi z).

On by default, and shown only after a 4Pi fit, where it is the step that gives z its precision. Its settings, under 4Pi phase, are those of 4Pi z; the fit keeps the phase's slope with the table, so as fitted needs no file.

4Pi phase
   calibration
   fourpi.slope
as fittedThe phase's slope in z: kept with the table by the 4Pi fit, or read from a 4Pi model file. Choices: as fitted; from a model file
   model
   fourpi.path
–A 4Pi model (.h5): this program's or uiPSF v1's.
   time window
   fourpi.window_frames
1000 framesThe cavity's phase is measured over this many frames. at least 10 frames
   smoothing
   fourpi.smoothing
1 windowsAverage each window with its neighbours, this many in all. at least 1 windows
   refine period
   fourpi.refine_period
offFind the fringe period that the data agree with best.
   z scale (more)
   fourpi.z_scale
1True z per apparent z: 1 when sample and immersion index match. at least 0.01
overlay channels
overlay
offMove the second half of a two-channel fit onto the first, by beads; channel is the half (Analysis/After fit/Overlay channels).

Off by default. Inside a fitter, the beads are fitted with that fitter's camera settings and in its channel arrangement, so the overlay's own channels part is not shown there. With keep the registration on, the beads are fitted and registered once and the result is used again by every fit that names the same beads, until a bead file changes.

channel overlay
   transformation from
   overlay_channels.source
transformation fileA saved registration, beads already fitted as two channels, or bead movies to fit. Choices: transformation file; fitted beads; bead movies
   file
   overlay_channels.path
–A _2ct.h5 (Calibrate transform, or this plugin's), or a dual-colour bead calibration.
   fitted beads
   overlay_channels.beads_table
–Bead localizations fitted with channels > read: two channels.
   bead movies
   overlay_channels.beads
–A folder of bead movies, or one movie's path; beads seen in both halves.
bead fit – How the bead movies are fitted: Gaussian 2D, two channels, the sample's camera.
      cutoff
      overlay_channels.bead_fit.cutoff
1.7The detection threshold, in units of the filtered frame's noise (the fitters' dynamic cutoff). at least 0.1
      at most
      overlay_channels.bead_fit.max_frames
autoFrames fitted per bead movie; auto: all. at least 1 frames
channels – Where a split chip's two channels lie: the microscope's entry, or chosen by hand.
      layout
      overlay_channels.channels.layout
the microscope'sHow the chip is split: the microscope's entry, or chosen by hand with the main channel and the split. Choices: the microscope's; right-left; right-left mirrored; up-down; up-down mirrored
      main channel
      overlay_channels.channels.main_channel
the microscope'sThe channel the other is registered onto: the microscope's (its transmitted arm), or either half, to swap them. Choices: the microscope's; left; right; upper; lower
      split position (more)
      overlay_channels.channels.split_position
autoThe first pixel of the second channel, on the chip, for a layout chosen by hand; empty: the middle of the frame. at least 1 px
registration – How a registration between two channels is measured: the vote, the pairing and the fit.
      transformation
      overlay_channels.registration.model
projective (8 coefficients)Projective extrapolates gracefully; the polynomial describes a distorted field far better where the pairs reach, and is refused when they do not reach far enough. Choices: projective (8 coefficients); polynomial, order 3 (20)
      vote bin (more)
      overlay_channels.registration.vote_bin_px
2 pxThe bin of the histogram of pair vectors the offset is voted in. at least 0.1 px
      vote smoothing (more)
      overlay_channels.registration.vote_smooth_px
4 pxThe width of the difference-of-Gaussians filter the vote is scored with. at least 0.1 px
      coarse matching
      overlay_channels.registration.coarse_tolerance_px
20 pxFirst pass; must cover the rotation between the channels – 3 degrees over 512 px is 27 px. at least 0.1 px
      fine matching
      overlay_channels.registration.fine_tolerance_px
1 pxSecond pass over clean matches only, which is where the accuracy comes from; 0 skips it.
      adapt fine matching (more)
      overlay_channels.registration.adapt_fine_tolerance
onWiden the fine matching to what the coarse fit misses its own pairs by, when those pairs are clean.
      minimum pairs (more)
      overlay_channels.registration.min_pairs
20Fewer pairs than this and the registration refuses. at least 4
      pairs used in the fit (more)
      overlay_channels.registration.max_pairs
20000At most this many pairs, drawn at random, go into each fit. at least 4
      outlier threshold (more)
      overlay_channels.registration.reprojection_threshold_px
1 pxThe robust (RANSAC) fit's inlier radius, at least; it widens with the matching tolerance. at least 0.01 px
      dx/dy limit (more)
      overlay_channels.registration.transform_axis_limit_px
0.5 pxThe largest |dx| or |dy| a pair may keep after the first fit, at least; it widens with the matching tolerance. at least 0.01 px
   keep the registration
   overlay_channels.save
onWrite it beside the beads as <name>_2ct.h5 and use it again while the beads and these settings are unchanged.
drift correction
drift
noneEstimate the drift from the finished table and subtract it from every localization. Off by default: it is minutes of work on a dataset it cannot see beforehand.

Their pages, RCC and COMET, say which to choose. The settings under RCC drift and COMET drift are theirs. COMET's question before a long run is not asked after a fit: choosing it is the agreement. With z in the table, both correct z as well, unless their correct z says otherwise.

Choices: none; RCC; COMET
RCC drift – How finely to bin, render and search.
   time windows
   rcc.n_timepoints
20How many windows the acquisition is cut into: more follow faster drift, fewer are less noisy. at least 2
   pixel size
   rcc.pixelsize_nm
15 nmThe pixel of the images that are correlated; about the localization precision. at least 1 nm
   z bin (more)
   rcc.z_pixelsize_nm
5 nmThe bin width of the z histograms. at least 0.1 nm
   max drift
   rcc.max_drift_nm
500 nmThe largest drift between any two windows that can be found. at least 1 nm
   peak fit half-width (more)
   rcc.fit_window
3 pxThe patch the correlation peak is fitted over, for its sub-pixel position. at least 1 px
   max image size (more)
   rcc.max_pixels
2048 pxA wider field of view is folded back onto itself, to keep the correlation fast. at least 64 px
   correct z
   rcc.use_z
autoAuto: if the table has z.
   merge blinks
   rcc.group
onMerge the localizations of one blink into one before measuring.
   within (more)
   rcc.group_dx_nm
autoHow close localizations in consecutive frames must be to be one blink; auto: the session's merge settings.
   dark frames (more)
   rcc.group_dt
autoHow many dark frames a blink may skip; auto: the session's merge settings.
   tile (more)
   rcc.tile_nm
200 nmThe axial pass correlates z histograms in tiles of the field of view this size. at least 1 nm
   tile y (more)
   rcc.tile_y_nm
autoAuto: square tiles. at least 1 nm
   max axial drift (more)
   rcc.axial_max_drift_nm
200 nmHow far from zero the axial correlation peak is looked for. at least 1 nm
   skip zero shift (more)
   rcc.exclude_zero_lag
onLeave the zero-shift sample out of the axial peak search.
   error bar
   rcc.split_half
onEstimate again from each half of the field and show both: how far they differ is twice the curve's noise.
   reference (more)
   rcc.reference
as estimatedThe frame the drift is zero at; first or last frame for consecutive files. Choices: as estimated; first frame; last frame
COMET drift – COMET parameters. The defaults suit a typical SMLM movie.
   window unit (more)
   comet.segmentation_mode
framesWhat window size counts; time-window fit only. Choices: frames; localizations; windows
   window size
   comet.segmentation_var
500Frames or localizations per time window, or the number of windows; time-window fit only. at least 1
   max drift
   comet.max_drift_nm
300 nmThe largest drift expected; also the radius within which localizations are paired. at least 1 nm
   target sigma
   comet.target_sigma_nm
30 nmThe finest width of the overlap Gaussian, where refinement stops. at least 0.1 nm
   initial sigma (more)
   comet.initial_sigma_nm
autoThe width the refinement starts from; auto: a third of max drift.
   smoothing (more)
   comet.boxcar_width
1 windowsRunning mean over this many windows between refinement steps; 1 is none; time-window fit only. 1 to 1000 windows
   interpolation (more)
   comet.interpolation
cubicThe curve from the window estimates to every frame; time-window fit only. Choices: cubic; catmull-rom
   max locs / window (more)
   comet.max_locs_per_segment
autoA random subset of at most this many per window; auto: all; time-window fit only. at least 1
   ftol (more)
   comet.optimizer_ftol
1e-07Relative change of the cost at which the optimizer stops.
   approximate kernel (more)
   comet.approximate_kernel
onSkip pairs more than 6 sigma apart; the spline fit always does.
   ftol coarse (more)
   comet.optimizer_ftol_coarse
autoFtol for the steps above the target sigma; auto: ftol; time-window fit only.
   quality control (more)
   comet.quality_control
offDiscard time windows whose fit does not beat no correction; needs fit spline off.
   min lift (more)
   comet.min_lift
0How much a window's fit must improve its overlap over no correction to be kept.
   merge blinks
   comet.group
onMerge the localizations of one blink into one before estimating.
   within (more)
   comet.group_dx_nm
autoHow close localizations in consecutive frames must be to be merged; auto: the session's merge settings.
   dark frames (more)
   comet.group_dt
autoHow many dark frames a blink may skip; auto: the session's merge settings.
   two stage (more)
   comet.two_stage
offA grouped pass, then an ungrouped one within fine radius.
   fine radius (more)
   comet.two_stage_radius_nm
30 nmThe max drift of the second, ungrouped pass.
   RCC first (more)
   comet.rcc_prepass
offCorrelate rendered time windows to take out the bulk of the drift, then run COMET over a small max drift.
   RCC windows (more)
   comet.rcc_prepass_windows
10The time windows RCC correlates. at least 2
   RCC max drift (more)
   comet.rcc_prepass_max_drift_nm
autoAuto: RCC's own default.
   fit spline
   comet.spline
onFit the drift as a smooth curve in time rather than one value per time window.
   knot spacing
   comet.spline_knot_frames
2000 framesFrames between the spline's coefficients. at least 10 frames
   spline penalty (more)
   comet.spline_penalty
0Extra penalty on the curve's bending; 0 is none.
   transformation
   comet.transformation
shiftWhat changes over time besides the position; spline fit only. Choices: shift; xy scale; xy scale + rotation; xy affine; xy affine + z scale; 3D affine
   transformation knots (more)
   comet.transformation_knot_frames
autoFrames between the transformation's spline coefficients; auto: the knot spacing. at least 10 frames
   transformation penalty (more)
   comet.transformation_penalty
0Pulls the transformation towards none where the data say little; 0 is none.
   correct z
   comet.use_z
autoAuto: if the table has z.
   precision weights
   comet.precision_weights
onWiden each pair's Gaussian by the two localizations' precisions, so imprecise ones count less; needs xy_err_nm, and z_err_nm for z.
   z width (more)
   comet.sigma_z_factor
1 x lateralThe overlap Gaussian's width in z as a multiple of its lateral width; 1 is one width for all axes. 0.1 to 20 x lateral
   error bar
   comet.split_half
onEstimate again from each half of the field and show both: how far they differ is twice the curve's noise.
   reference (more)
   comet.reference
as estimatedThe frame the drift is zero at; first or last frame for consecutive files. Choices: as estimated; first frame; last frame
assign colours
assign_colors
onSplit the localizations by their photon ratio and write channel (Analysis/After fit/Assign colours).

On by default: in a two-colour fit it is seconds, and it is what the fit was for. To change the rule afterwards, change colour assignment and press Run these now.

colour assignment
   method
   colors.mode
split at the minimaA cut in r, or a posterior per localization. Choices: split at the minima; probabilistic
   colours
   colors.colors
2How many species the histogram of r holds. 1 to 6
   exclusion dr
   colors.exclusion
0.05Minima: leave this much of r on either side of a boundary unassigned.
   sigma
   colors.tolerance
3Probabilistic: a colour is given only within this many sigma of its expected split, the sigma being that localization's own photon statistics plus any extra spread. 0: assign to the nearest colour however far away.
   keep the tails
   colors.keep_tails
offProbabilistic: apply the sigma test only between the outermost colours, so a localization more extreme than the first or the last mode is kept rather than refused.
   allowed crosstalk
   colors.crosstalk
0.05Probabilistic: refuse what is too close to call as well – the largest expected fraction of wrongly assigned localizations. Narrow beside the sigma test, and what matters where two colours overlap. 1e-06 to 0.5
   extra spread
   colors.spread
0Probabilistic: a species' own width in r, added in quadrature to the shot noise, for a dye whose splitting ratio varies across the field or between molecules. 0: shot noise alone (the summary prints what the modes suggest).
   use fitted errors
   colors.use_errors
onTake the photon errors from the fit where the table has them; otherwise sqrt(photons).
   use abundances (more)
   colors.use_prior
onProbabilistic: weight each species by how much of the sample sits under its mode.
   minimum photons (more)
   colors.min_photons
0Localizations with fewer photons in total are ignored and left unassigned.
   intensity LUT (more)
   colors.cmap
viridisThe colour map of the intensity plot's 2D histogram. Choices: viridis; cividis; turbo; magma; inferno; Greys; Greys_r
   histogram bins (more)
   colors.bins
200How many bins the histogram of r has over its whole range, -1 to 1. 10 to 2000
   smoothing (more)
   colors.smoothing
2 binsThe histogram is smoothed by this much before its maxima are looked for; it also sets how far apart two modes must be.
   expected r (more)
   colors.expected
autoThe species' ratios, comma separated ("-0.65, 0.96"), measured on single-label samples or computed from the spectra. auto: the histogram's own maxima.
   channel 1 attribute (more)
   colors.channel1
autoAuto: photons_ch0, or the first pair of per-channel attributes in the table.
   channel 2 attribute (more)
   colors.channel2
autoThe attribute r counts negative; name both attributes or neither.
then chain
chain
–A saved chain run last, on the finished table; empty: none.

Leave it empty for none. Its settings are edited in the chain's own panel and saved to its file.

Output

The table with what the steps wrote: z_nm and z_err_nm from Astigmatic z or 4Pi z (with fringe_probability), the second half moved and channel written by the overlay, positions moved by the drift correction, channel from Assign colours, and whatever the chain added. The output lists one line per step: what it found, that it failed and why, or nothing for a step that was not run. Each step's figures (the drift curve, the colour histogram, the widths against z) open with the result, each named after its step.