napari plugin

The Track Analyzer dock widget loads and filters tracks, runs analyses, and displays previews alongside images in napari. Install it as described in Installation, start napari, and select Plugins > Track Analyzer. The widget has five tabs: Load data, Filtering, Trajectory analysis, Map analysis, and Comparator.

Track Analyzer's napari Load data tab showing the loading and configuration controls

The Load data tab. The path shown is an example.

Inputs

Use a CSV or TXT table containing track IDs, frame numbers, X and Y coordinates, and optionally Z coordinates and custom variables. Coordinates may be in pixels or scaled units. The plugin maps source columns to Track Analyzer’s column names. For TrackMate data, export the spots table.

An image is optional. Open it in napari before using image-based previews or backgrounds; there is no general image loader in the plugin. For exported backgrounds, the open grayscale image must have a saved source file, or the layer name must match a file in the dataset directory.

Load data and metadata

In Load data, choose one of the following:

  • Load table: select a new table, set the column separator, header-row option, and TrackMate CSV option, then click Import table. To change the parsing options, edit them and import again. Expand Inspect and link columns. Assign x, y, frame, and track; assign z and named custom variables if needed. Choose how to resolve trajectory gaps and click Apply mapping. TrackMate column assignments are proposed automatically when the TrackMate option is enabled.

  • Load existing database: select an existing data_base.p. Its processed table is loaded directly, so column mapping is not needed.

  • Load test dataset (temporary): load data_base.p and stack.tiff from ~/Desktop/TA/test_rotation, if those local files exist.

The selected table or database’s parent folder is used for metadata and outputs. File dialogs initially open in the user’s home directory, unless an open image has a source path.

Clear loaded data removes the current dataset, its filters and plugin-generated previews, but keeps image layers and comparator datasets. It does not delete files. Wait for any running trajectory or map analysis or grid computation to finish before clearing.

In Input metadata, enter or load the pixel size, frame interval, units, image dimensions, and optional Z step. Use Save info.txt to save metadata in the dataset directory; replacing an existing file requires confirmation.

Before saving a new database, optionally set preprocessing coordinates in Custom origin and axis orientation. Use Pick origin in viewer to choose an origin on an open image. These settings affect preprocessing; displayed tracks retain their source coordinates. Then click Save database to preprocess trajectories and write data_base.p. Saving over an existing database requires confirmation. Trajectory and map analyses require a processed database and saved info.txt.

Plotting configuration controls figure size, resolution, format, stack export, data-point export, and custom colors. Its Show axes and Hide background image options are shared by trajectory-on-movie, Voronoi, and scalar and vector map exports; they do not change napari preview layers. When axes are shown, padding is added around the image area for their labels, so exported images are larger than the original image. Enable Render TIFF stacks in parallel to render trajectory, Voronoi, scalar, and vector TIFF stacks using up to four worker processes. This shared option is off by default and does not affect individual-image exports. Worker startup and data transfer can make parallel rendering slower for small stacks.

Filtering

In Filtering, set the number of named subsets and choose whether to analyze them separately or together. Expand Define analysis subsets to set each subset’s color, position ranges, frame window, and track-length limits. Draw ROI sets the X/Y ranges using a rectangle drawn in the viewer. If no image is open, it uses displayed tracks or shows a 2D X/Y projection of the loaded tracks for reference.

Optionally add track-selection sets under Select tracks within each subset. Each set can select track IDs, tracks entering a position ROI within a frame window, or both, and is applied within every analysis subset. Use Draw track ROI to define a selection ROI in the viewer. Set the two frame-window endpoints to the same value to select at a single frame.

Click Apply filters to apply the selections; a successfully applied ROI drawing layer is hidden, but its coordinate ranges are retained. Display tracks shows the filtered tracks using the selected colors. Save filters writes config/filters.csv; Remove all subsets clears subset and track-selection controls.

Trajectory analysis

The trajectory tab offers Trajectories on movie, Total trajectories, Parameter plots, Mean squared displacement (MSD), and Voronoi analysis. Each foldout has an independent On/Off switch: opening or closing it does not change whether that analysis runs. Add histogram, boxplot, or scatter-plot rows for instantaneous or whole-track parameters as needed.

