Note
Click here to download the full example code
The Basics#
This tutorial will introduce some of the basics concepts in NAVis.
This is not supposed to be comprehensive but rather to give you a flavor of how things work. For inspiriation, explore the example gallery and for detailed explanations have a look at the API documentation.
Single Neurons#
NAVis lets you import neurons from a variety of local and remote sources. For demonstration purposes NAVis comes with a bunch of fruit fly neurons from the Janelia hemibrain project:
Note
We will cover loading neurons from different sources in a different tutorial.
import navis
# Load a single neuron
n = navis.example_neurons(n=1, kind='skeleton')
n
In above code we loaded one of the example neurons. NAVis represents neurons as navis.TreeNeuron
, navis.MeshNeuron
, navis.VoxelNeuron
or navis.Dotprops
.
In the above example we asked for a skeleton, so the neuron returned is a TreeNeuron
. This class is essentially a wrapper around the actual neuron data (the SWC table in this case) and has some convenient features.
Node data is stored as pandas.DataFrame
:
n.nodes.head()
Pandas
pandas is the data science library for Python and will help you analyze and visualize your data. We highly recommend familiarizing yourself with pandas! There are plenty of good tutorials out there but pandas' own 10 Minutes to pandas is a good place to start.
Try typing in "n.
" and hitting tab: most attributes and functions are accessible via autocompletion. If you don't know what a function does, check out the documentation using help()
or via the API documentation:
help(navis.TreeNeuron.root)
help(navis.TreeNeuron.downsample)
You will notice that many NAVis functions that accept neurons have an inplace
parameter. This is analogous to pandas:
Downsample a copy, leaving the original unchanged (this is the default for almost all functions)
n_ds = n.downsample(10, inplace=False)
# Downsample original neuron
n.downsample(10, inplace=True)
n
navis.TreeNeuron
functions such as .downsample()
are shorthands for calling the actual NAVis functions. So above code is equivalent to:
n = navis.example_neurons(n=1, kind='skeleton')
n_ds = navis.downsample_neuron(n, downsampling_factor=10, inplace=False)
n_ds
Lists of Neurons#
For multiple neurons, NAVis uses navis.NeuronList
:
nl = navis.example_neurons(n=3, kind='skeleton')
nl
navis.NeuronList
is a container and behaves like a glorified list
:
nl[0]
navis.NeuronList
lets you run/access all functions (methods) and properties of the neurons it contrains:
nl.cable_length
Out:
array([266476.88, 304332.66, 274703.38], dtype=float32)
nl_ds = nl.downsample(10, inplace=False)
nl_ds
Let's finish this primer with some eye candy
nl.plot3d(backend='plotly')
What next?#
-
Neuron types ---
Find out more about the different neuron types in NAVis.
-
Lists of Neurons ---
Check out the guide on lists of neurons.
-
Neuron I/O ---
Learn about how to load your own neurons into NAVis.
Total running time of the script: ( 0 minutes 0.478 seconds)
Download Python source code: tutorial_basic_00_basics.py