Radii Cleaning Tutorial#
Radii Cleaning fixes abnormal radius values while preserving branch continuity.
OS note: replace ./data/... with .\data\... on Windows. If swcstudio is not on PATH, use module mode (python -m swcstudio.cli.cli ... on macOS/Linux, py -m swcstudio.cli.cli ... on Windows).
Shared backend module:
swcstudio.tools.batch_processing.features.radii_cleaning
Validation tool reuses the same implementation through:
swcstudio.tools.validation.features.radii_cleaning
So GUI Batch tab, GUI Validation tab, and CLI all use one core behavior.
What counts as abnormal#
The current cleaner treats the SWC as directed paths instead of a flat node list.
It looks for:
non-positive radii (
<= 0)non-finite radii (
NaN,inf)local single-node spikes relative to a 5-node path window
radii that violate configured sanity bounds
branch points that become thicker distally than biologically expected
Triple-pass refinement#
The current cleaner follows a path-aware three-pass method:
Local outlier repairuses a 5-node neighborhood (
2upstream,2downstream)computes the local median radius
flags a node when
|R_current - R_median| / R_median > 0.5immediately replaces the flagged radius with the local median or a topology-based fallback
Global taper enforcementwalks each branch segment from soma/proximal anchor toward the leaf
enforces
R_i <= R_(i-1) * (1 + slack)default taper slack is
0.05axons can also enforce a minimum floor radius
Savitzky-Golay-style smoothinguses a local quadratic fit on each directed path
default window is
7nodesdefault polynomial order is
2smoothing runs after spike repair and taper enforcement, then taper is re-enforced once
Key config file#
swcstudio/tools/batch_processing/configs/radii_cleaning.json
Validation radii cleaning is a thin wrapper over the same backend and can layer per-tool overrides through:
swcstudio/tools/validation/configs/radii_cleaning.json
Important config fields#
Under rules:
soma radii are always preserved during radii cleaning
small_radius_zero_only: only treat very small values as abnormal if they are zerosanity_bounds.global.lower_percentilesanity_bounds.global.upper_percentilesanity_bounds.global.lower_abssanity_bounds.global.upper_abssanity_bounds.per_type: per-type overridesenabledlower_percentileupper_percentilelower_absupper_abs
local_outlier.enabledlocal_outlier.window_nodesdefault:
5
local_outlier.max_percent_deviationdefault:
0.5
taper.enabledtaper.slackdefault:
0.05
axon_floor.enabledaxon_floor.min_radiusdefault:
0.12
savgol.enabledsavgol.window_nodesdefault:
7
savgol.polyorderdefault:
2
savgol.gaussian_sigma_fractiondefault:
0.5
fixed_point.enabledfixed_point.max_passesdefault:
32
fixed_point.min_effective_deltadefault:
0.005
replacement.clamp_min,replacement.clamp_max
CLI examples#
Clean one file with the current JSON-configured three-pass method:
swcstudio radii-clean ./data/single-soma.swc
Clean one file while overriding rules for this run:
swcstudio radii-clean ./data/single-soma.swc --config-json '{"rules":{"local_outlier":{"max_percent_deviation":0.4}}}'
Validation command path (same backend):
swcstudio radii-clean ./data/single-soma.swc
Outputs and logs#
file mode: writes
<stem>_radii_cleaning_<timestamp>.swcand<stem>_radii_cleaning_<timestamp>.txtfolder mode: writes
<folder>/<folder>_batch_radii_cleaning_<timestamp>/plus a matching timestamped report
Report includes:
change counts
per-file summary (folder mode)
node-level change lines with old/new radii and reasons such as:
local_outliernon_positivenon_finitetaper_cappost_smooth_taper_capaxon_floorsavitzky_golay
config used
GUI notes#
GUI panels expose JSON editor to adjust the three-pass behavior
histogram/statistics view helps inspect the affected radius distribution
run-on-loaded-file and run-on-folder are available in appropriate panels
Auto Radii Editing runs to a fixed point so the cleaned file should reopen without the
Outlier radii detectedissue under the same rules