Skip to content, Skip to search


SNT: Python Notebooks

2,354 bytes removed, 19 May
Redirect to updated content
==Introduction==Direct access to the SNT API from the [ Python] programming language is made possible through the [ pyimagej] module. This enables full integration between SNT and any library in the Python ecosystem.==Installing pyimagej==Follow the instructions given #REDIRECT [ here]==Getting Started==To initialize Fiji from Python with GUI capabilities:<source lang="python">import imagejij = imagej.init('sc.fiji:fiji', headless=False)</source>Then, use [ pyjnius] (bundled with pyimagej) to import the SNT (Java) 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: <source lang="python">from jnius import autoclassMouseLightLoader = autoclass('')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 specific mouse cortical motor neuron (ID = "AA0100" in the [ MouseLight database]). <source lang="python">def run(): loader = MouseLightLoader("AA0100") if not loader.isDatabaseAvailable(): print("Could not connect to ML database", "Error") return if not loader.idExists(): print("Somehow the specified id was not found", "Error") return  a_tree = loader.getTree('axon', None) _Scripting# compartment, color s_stats = TreeStatistics(a_tree) metric = TreeStatistics.INTER_NODE_DISTANCE summary_stats = s_stats.getSummaryStats(metric) s_stats.getHistogram(metric).show() print("The average inter-node distance is %d" % summary_stats.getMean())</source> ==Advanced Examples==The [ NotebooksPython_Notebooks] directory in the SNT [ GitHub repository ] contains examples which can be executed on [ Binder].