Difference between revisions of "SNT: Python Notebooks"

(Getting Started)
Line 1: Line 1:
 
=Python Notebooks=
 
=Python Notebooks=
 
Direct access to the SNT API from the [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.
 
Direct access to the SNT API from the [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.
 +
==Installing pyimagej==
 +
Follow the instructions given [https://github.com/imagej/pyimagej#installation here]
 
==Getting Started==
 
==Getting Started==
 
To initialize Fiji from Python:
 
To initialize Fiji from Python:

Revision as of 19:24, 11 April 2019

Python Notebooks

Direct access to the SNT API from the Python programming language is made possible with the pyimagej module. This enables full integration between SNT and any library in the Python ecosystem.

Installing pyimagej

Follow the instructions given here

Getting Started

To initialize Fiji from Python:

import imagej
ij = imagej.init('sc.fiji:fiji')

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 MouseLightLoader and TreeStatistics classes:

from jnius import autoclass
MouseLightLoader = autoclass('tracing.io.MouseLightLoader')
TreeStatistics   = autoclass('tracing.analysis.TreeStatistics')

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).

d_stats = TreeStatistics(tree)
metric = TreeStatistics.INTER_NODE_DISTANCE
summary_stats = d_stats.getSummaryStats(metric)
d_stats.getHistogram(metric).show()
print("The average inter-node distance is %d" % summary_stats.getMean())