Analyze spike activity results¶
Note
This guide is a continuation of the Simulation guide.
After a simulation, BSB will write its outcomes in .nio
files. These files leverage the HDF5
(Hierarchical Data Format version 5) format, which is widely employed in scientific computing,
engineering, and data analysis. HDF5 files store data in groups (or blocks), in a dictionary
fashion, which allows for efficient management and organization of large datasets.
The content is read/written using the Neo Python package, a library designed for handling electrophysiology data.
Let’s extract the spike train data produced by your last simulation. First, load the content from
your simulation-results/NAME_OF_YOUR_NEO_FILE.nio
file, use the following code:
from neo import io
# Read simulation data
my_file_name = "simulation-results/NAME_OF_YOUR_NEO_FILE.nio"
sim = io.NixIO(my_file_name, mode="ro")
block = sim.read_all_blocks()[0]
segment = block.segments[0]
my_spiketrains = segment.spiketrains
In our case, we have only one block
of data since we only ran one simulation. We also have a
unique segment
since all our data is recorded with the same time frame (see
Neo docs for more details).
If you followed the previous simulation example, the list my_spiketrains
should contain the
spike trains generated by background noise, as well as by base type and
top type cells.
Each SpikeTrain
object holds information about the device name,
the size of the cell population, and an array of the IDs of spiking cells, accessible through the
annotations attribute:
import matplotlib.pylab as plt # you might have to pip install matplotlib
nb_spike_trains = len(my_spiketrains)
fig, ax = plt.subplots(nb_spike_trains, sharex=True, figsize=(10, nb_spike_trains * 6))
for i, spike_t in enumerate(my_spiketrains): # Iterate over all spike trains
name = spike_t.annotations["device"] # Retrieve the device name
cell_list = spike_t.annotations["senders"] # Retrieve the ids of the cells spiking
spike_times = spike_t.magnitude # Retrieve the spike times
ax[i].scatter(spike_times, cell_list, c=f"C{i}")
ax[i].set_xlabel(f"Time ({spike_t.times.units.dimensionality.string})")
ax[i].set_ylabel(f"Neuron ID")
ax[i].set_title(f"Spikes from {name}")
plt.tight_layout()
plt.savefig("simulation-results/raster_plot.png", dpi=200)
This code should produce one figure with 3 subplots showing the raster plot of spiking activity
for each device created in the simulation. The resulting figure is saved in the
simulation-results
folder. The plot for the base type cells should show some spike events:

These events indicates that some cells are receiving more spikes from the generator.
Various analyses can be perform on spiking data, and several tools facilitate these. If you want to learn more about spike analysis, we recommend the Elephant python package already integrates Neo, and the Analysis of Parallel Spike Trains and the Neuronal Dynamics books on this topic.
Next steps: