SpikeMonitor class
(Shortest import: from brian2 import SpikeMonitor)
- class brian2.monitors.spikemonitor.SpikeMonitor(*args, **kw)[source]
Bases:
EventMonitor
Record spikes from a
NeuronGroup
or other spike source.The recorded spikes can be accessed in various ways (see Examples below): the attributes
i
andt
store all the indices and spike times, respectively. Alternatively, you can get a dictionary mapping neuron indices to spike trains, by calling thespike_trains
method. If you record additional variables with thevariables
argument, these variables can be accessed by their name (see Examples).- Parameters:
source : (
NeuronGroup
,SpikeSource
)The source of spikes to record.
variables : str or sequence of str, optional
Which variables to record at the time of the spike (in addition to the index of the neuron). Can be the name of a variable or a list of names.
record : bool, optional
Whether or not to record each spike in
i
andt
(thecount
will always be recorded). Defaults toTrue
.when : str, optional
When to record the events, by default records events in the same slot where the event is emitted. See Scheduling for possible values.
order : int, optional
The priority of of this group for operations occurring at the same time step and in the same scheduling slot. Defaults to the order where the event is emitted + 1, i.e. it will be recorded directly afterwards.
name : str, optional
A unique name for the object, otherwise will use
source.name+'_spikemonitor_0'
, etc.codeobj_class : class, optional
The
CodeObject
class to run code with.
Examples
>>> from brian2 import * >>> spikes = SpikeGeneratorGroup(3, [0, 1, 2], [0, 1, 2]*ms) >>> spike_mon = SpikeMonitor(spikes) >>> net = Network(spikes, spike_mon) >>> net.run(3*ms) >>> print(spike_mon.i[:]) [0 1 2] >>> print(spike_mon.t[:]) [ 0. 1. 2.] ms >>> print(spike_mon.t_[:]) [ 0. 0.001 0.002] >>> from brian2 import * >>> G = NeuronGroup(2, '''counter1 : integer ... counter2 : integer ... max_value : integer''', ... threshold='counter1 >= max_value', ... reset='counter1 = 0') >>> G.run_regularly('counter1 += 1; counter2 += 1') CodeRunner(...) >>> G.max_value = [50, 100] >>> mon = SpikeMonitor(G, variables='counter2') >>> net = Network(G, mon) >>> net.run(10*ms) >>> print(mon.i[:]) [0 0 1] >>> print(mon.counter2[:]) [ 50 100 100]
Attributes
The array of spike counts (length = size of target group)
Returns the total number of recorded spikes.
Methods
Return a dictionary mapping recorded variable names (including
t
) to a dictionary mapping neuron indices to arrays of variable values at the time of the spikes (sorted by time).Return a dictionary mapping neuron indices to arrays of spike times.
values
(var)Return a dictionary mapping neuron indices to arrays of variable values at the time of the spikes (sorted by time).
Details
- count
The array of spike counts (length = size of target group)
- num_spikes
Returns the total number of recorded spikes.
- all_values()[source]
Return a dictionary mapping recorded variable names (including
t
) to a dictionary mapping neuron indices to arrays of variable values at the time of the spikes (sorted by time). This is equivalent to (but more efficient than) callingvalues
for each variable and storing the result in a dictionary.- Returns:
all_values : dict
Dictionary mapping variable names to dictionaries which themselves are mapping neuron indicies to arrays of variable values at the time of the spikes.
Examples
>>> from brian2 import * >>> G = NeuronGroup(2, '''counter1 : integer ... counter2 : integer ... max_value : integer''', ... threshold='counter1 >= max_value', ... reset='counter1 = 0') >>> G.run_regularly('counter1 += 1; counter2 += 1') CodeRunner(...) >>> G.max_value = [50, 100] >>> mon = SpikeMonitor(G, variables='counter2') >>> run(10*ms) >>> all_values = mon.all_values() >>> print(all_values['counter2'][0]) [ 50 100] >>> print(all_values['t'][1]) [ 9.9] ms
- spike_trains()[source]
Return a dictionary mapping neuron indices to arrays of spike times.
- Returns:
spike_trains : dict
Dictionary that stores an array with the spike times for each neuron index.
Examples
>>> from brian2 import * >>> spikes = SpikeGeneratorGroup(3, [0, 1, 2], [0, 1, 2]*ms) >>> spike_mon = SpikeMonitor(spikes) >>> run(3*ms) >>> spike_trains = spike_mon.spike_trains() >>> spike_trains[1] array([ 1.]) * msecond
- values(var)[source]
Return a dictionary mapping neuron indices to arrays of variable values at the time of the spikes (sorted by time).
- Parameters:
var : str
The name of the variable.
- Returns:
values : dict
Dictionary mapping each neuron index to an array of variable values at the time of the spikes.
Examples
>>> from brian2 import * >>> G = NeuronGroup(2, '''counter1 : integer ... counter2 : integer ... max_value : integer''', ... threshold='counter1 >= max_value', ... reset='counter1 = 0') >>> G.run_regularly('counter1 += 1; counter2 += 1') CodeRunner(...) >>> G.max_value = [50, 100] >>> mon = SpikeMonitor(G, variables='counter2') >>> run(10*ms) >>> counter2_values = mon.values('counter2') >>> print(counter2_values[0]) [ 50 100] >>> print(counter2_values[1]) [100]
Tutorials and examples using this
Tutorial 1-intro-to-brian-neurons
Tutorial 3-intro-to-brian-simulations
Example CUBA
Example IF_curve_Hodgkin_Huxley
Example IF_curve_LIF
Example adaptive_threshold
Example advanced/custom_events
Example advanced/modelfitting_sbi
Example advanced/opencv_movie
Example compartmental/hh_with_spikes
Example frompapers/Brette_2004
Example frompapers/Brette_2012/Fig5A
Example frompapers/Brette_Gerstner_2005
Example frompapers/Brette_Guigon_2003
Example frompapers/Brunel_2000
Example frompapers/Brunel_Hakim_1999
Example frompapers/Brunel_Wang_2001
Example frompapers/Diesmann_et_al_1999
Example frompapers/Izhikevich_2003
Example frompapers/Izhikevich_2007
Example frompapers/Nicola_Clopath_2017
Example frompapers/Rossant_et_al_2011bis
Example frompapers/Stimberg_et_al_2018/example_6_COBA_with_astro
Example frompapers/Stimberg_et_al_2019/example_3_bisection_standalone
Example frompapers/Sturzl_et_al_2000
Example frompapers/Touboul_Brette_2008
Example frompapers/Vogels_et_al_2011
Example frompapers/Wang_2002
Example non_reliability
Example phase_locking
Example reliability
Example standalone/STDP_standalone
Example standalone/cuba_openmp
Example synapses/STDP
Example synapses/jeffress
Example synapses/licklider