navis.segment_analysis¶
- navis.segment_analysis(x)[source]¶
Calculate morphometric properties a neuron’s segments.
This currently includes Strahler index, length, distance to root and tortuosity. If neuron has a radius will also calculate radius-based metrics such as volume.
- Parameters:
x (TreeNeuron | MeshNeuron) – Neuron(s) to produce segment analysis for.
parallel (bool) – If True and input is NeuronList, use parallel processing. Requires pathos.
n_cores (int, optional) – Numbers of cores to use if
parallel=True
. Defaults to half the available cores.progress (bool) – Whether to show a progress bar. Overruled by
navis.set_pbars
.omit_failures (bool) – If True will omit failures instead of raising an exception. Ignored if input is single neuron.
- Returns:
Each row represents one linear segment between leafs/branch nodes (corresponds to x.small_segments):
strahler_index is the Strahler Index of this segment
length is the geodesic length of the segment
tortuosity is the arc-chord ratio, i.e. the ratio of length to the distance between its ends
root_dist is the geodesic distance from the base of the segment to the root
If neuron node table has a radius column will also compute the following properties:
radius_mean
radius_max
radius_min
volume
- Return type:
pandas.DataFrame
See also
navis.strahler_index()
This function calculates the Strahler index for every nodes/vertex in the neuron.
navis.tortuosity()
This function calculates a tortuosity for the entire neuron.
Examples
Run analysis on a single neuron:
>>> import navis >>> n = navis.example_neurons(1, kind='skeleton') >>> n.reroot(n.soma, inplace=True) >>> sa = navis.segment_analysis(n) >>> sa.head() length tortuosity root_dist strahler_index ... volume 0 1073.535053 1.151022 229.448586 1 ... 4.159788e+07 1 112.682839 1.092659 10279.037511 1 ... 1.153095e+05 2 214.124934 1.013030 9557.521377 1 ... 8.618440e+05 3 159.585328 1.074575 9747.866968 1 ... 9.088157e+05 4 229.448586 1.000000 0.000000 6 ... 3.206231e+07 >>> # Get per Strahler index means >>> sa.groupby('strahler_index').mean() length tortuosity root_dist ... volume strahler_index 1 200.957415 1.111979 13889.593659 ... 8.363172e+05 2 171.283617 1.047736 14167.056400 ... 1.061405e+06 3 134.788019 1.023672 13409.920288 ... 9.212662e+05 4 711.063734 1.016606 15768.886051 ... 7.304981e+06 5 146.350195 1.000996 8443.345668 ... 2.262917e+06 6 685.852990 1.056258 1881.594266 ... 1.067976e+07
Compare across neurons:
>>> import navis >>> nl = navis.example_neurons(5, kind='skeleton') >>> sa = navis.segment_analysis(nl) >>> # Note the `neuron` column when running the analysis on NeuronLists >>> sa.head() neuron length tortuosity root_dist ... volume 0 1734350788 112.682839 1.092659 11123.123978 ... 1.153095e+05 1 1734350788 214.124934 1.013030 10401.607843 ... 8.618440e+05 2 1734350788 159.585328 1.074575 10591.953435 ... 9.088157e+05 3 1734350788 1073.535053 1.151022 0.000000 ... 4.159788e+07 4 1734350788 260.538727 1.000000 1073.535053 ... 3.593405e+07 >>> # Get Strahler index counts for each neuron >>> si_counts = sa.groupby(['neuron', 'strahler_index']).size().unstack() >>> si_counts strahler_index 1 2 3 4 5 6 7 neuron 722817260 656.0 336.0 167.0 74.0 32.0 24.0 NaN 754534424 726.0 345.0 176.0 111.0 37.0 9.0 18.0 754538881 642.0 344.0 149.0 88.0 21.0 24.0 NaN 1734350788 618.0 338.0 138.0 74.0 38.0 11.0 NaN 1734350908 761.0 363.0 203.0 116.0 20.0 33.0 NaN