For an instantaneous spatial profile, open Scatter plots, choose a Line type, and click Draw profile line. Drag to draw a straight line or freehand path, or click the vertices of a polyline and double-click to finish. Set Profile full width in the dataset’s length units and add one or more line profile rows. The analysis plots each observation within half the width of the nearest point on the path against distance from its first vertex, in physical length units. The selection includes round ends and uses the XY projection across all frames and Z positions. If segments are equally close, the earliest segment in the path is used. Existing scatter, regression, binning, hue and data-point export options apply. The line type, vertices in pixel coordinates and physical width are saved in the scatter configuration. When data-point export is enabled, the line-profile_<parameter>.csv rows are ordered by distance along the line. The plot image uses the same basename and the selected image format.

Opening a trajectory foldout and enabling its independent On/Off switch

Expand a foldout to edit its settings; its switch controls whether it runs.

The track color code and colormap at the top are shared by Preview colored tracks and the trajectory exports. The group color code uses the filtering subset colors, or the track-selection set colors when those sets are present.

In Voronoi analysis, Preview Voronoi displays a 2D tessellation for the current filters and frame. The outline color is editable; enabling Show cell area adds a separate area-colored layer. The area threshold, length scale, colormap, and color limits determine the fill. Unbounded and excluded cells are not filled. The preview supports 2D images and 2D time-lapse images; it follows the current frame and is computed per subset in separate mode. Area and color settings update an existing preview automatically; run it again after changing data or filters. For 3D tracks, Voronoi and neighbor exchange analysis use only the XY coordinates and ignore Z after filtering. Select Set custom color limits to edit the minimum and maximum area colors; the fields are initialized from the current preview when available. Without a current preview, enter the limits manually.

Export neighbor exchange analysis, under Voronoi analysis, is off by default and detects topology-only T1 and T2 candidates in the XY plane. It can run even when the Voronoi analysis switch is off. Points with the same XY position in a frame cannot be tessellated, even if they differ in Z. A T1 candidate has four persistent cells: an old neighbor pair loses its edge and the other pair gains an edge, while the four cross-neighbor edges exist before and after. Set Maximum T1 duration to the maximum number of frame intervals between the last old edge and the first new edge; intermediate frames may have neither edge. A T2 candidate is a disappearing cell with exactly three neighbors that remain mutually adjacent. The cell must also be absent from the original dataset in the following window.

Persistence requires the pre- and post-event topology to last for that many consecutive frames on each side. Missing or untessellatable frames break the comparison. Events involving unbounded Voronoi cells, or cells whose vertices touch or cross the image bounds when dimensions are known, are excluded. Voronoi neighbors are inferred from the filtered XY point set, not cell boundaries: filtering out cells can change the topology, and finite tracking gaps can still produce candidates. Separate subsets are analyzed independently; overlapping subsets cannot be analyzed together. Review candidates before interpreting them as biological transitions.

Preview neighbor exchanges marks T1 and T2 candidates at the first post-event frame. Choose their marker colors separately; the defaults are magenta for T1 and cyan for T2. Color changes update the preview and also apply to exported diagrams. In a 3D time-lapse viewer, projected markers appear on every Z slice. Preview again after changing inputs or settings. Analysis saves neighbor_exchanges.csv with event frames, XY positions in pixels, and track IDs, plus its settings in config/neighbor_exchange_config.csv. When Voronoi diagram export is also enabled, the same colored markers appear on individual images and TIFF stacks at the first post-event frame, provided that frame is included by the plotting increment. Exported marker diameters are twice the diagram line width.

Click Run trajectory analysis to save results in numbered folders under <dataset>/traj_analysis/. Subsets must have unique names and contain data. The progress bar indicates work is ongoing rather than a percentage; the log shows analysis messages. A notification and a log message indicate when the analysis completes.

MSD fitting models

The MSD analysis computes the mean squared displacement at each lag time for each trajectory. Choose Only plot MSD to skip model fitting, or select:

  • Random walk: fits the diffusion coefficient \(D\) to \(\mathrm{MSD}(\tau) = 2dD\tau\).

  • Biased random walk: fits \(D\) to \(\mathrm{MSD}(\tau) = 2dD\tau + \bar v^2\tau^2\), using the measured mean speed \(\bar v\) rather than fitting it.

  • Persistent random walk: fits the persistence time \(P\) to \(\mathrm{MSD}(\tau) = \bar v^2 P[\tau - P(1-e^{-\tau/P})]\), again using measured mean speed.

Here \(d\) is the selected MSD dimension and \(\tau\) is lag time in the dataset’s time units. Individual fits use each track’s mean speed; fits of the averaged MSD use the mean speed of the analyzed data. Maximum fit lag time includes lag times up to that value. The all-MSD output also reports a log-log exponent calculated over the available mean MSD points, independently of that fit limit. Use enough trajectory observations and inspect fit quality; the models describe motion rather than identify its biological cause.

Map analysis

Maps average quantities on a regular 2D grid. In Define grid, select the number of X cells and grid origin, then click Preview grid. Changing these settings updates a visible grid preview. The grid uses the open image dimensions, or filtered track extents if no image is open.

Set temporal averaging, relative arrow size, frame increment, and export options under Map parameters. In Fields to plot, add scalar fields, vector fields, or vector means and remove any unwanted rows. Vector fields can have a scalar background.

Compute grid values calculates all available fields and displays finite ranges for the selected fields across frames and subsets. Use the two-handle slider to select color limits within the computed range. For a constant range the slider is disabled; select Enter custom limits to type limits instead, including values outside the computed range. Custom limits may also be entered before computing grid values. Changing the data, filters, grid, image geometry, or temporal average invalidates the computed values. Run the computation again after such changes. A subsequent map analysis reuses current computed values; if none are available, analysis computes them as usual.

Show selected maps in viewer creates scalar image layers and vector arrow layers. Missing scalar values are transparent. Scalar colors and limits are set in the widget; click the display button again after changing them. Relative arrow size updates existing preview arrows immediately. Run map analysis saves plots and optional field exports under <dataset>/map_analysis/. A notification and a log message indicate when the analysis completes.

Comparator

The comparator pools or compares previously saved trajectory analyses, even when they come from different dataset roots. All selected datasets must use the same length and time units: unit conversion is not supported.

  1. Expand Datasets and choose a dataset root. Select an individual folder under Trajectory analysis and click Add selected analysis. Repeat for other analyses or roots. Use Refresh analyses after generating new analyses, or browse directly to an analysis folder.

  2. Give the selected datasets unique names and choose compare (separate colors) or pool (one group).

  3. Add instantaneous or whole-trajectory histograms, boxplots, or scatter plots. Parameter choices are numerical fields shared by all datasets and supported by the plotting engine.

  4. Optionally turn on the Mean squared displacement (MSD) foldout switch; it is off by default. MSD comparison requires a nonempty all_MSD.csv for each selected analysis. Parameter plots use all_data.csv and mean_track_data.csv.

  5. Click Run comparison. Results are saved under <first dataset>/pooled_datasets/<mode>_<dataset names>/. If the output folder exists, choose Overwrite, Create new folder, or Cancel. Overwrite replaces matching files but retains unrelated files in the folder.

The comparator runs in a separate process and displays progress and output messages in the widget. A notification and a log message indicate when the comparison completes.

Synthetic datasets

Open Plugins > Track Analyzer > Synthetic Dataset Generator as a separate dock widget. Set the track and frame counts, dimensionality, frame interval, pixel size, space bounds, and initial-position bounds. Initial positions can be random or arranged on an approximate grid in 2D or 3D; grid spacing can change the actual track count. A 3D grid contains at most the requested number of tracks; if it has only one position along an axis, that position is at the center of the initial range. Periodic boundaries wrap positions into the configured space bounds.

In Space and initial bounds, set the width and height (and depth in 3D). Use the two handles or the numeric minimum and maximum inputs to set the initial range on each axis. The preview shows the initial XY rectangle inside the space, with X increasing right and Y increasing down as in an image. Numeric bounds are listed below; in 3D the Z bounds are listed too. Space minima default to zero and can be changed under Advanced: space origin. Changing an origin shifts the corresponding initial range by the same amount. Reducing a space size clamps initial bounds to the new extent; if the range becomes empty, adjust it before generating.

Space bounds determine the TIFF extent and, when periodic boundaries are enabled, where positions wrap. Without periodic boundaries they do not prevent trajectories from leaving the space.

Synthetic Dataset Generator controls in napari

The separate synthetic dataset generator.

Motion model and field preview

At each frame, the generator evaluates the velocity vector and diffusion coefficient at the track’s current position. It adds a directed displacement \(\mathbf{v}\Delta t\) and a random displacement in a uniformly sampled direction with length \(\sqrt{2dD\Delta t}\), where \(d\) is the number of dimensions, \(D\) is the diffusion coefficient and \(\Delta t\) is the frame interval. It then applies periodic wrapping if enabled. The random displacement has a fixed length for that step, not a normally distributed length.

Each component of velocity and the diffusion coefficient is defined by a separate spatial polynomial:

\[f(x,y,z) = \mathrm{cst} + a(x-b)^p + c(y-d)^q + e(z-f)^r\]

In 2D the Z term is omitted. Each term has a coefficient, center, and non-negative power; the model has no mixed terms such as \(xy\). The live equation in each field section reflects the entered polynomial before clamping. Negative diffusion values are clamped to zero for trajectory steps and diffusion-field exports; a warning is emitted when this happens. Negative coefficients are allowed because the resulting field can still be non-negative. Non-finite diffusion values at initial positions or where a step is computed remain errors. Positions use micrometers and time uses seconds: diffusion is in µm²/s and velocity in µm/s.

The Normalize by space size option is enabled by default for both diffusion and velocity: each term is coefficient * ((position - center) / size) ** power. For example, to make X velocity increase linearly from 0 to 2 µm/s across X, set its X coefficient to 2, its center to the X minimum, and its power to 1; set the constant and other terms to zero. Clear the checkbox to use the original unnormalized polynomial instead. Changing the checkbox reinterprets the entered values; it does not convert them. The saved config.csv always contains the equivalent physical diffusion and velocity coefficients for the command-line script.

The collapsible live field preview stays visible above the controls while you edit them. It shows the minimum and maximum of each field over the full space (including Z in 3D), not just the initial bounds or the XY slice. The ranges are calculated from each independent axis term’s endpoints and center. Undefined or non-finite fields are reported. The diffusion range shows clamped values and indicates when the underlying polynomial is negative. Without periodic boundaries, tracks can leave the space and encounter values outside these ranges.

The XY arrow preview samples the X and Y velocity components on a grid covering the space bounds. Arrows share a relative scale: their directions show the combined velocity, and their lengths are proportional to speed within that preview. The scale changes when the field changes; the maximum sampled speed is shown below the plot. X points right and Y points down, matching image coordinates. For 3D the preview is a slice at the midpoint of the Z space; it does not show Z velocity or random diffusion. It is an illustration, not generated trajectories or a validation of every possible position. Invalid or non-finite sampled velocities are reported instead of drawn. Fractional powers can be undefined for positions below their center.

Setting the X coefficient to 2, center to 0, and power to 1 in normalized velocity mode

Setting a linear X velocity gradient from 0 to 2 µm/s when the X space minimum is 0. Other velocity terms are set to zero.

Choose an existing output directory to save the generated files. Browse starts in your home directory when the field is empty. Leave the field empty to generate and display tracks without saving a dataset; intermediate files are created in a temporary directory and removed after generation. TIFF export is disabled when no output directory is specified.

When an output directory is provided, the synthetic TIFF export is enabled by default and writes stack.tiff. It is an XY projection even for 3D data. Its parallel rendering option is independent of the main analysis widget. Viewer tracks use the physical coordinates saved in positions.csv; TIFF coordinates are pixels relative to the space minima.

Click Generate synthetic dataset. When saving, the process confirms before replacing existing output files, saves its configuration and results, and displays the generated tracks in the viewer. Generation does not automatically load those tracks as an analysis database: use Load table, select positions.csv, apply the column mapping, and save a database to analyze them. Files not selected for export, such as an existing TIFF when TIFF export is off, are left unchanged.

napari troubleshooting

  • If the plugin is missing from napari, check that napari and Track Analyzer are installed in the same environment, as described in Installation.

  • If analysis cannot start, check the status and log, confirm info.txt and data_base.p are available, and remove or adjust empty subsets.

  • If an exported background cannot be found, save the image to a file or hide the background in the shared plotting configuration.

  • If map colors are unavailable, compute grid values and select a field with finite values. After changing grid inputs, recompute them.

  • If comparator fields are unavailable, check that the corresponding analysis tables exist and contain the selected numerical parameter in every dataset.