Skip to content, Skip to search

Changes

SNT: Python Notebooks

1,361 bytes removed, 19 May
Redirect to updated content
=Python Notebooks=Direct access to the SNT API from the #REDIRECT [https://www.python.org/ Python] programming language is made possible with the [https://pypi.org/project/pyimagej/ pyimagej] module. This enables full integration between SNT and any library in the Python ecosystem.==Getting Started==To initialize Fiji from Python:<source lang="python">import imagejij = imagej.init('sc.fiji:fiji')</source>Then, import the SNT classes you need. For example, to download a neuron reconstruction from the MouseLight database and calculate summary statistics on it, you would import the [http://javadoc.scijava.org/Fiji/tracing/io/MouseLightLoader MouseLightLoader_Scripting#Python_Notebooks] and [http://javadoc.scijava.org/Fiji/tracing/analysis/TreeStatistics.html TreeStatistics] classes: <source lang="python">from jnius import autoclassMouseLightLoader = autoclass('tracing.io.MouseLightLoader')TreeStatistics = autoclass('tracing.analysis.TreeStatistics')</source>Now you can access all the attributes and methods these classes offer. Let's get a summary of the inter-node distances for a cortical motor neuron (UUID = "AA0100" in the MouseLight database). <source lang="python">d_stats = TreeStatistics(tree)metric = TreeStatistics.INTER_NODE_DISTANCEsummary_stats = d_stats.getSummaryStats(metric)d_stats.getHistogram(metric).show()print("The average inter-node distance is %d" % summary_stats.getMean())</source>
Emailconfirmed
1,572
edits