Radii Cleaning Tutorial#
Radii Cleaning fixes abnormal radius values while preserving branch continuity.
OS note: replace / with \ in paths 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 cleaner changes a radius only when it is certainly wrong, by one of three tests:
Invalid: zero, negative, or not a number (
NaN,inf).Implausible: above its type’s plausible maximum (axon 5 µm, basal dendrite 8 µm, apical dendrite 10 µm, other neurite types 10 µm). The ranges are fixed, so a file whose radii are mostly wrong cannot widen them.
An isolated spike or dip: more than 3 times thicker or thinner than the median of its plausible neighbours on both sides along the branch (2 upstream, 2 downstream). On 1,500 expert-traced cells, 99% of radii lie within x1.9 of their neighbours and 0.5% beyond x3, so natural variation is left alone.
Every other radius is kept as it is, including placeholders such as 0.004 unless one sits alone among real values. Each changed node records the test it failed.
Triple-pass refinement#
The current cleaner follows a path-aware three-pass method:
Local outlier repairuses a 5-node neighborhood (
2upstream,2downstream), plausible radii only, and needs a neighbour on each sideflags a node when
R_current > 3 * R_medianorR_current < R_median / 3(local_outlier.max_ratio), and every invalid or implausible radiusreplaces the flagged radius with the local median or a topology-based fallback
Taper enforcement(off by default)when
taper.enabledis on: walks each branch from the soma toward the tips and enforcesR_i <= R_(i-1) * (1 + slack)(slack0.05)off by default because real dendrites do not taper monotonically: the cap changed correct radii, and one thin node thinned everything distal to it
axons can also enforce a minimum floor radius (
axon_floor, off by default)
Savitzky-Golay-style smoothingrefines the replacement value of flagged nodes only, with a local quadratic fit over their plausible neighbours
default window is
7nodes, polynomial order2
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 zero (defaulttrue; a small value can still be a local outlier)sanity_bounds.default: plausible range for types without their own entrymin_radius(default0.05),max_radius(default10)
sanity_bounds.per_type: plausible range per node type, keyed by type name or ID (withtype_id)enabledmin_radius,max_radius(µm): axon0.05–5, basal dendrite0.05–8, apical dendrite0.05–10configs from earlier versions with
lower_abs/upper_absstill work; their percentile keys are ignored
local_outlier.enabledlocal_outlier.window_nodesdefault:
5
local_outlier.max_ratiodefault:
3(replacesmax_percent_deviation)
taper.enableddefault:
false
taper.slackdefault:
0.05
axon_floor.enableddefault:
false(many real axons are thinner than 0.12 µm)
axon_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 cell.swc
Clean one file while overriding rules for this run:
swcstudio radii-clean cell.swc --config-json '{"rules":{"local_outlier":{"max_ratio":2.5}}}'
Validation command path (same backend):
swcstudio radii-clean cell.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