Internals

Non-exported helpers. These are implementation details and may change between releases — they are documented here for contributors. See Extending the Pipeline for the public extension points.

SMLMAnalysis.TeeLoggerType
TeeLogger(loggers)

Logger that forwards messages to multiple loggers. Used internally to tee @info output to both console and log file.

source
SMLMAnalysis._auto_cameraMethod
_auto_camera(cfg::DetectFitConfig) -> AbstractCamera

Resolve camera from DetectFitConfig. Uses cfg.camera if set, otherwise auto-builds from MIC H5 calibration when pixel_size is provided.

source
SMLMAnalysis._calculate_modeMethod
_calculate_mode(values; n_bins=100)

Calculate the mode of a distribution using histogram binning. Returns the center of the most populated bin.

Uses a median-centered range (median ± 3×MAD) to avoid outlier peaks at large fitted PSF sigma pulling the mode away from the true peak.

source
SMLMAnalysis._compute_bin_statMethod
_compute_bin_stat(xs, ys, values, cfg, stat_fn) -> Matrix{Float64}

Bin emitters spatially and compute stat_fn(bin_values) per bin. Returns n_bins × n_bins grid in Makie convention: grid[ix, iy] maps to (x_centers[ix], y_centers[iy]) when used with heatmap!(ax, x_centers, y_centers, grid).

This is the fundamental convention: first array index = x-axis (horizontal), second = y-axis (vertical). Julia arrays are (row, col) = (y, x) in image convention, but Makie's heatmap maps first index to x. So we store as [ix, iy].

source
SMLMAnalysis._compute_crosscorrMethod
_compute_crosscorr(smld_a, smld_b, cfg) -> (r, g, area)

Compute pair cross-correlation g(r) between two SMLDs using KDTree + Ripley's edge correction.

source
SMLMAnalysis._compute_intensity_pvaluesMethod
_compute_intensity_pvalues(xs, ys, photons, field_model)

Compute Poisson upper-tail p-values for each emitter. p = P(X ≥ N) where X ~ Poisson(λ) and λ = field_model(x, y).

λ is the per-bin percentile (upper bound of single-emitter emission at this position), so emitters near or below λ get p ≈ 1 (kept), while emitters far above λ get small p.

source
SMLMAnalysis._convolve_1dMethod
_convolve_1d(h::Vector{Float64}) -> Vector{Float64}

Self-convolution of histogram h. Returns vector of length 2n-1 where n = length(h). The result represents the distribution of the sum of two independent draws from h.

source
SMLMAnalysis._default_colorsMethod
_default_colors(n::Int) -> Vector{Symbol}

Default color palette for multi-target rendering. 2 channels: cyan/magenta. 3 channels: cyan/magenta/yellow. Supports up to 6 channels; provide explicit colors for more.

source
SMLMAnalysis._estimate_bleaching_rateMethod
_estimate_bleaching_rate(frame_counts) -> NamedTuple or nothing

Fit N(t) = a + b*exp(-k*t) to a per-frame localization count vector via linearized initial guess + Nelder-Mead refinement.

This is the OBSERVED decay rate, not the true kbleach for GenericFluor: bleaching only occurs from the On state, so `kobserved = kbleach * Pon, wherePon = kon/(kon+koff)is the duty cycle. To get true k_bleach:kbleach = kobserved / P_on`.

Returns (k_bleach, N_0, offset, half_life, r_squared, valid_frames, smoothed) or nothing if the fit fails.

source
SMLMAnalysis._estimate_excitation_fieldMethod
_estimate_excitation_field(xs, ys, photons, lambda_global, cfg, verbose)

Estimate excitation field from per-bin percentiles of photon counts.

Each spatial bin computes quantile(photons, rate_percentile) independently, capturing the local upper bound of single-emitter emission. A Gaussian field model is then fit to these per-bin rates to produce a smooth field_model(x, y).

Returns (actual_mode, field_params, r2, field_model).

source
SMLMAnalysis._estimate_p2Method
_estimate_p2(xs, ys, photons, field_model, cfg) -> (p2, tail_obs, tail_f2)

Estimate double-emitter fraction via mixture decomposition of field-normalized photons.

Algorithm:

  1. Compute normalized photons: n_i = photons_i / λ(x_i, y_i)
  2. Histogram fobs with `p2n_binsbins over[0, p99.5]`
  3. Self-convolve: f₂ = conv(f_obs, f_obs) — distribution of sum of two singles
  4. At threshold τ: p₂ = Σf_obs(>τ) / Σf₂(>τ)

Returns (nothing, nothing, nothing) if estimation fails (e.g., zero tail mass).

source
SMLMAnalysis._fit_gaussian_fieldMethod
_fit_gaussian_field(cx, cy, rates, xs, ys)

Fit N(x,y) = A·exp(-2·((x-x₀)² + (y-y₀)²)/w²) + bg to per-bin rates.

Returns (params::NamedTuple, r2::Float64) or (nothing, 0.0) on failure.

source
SMLMAnalysis._get_psf_sigma_boundsMethod
_get_psf_sigma_bounds(range_spec, values) -> (lo, hi)

Calculate PSF sigma filter bounds.

  • :auto → mode ± 10%
  • (min, max) → explicit bounds in microns
source
SMLMAnalysis._grid_figure_sizeMethod
_grid_figure_size(data; n_cols=4, n_rows=3, panel_height=200)

Calculate figure size for grid overlay plots based on data aspect ratio.

source
SMLMAnalysis._inject_cameraMethod
_inject_camera(cfg::DetectFitConfig, camera::AbstractCamera) -> DetectFitConfig

Inject camera into DetectFitConfig if not already set. Used by AnalysisConfig pipeline.

source
SMLMAnalysis._plan_sample_framesFunction
_plan_sample_frames(ds_frame_counts::Vector{Int}, n_samples::Int=12)

Precompute which frames to sample across all datasets for overlay plots. Always includes first and last absolute frames, with equal spacing between.

Returns (plan, abs_frames):

  • plan::Dict{Int, Vector{Int}}: dataset index → local frame indices to capture
  • abs_frames::Vector{Int}: absolute frame numbers for display labels (in order)
source
SMLMAnalysis._produces_smldMethod
_find_final_smld_step(steps) -> Int

Walk steps in reverse and return the 1-based index of the last step that produces a BasicSMLD (i.e., not a terminal render). Returns 0 if no SMLD-producing step is found.

Used by _run_pipeline to translate Checkpoint.END into a per-step "this is the final, save it" decision.

source
SMLMAnalysis._resolve_colorsMethod
_resolve_colors(cfg::CompositeRenderConfig, defaults::Vector{Symbol}) -> Vector{Symbol}

Use per-step colors if specified, otherwise fall back to MultiTargetConfig defaults.

source
SMLMAnalysis._resolve_file_sourcesMethod

Resolve file-based sources from config options.

Returns a vector of NamedTuples describing each dataset to load. Dataset count is determined from the data structure, not from a config field.

source
SMLMAnalysis._resolve_psf_boundsMethod
_resolve_psf_bounds(emitters, cfg) -> Union{NamedTuple, Nothing}

Pre-resolve PSF sigma filter bounds from the emitter population. Returns named tuple with :iso or :aniso bounds, or nothing if psf_sigma filter is off.

source
SMLMAnalysis._rightmost_significant_peakMethod
_rightmost_significant_peak(smoothed, peak_threshold) -> Int

Index of the rightmost local maximum of smoothed (a value ≥ both neighbours, with a missing right edge treated as 0) whose height is at least peak_threshold. Returns 1 if none qualifies. Shared by the valley-threshold search and the diagnostic figure so both mark the same peak.

source
SMLMAnalysis._ripley_edge_weightMethod
_ripley_edge_weight(x, y, r, bounds) -> Float64

Ripley's isotropic edge correction: fraction of circle circumference at (x,y) with radius r that falls inside the rectangular FOV defined by bounds.

Returns a weight in (0, 1]. Points near boundaries get lower weights, which are inverted to up-weight their contributions.

