Display morphologies from a compiled networkΒΆ
There are several tools that you can use to visualize morphologies. Among them, you can use:
Brayns (efficient for large scale networks)
Matplotlib but only for a couple of morphologies
Here is a small code snippet showing how you can extract and display points of the morphology in 3D:
import numpy as np
from matplotlib.pylab import plt
from bsb import from_storage
scaffold = from_storage("my_circuit.hdf5")
cell_type_name = "my_cell_type"
ps = scaffold.get_placement_set(cell_type_name)
# We will only display one cell here
cell_id = 14 # cell id to display
morpho = ps.load_morphologies().get(cell_id)
rotation = ps.load_rotations()[cell_id]
offset_position = ps.load_positions()[cell_id]
# Rotate, translate morphology
morpho.rotate(rotation)
morpho.translate(offset_position)
# Example of 3D display with matplotlib
fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(111, projection="3d")
for branch in morpho.branches:
x, z, y = branch.points.T
# filter labels to use a different color for dendrites and axons
is_axon = np.array(
[
np.isin(list(branch.labelsets[branch.labels[i]]), ["axon"]).any()
for i in range(len(branch.points))
]
)
ax1.plot(x[~is_axon], y[~is_axon], z[~is_axon], c="blue")
ax1.plot(x[is_axon], y[is_axon], z[is_axon], c="red")
mins = np.min(morpho.points, axis=0)
maxs = np.max(morpho.points, axis=0)
ax1.plot([mins + max(maxs - mins)])
plt.show()
Remember that you can also load morphologies directly from their swc files:
from bsb import parse_morphology_file
morpho = parse_morphology_file("path/to/file.swc")