Visualization is highly customizable in btmorph because you can access the data directly and subsequently use all available Python tools to visualize the data. Visualizing a neurite boils down to looping over all nodes in the tree and plotting a line segment in between the current node and its parent. As such, end users can implement their own visualization flexibly and efficiently.
In addition to the “DIY” method btmorph also contains several wrappers to quickly generate some standard visualizations of neurites. Below we illustrate the plotting capabilities included in btmorph. Please consult the API for more details about the visualization wrappers. All wrapper use standard Matplotlib functionality.
As in the previous tutorial, we assume the user is in the examples directory of the btmorph package. The exemplar neurons are from the Kawaguchi archive and downloaded from NeuroMorpho.org. Using the btmorph function filter_and_save_SWC we obtained “filtered” versions that only contain the basal and apical trees. These data files can be found in the folder examples/data.
Basic 2D plotting is provided and entails a straightforward projection onto the XY plane. First, we set up some of the files for later use.
full_fn = "data/CTh5080306F.CNG.swc" filtered_fn = "data/CTh5080306F.CNG_filtered.swc" basal_fn = "data/CTh5080306F.CNG_filtered_basal.swc" apical_fn = "data/CTh5080306F.CNG_filtered_apical.swc"
The color scheme used for 2D plotting can be adjusted. Currently only two schemes are in use: a default one and the one used by NeuroMorpho.org. Execute the following command:
import btmorph btmorph.plot_2D_SWC(full_fn,show_axis=False,color_scheme='default',depth='Y')
With this command axes are not drawn (show_axis=False), the default color scheme is used (color_scheme=’default’) and the Y axis, which is used to set the depth (i.e., from superficial to deep), corresponds to the Y-axis used in the SWC file (depth=’Y’). The color scheme and depth argument are redundant here because they are the defaults; calling the same function without them would produce the same figure as illustrated below.
A slight variation is shown below and uses the color_scheme=’neuromorpho’. But because thin neurites are hardly visible we can better draw a wire plot in which all neurites have the same diameter.
Plots can be either saved by using the interactive command in Ipython: savefig(‘name.extension’) (and see the matplotlib documentation for more info about the savefig command). Another option in btmorph is to provide the outN argument. The value of this argument has to be a string of the form 'name.extension'; either the full path can be included in the name or a relative path to save the figure in the current working directory.
A nice way to visualize variation in a set of morphologies is by plotting a spatial density of the neurites. In btmorph this can be achieved by the population_2D_density_projections.
import btmorph btmorph.population_density_projection(destination='data/pyr_pop/', \ filter='*.swc', outN="data/pyr_pop/density.png", precision=[10, 10, 10],depth='Y')
and results in the following image:
Pseudo 3D plotting¶
A 2D projection does not tell much about the spatial embedding of a neuron outside the projected plane. But 3D figures can become easily cluttered if many neurites are contained in one file. Therefore, we include two options for “pseudo 3D” plotting; that is, a plot containing three 2D projections that shows the neuron along three orthogonal axes.
To plot a plain-vanilla pseudo 3D figure, execute the following command:
import btmorph btmorph.true_2D_projections(filtered_fn,depth="Y",bar=[100,1000,100])
A similar pseudo 3D version is also available for the density plot.
import btmorph btmorph.population_2D_density_projections(destination='data/pyr_pop/', \ filter='*.swc', outN="data/pyr_pop/density.png", precision=[10, 10, 10])
3D plotting is currently under construction. The final API can change in the near future.
A 3D plot can still be convenient especially when you can interactively adjust the point of view using ipython --pylab -i.
Invoke the following code to generate a plot as illustrated below (left). A rotated version is plotted on the right.
A simple animation is provided to visually inspect a morphology in 3D. The animation rotates a morphology around the longest axis (generally the Y-axis in NeuroMorpho.org)