source
SMLMAnalysis._run_pipelineFunction
_run_pipeline(initial_state, steps, camera, outdir, verbose)

Internal pipeline executor. Folds analyze() dispatch over the steps vector, threading state through each step. Step routing is determined entirely by Julia's method dispatch on (state_type, config_type).

Wrong step ordering produces a MethodError — e.g., FilterConfig before DetectFitConfig gives no method matching analyze(::Vector{...}, ::FilterConfig).

source
SMLMAnalysis._save_box_overlayMethod
_save_box_overlay(dir, filename, images, roi_batch, box_colors; ...)

ROIBatch convenience (detectfit/filter): unpack x_corners/y_corners/frame_indices/roi_size and delegate to the core renderer above. Behavior unchanged for existing callers.

source
SMLMAnalysis._save_box_overlayMethod
_save_box_overlay(dir, filename, images, x_corners, y_corners, frame_indices, box_size, box_colors; ...)

Core box-overlay renderer: a grid of sample frames (contrast-stretched grayscale) with a colored box_size rectangle drawn at each (x_corner, y_corner) on its frame. This is the shared "boxes on the raw data" diagnostic style — detectfit (detection_overlay.png) and filter (fit_overlay.png) render through it so the whole pipeline's overlays are one visual family.

The box-geometry is passed as plain arrays so non-ROIBatch callers use the identical renderer; see the roi_batch convenience method below.

source
SMLMAnalysis._save_continuous_drift_figureMethod

Plot drift trajectory with global frame view for multi-dataset acquisitions. Uses drift_trajectory default mode (inter + intra per chunk) so boundary discontinuities between chunks are visible as gaps.

source
SMLMAnalysis._save_drift_jitter_plotMethod

Plot frame-to-frame drift jitter and cumulative drift from linked emitters. Three panels: jitter X, jitter Y (top), cumulative drift (bottom). Uses global frame numbering (absolute_frame across datasets).

source
SMLMAnalysis._save_filter_quality_figuresMethod
_save_filter_quality_figures(dir, smld_raw, cfg)

Generate fit quality distribution plots with filter thresholds highlighted. Shows photons, background, precision, p-value, and PSF sigma distributions from the raw (unfiltered) SMLD, with rejected regions marked per FilterConfig.

source
SMLMAnalysis._save_fit_overlayMethod

Generate fit overlay: boxes colored by fit quality using FilterConfig thresholds.

Colors: green=pass, red=photons fail, orange=precision fail, purple=pvalue fail, gray=no match.

source
SMLMAnalysis._save_info!Method
_save_info!(dir::String, info; section::String="")

Write upstream Info struct fields to info.toml in TOML format.

Writes scalar fields (numbers, bools, strings, symbols, tuples of scalars). Skips complex fields (arrays, dicts, structs like BasicSMLD, models).

When section is empty, writes a fresh file with type header. When section is provided, appends a [section] block.

source
SMLMAnalysis._save_loc_per_frameMethod
_save_loc_per_frame(dir, smld; filename, title) -> bleach_result or nothing

Plot localizations per absolute frame across all datasets, with photobleaching exponential decay fit overlay (a + b*exp(-k*t)). Marks dataset boundaries for multi-dataset SMLDs.

Used by detectfit (raw fits) and filter (post-filter fits) steps.

source
SMLMAnalysis._save_pipeline_config!Method
_save_pipeline_config!(dir, steps, camera, roi, verbose, checkpoint)

Write the orchestration-level AnalysisConfig to dir/config.toml.

Mirrors the per-step _save_config! (which writes each step's config into its own subdir) but captures what those don't: the camera, the global ROI crop, verbosity, checkpoint level, and a manifest of the step sequence.

source
SMLMAnalysis._save_step_smldMethod
_save_step_smld(dir, smld; filename, kwargs...)

Persist a step's output SMLD via JLD2 so downstream iteration (e.g., diagnostic plots, parameter sweeps, BaGoL re-runs) can resume without re-running the upstream pipeline. The SMLD is stored under the smld key:

data = JLD2.load("path/smld_corrected.jld2")
smld = data["smld"]   # full BasicSMLD with camera, n_frames, n_datasets

Extra named values are stored as additional top-level keys (e.g., pass drift_model=drift_model to embed the drift model alongside the SMLD).

No-op if dir is nothing.

source
SMLMAnalysis._select_sourcesMethod

Apply cfg.datasets selection to a resolved source list. Bounds-checks and returns the selected subset in the order given. Pass-through when cfg.datasets is nothing.

source
SMLMAnalysis._spatial_bin_ratesMethod
_spatial_bin_rates(xs, ys, photons, cfg)

Bin emitters spatially and compute rate_percentile of photons per bin. Returns named tuple with centers_x, centers_y, rates, counts, and grid info.

source
SMLMAnalysis._valley_thresholdMethod

Find threshold using valley detection between isolated (low neighbors) and clustered (high neighbors).

Algorithm:

  1. Build and smooth histogram
  2. Find rightmost significant peak (clustered population)
  3. Find local minimum (valley) between origin and that peak
  4. If no clear valley (unimodal), use heuristics based on peak position
source
SMLMAnalysis._write_camera!Method
_write_camera!(io, cam)

Write a compact [camera] provenance block: type, pixel grid dimensions, and pixel size derived from the edge vectors (rather than dumping the full edges). sCMOS calibration fields are written as scalars, or summarized by shape if maps.

source
SMLMAnalysis._write_composite_readme!Method
_write_composite_readme!(composite_dir, config, smlds, step_infos)

Write a README.md in the composite directory documenting the color scheme, channel labels, multi-target steps, and per-channel localization counts.

source
SMLMAnalysis._write_detection_frame_moviesMethod
_write_detection_frame_movies(dir, stacks, abs_frames, fps, v)

DEBUG-verbosity output. For each detection-overlay gallery frame, write a short realtime MP4 of the raw camera frames. stacks[k] is a (H, W, ~100)-frame window containing gallery frame abs_frames[k] (same order as the overlay panel). Contrast is ONE global linear stretch over the whole 100-frame window: black point = 0.1st percentile (0.001), white point = 99.9th percentile (0.999) of all pixels in the window. Played at fps (realtime = 1/exposure). A label (frame / fps / stretch percentiles / black-white values) is burned into each frame. Files: dir/frame_movies/detection_frame_<gallery_frame>.mp4. Requires ffmpeg on PATH.

source
SMLMAnalysis.bagol_stepMethod
bagol_step(smld, cfg; outdir=nothing, step_number=0, verbose=Verbosity.STANDARD)

Group localizations into emitters via BaGoL. Returns (bagol_smld, BaGoLInfo).

source
SMLMAnalysis.cache_dirMethod
cache_dir(outdir) -> Union{String, Nothing}

Returns joinpath(outdir, ".cache") or nothing if outdir is nothing.

source
SMLMAnalysis.composite_render_stepMethod
composite_render_step(smlds, cfg; outdir, step_number, verbose, colors) -> (smlds, CompositeRenderInfo)

Render a multi-channel composite image. SMLDs pass through unmodified.

source
SMLMAnalysis.crossalign_stepMethod
crossalign_step(smlds, cfg; outdir, step_number, verbose) -> (aligned_smlds, CrossAlignInfo)

Align multiple SMLDs to a common reference using entropy-based alignment.

source
SMLMAnalysis.crosscorr_stepMethod
crosscorr_step(smlds, cfg; outdir, step_number, verbose, labels) -> (smlds, CrossCorrInfo)

Compute pair cross-correlation g(r) between two channels. SMLDs pass through unmodified.

source
SMLMAnalysis.densityfilter_stepMethod
densityfilter_step(smld, cfg; outdir=nothing, step_number=0, verbose=Verbosity.STANDARD)

Filter localizations by neighbor density. Returns (filtered_smld, DensityFilterInfo).

Arguments

  • smld::BasicSMLD: Input localizations
  • cfg::DensityFilterConfig: Density filter parameters

Keyword Arguments

  • outdir: Output directory (nothing to skip file output)
  • step_number: Step number for output directory naming
  • verbose: Verbosity level

Returns

(filtered_smld, DensityFilterInfo)

source
SMLMAnalysis.detectfitMethod
detectfit(images::AbstractArray{<:Real,3}, camera, cfg; kwargs...) -> (smld, info)

Convenience method for a single image stack. Wraps into a 1-element vector.

source
SMLMAnalysis.detectfitMethod
detectfit(camera, cfg; kwargs...) -> (smld, info)

File-based detectfit. Loads image data from cfg.path or cfg.paths. Each data source is loaded one at a time for memory efficiency.

source
SMLMAnalysis.detectfitMethod
detectfit(data, camera, cfg; kwargs...) -> (smld, DetectFitInfo)

Run combined detection and fitting on image data.

Arguments

  • data::Vector{<:AbstractArray{<:Real,3}}: Vector of image stacks (one per dataset)
  • camera::AbstractCamera: Camera model
  • cfg::DetectFitConfig: Detection and fitting configuration

Keywords

  • outdir::Union{String,Nothing}=nothing: Output directory for results
  • step_number::Int=1: Step number in the pipeline
  • verbose::Int=Verbosity.STANDARD: Verbosity level

Returns

(smld::BasicSMLD, info::DetectFitInfo)

source
SMLMAnalysis.driftcorrect_stepMethod
driftcorrect_step(smld, cfg; outdir, step_number, verbose) -> (corrected_smld, DriftInfo)

Run drift correction on smld, returning the corrected SMLD as the primary result, plus the upstream DriftInfo.

Returns

(corrected_smld, DriftInfo)

source
SMLMAnalysis.filter_stepMethod
filter_step(smld, cfg; outdir=nothing, step_number=0, verbose=Verbosity.STANDARD)

Filter localizations by quality criteria. Returns (filtered_smld, FilterInfo).

Diagnostic plots use smld (the input) for pre-filter distributions.

Arguments

  • smld::BasicSMLD: Input localizations
  • cfg::FilterConfig: Filter criteria

Keyword Arguments

  • outdir: Output directory (nothing to skip file output)
  • step_number: Step number for output directory naming
  • verbose: Verbosity level

Returns

(filtered_smld, FilterInfo)

source
SMLMAnalysis.frameconnect_stepMethod
frameconnect_step(smld, cfg; outdir, step_number, verbose) -> (combined_smld, FrameConnectInfo)

Run frame connection on smld, returning the combined (recombined) SMLD as the primary result, plus the upstream FrameConnectInfo.

When cfg.calibration is set, uncertainty calibration is applied before combination: link -> calibrate -> combine (single pass with correct weights).

Returns

(combined_smld, FrameConnectInfo)

source
SMLMAnalysis.intensityfilter_stepMethod
intensityfilter_step(smld, cfg; outdir=nothing, step_number=0, verbose=Verbosity.STANDARD)

Filter localizations by intensity-based multi-emitter rejection. Returns (filtered_smld, IntensityFilterInfo).

source
SMLMAnalysis.load_cacheMethod
load_cache(outdir, filename) -> Union{Dict, Nothing}

Load data from outdir/.cache/filename via JLD2. Returns nothing if missing or outdir is nothing.

source
SMLMAnalysis.render_stepMethod
render_step(smld, cfg; outdir=nothing, step_number=0, verbose=Verbosity.STANDARD)

Render localizations to a super-resolution image. Returns (render_image, RenderInfo).

Arguments

  • smld::BasicSMLD: Input localizations
  • cfg::SMLMRender.RenderConfig: Render configuration

Keyword Arguments

  • outdir: Output directory (nothing to skip file output)
  • step_number: Step number for output directory naming
  • verbose: Verbosity level

Returns

(render_image, RenderInfo)

source
SMLMAnalysis.save_cacheMethod
save_cache(outdir, filename; kwargs...)

Save data to outdir/.cache/filename via JLD2. No-op if outdir is nothing.

source