This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SMLMFrameConnection performs frame-connection on 2D SMLM localization data: combining repeated localizations of a single blinking fluorophore across frames into a single higher-precision localization. Implements the spatiotemporal LAP algorithm from Schodt & Lidke (2021).
# Run tests
julia --project=. -e 'using Pkg; Pkg.test()'
# Run a single test file
julia --project=. -e 'using Test, SMLMFrameConnection, SMLMData; include("test/test_helpers.jl"); include("test/test_frameconnect.jl")'
# Build docs locally
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
julia --project=docs docs/make.jl
# Quick REPL usage
julia --project=.Test files must include("test/test_helpers.jl") first since runtests.jl loads shared fixtures from it.
frameconnect() in frameconnect.jl is the main entry point. It orchestrates a 5-stage pipeline:
-
Precluster (
precluster.jl): Spatiotemporal clustering using KDTree nearest-neighbor search. Groups localizations withinmax_sigma_dist * mean(σ)distance andmax_frame_gapframes. Stores cluster assignments in emittertrack_idfields. -
Estimate parameters (
estimateparams.jl,estimatedensities.jl): Estimates photophysics rates (k_on, k_off, k_bleach, p_miss) from precluster statistics. Uses Optim.jl NelderMead to fit cumulative localization counts.estimatedensities.jlestimates local emitter density per cluster using KDTree neighbor distances. -
Connect via LAP (
connectlocalizations.jl->create_costmatrix.jl->solveLAP.jl->linkclusters.jl): For each multi-emitter precluster, builds a 2Nx2N cost matrix with connection/birth/death blocks using negative log-likelihoods from spatial separation, observation probability, and photophysics. Solves with Hungarian.jl.linkclusters.jlupdatesconnectIDfrom LAP assignments. -
Calibrate (optional,
calibration.jl): Whenconfig.calibrationis set, analyzes frame-to-frame jitter within connected tracks to estimate motion variance (σ_motion²) and CRLB scale factor (k²). Applies corrected uncertaintiesΣ_corrected = σ_motion² I + k² Σ_CRLBbefore combination. Falls back gracefully (identity correction) if insufficient data or poor fit. -
Combine (
combinelocalizations.jl): MLE weighted mean using full 2x2 covariance (precision-weighted). Produces higher-precision output localizations.
- Input/output:
BasicSMLDfrom SMLMData.jl containingEmitter2DFitemitters - Internal representation:
organizeclusters()converts toVector{Matrix{Float32}}where each matrix is a cluster with columns:[x, y, σ_x, σ_y, σ_xy, frame, dataset, connectID, sortindex] ParamStruct: mutable struct accumulating estimated parameters through the pipeline- Return: tuple
(combined::BasicSMLD, info::FrameConnectInfo)
FrameConnectConfig <: AbstractSMLMConfig: User-facing config (keyword-constructible)FrameConnectInfo{T} <: AbstractSMLMInfo: Algorithm output metadata (track assignments, rates, timing)CalibrationConfig: Optional uncertainty calibration settings (nested inFrameConnectConfig.calibration)CalibrationResult: Calibration diagnostics (nested inFrameConnectInfo.calibration,nothingwhen disabled)ParamStruct: Internal mutable state for pipeline parameters (not exported; access viaSMLMFrameConnection.ParamStruct)
frameconnect() accepts both kwargs and a FrameConnectConfig struct. The kwargs form constructs the config internally. Both FrameConnectConfig and FrameConnectInfo inherit from SMLMData abstract types.
- SMLMData.jl (v0.7): Provides
BasicSMLD,Emitter2DFit,IdealCamera, abstract config/info types - Hungarian.jl: LAP solver in
solveLAP.jl - NearestNeighbors.jl: KDTree for preclustering and density estimation
- Optim.jl: Parameter estimation (Fminbox + NelderMead)
- Positions and uncertainties in microns
- Frame numbers are 1-based integers
track_id=0means unconnected; populated values are compressed to1:n_tracks- Mutating functions use
!suffix with non-mutating wrappers (e.g.,connectlocalizations!/connectlocalizations) - Emitter precision type
ETis derived from emitter field values, not SMLD type parameter