EventMonitor class¶
(Shortest import: from brian2 import EventMonitor)
- class brian2.monitors.spikemonitor.EventMonitor(*args, **kw)[source]¶
Bases:
brian2.groups.group.Group
,brian2.groups.group.CodeRunner
Record events from a
NeuronGroup
or another event source.The recorded events can be accessed in various ways: the attributes
i
andt
store all the indices and event times, respectively. Alternatively, you can get a dictionary mapping neuron indices to event trains, by calling theevent_trains
method.- Parameters
source :
NeuronGroup
,SpikeSource
The source of events to record.
event : str
The name of the event to record
variables : str or sequence of str, optional
Which variables to record at the time of the event (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 event 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.
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+'_eventmonitor_0'
, etc.codeobj_class : class, optional
The
CodeObject
class to run code with.
See also
Attributes
The array of event counts (length = size of target group)
The event that we are listening to
Returns the pair (
i
,t
).Returns the pair (
i
,t_
).Returns the total number of recorded events.
Whether to record times and indices of events
The additional variables that will be recorded
The source we are recording from
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 events (sorted by time).Return a dictionary mapping event indices to arrays of event times.
reinit
()Clears all recorded spikes
resize
(new_size)values
(var)Return a dictionary mapping neuron indices to arrays of variable values at the time of the events (sorted by time).
Details
- count¶
The array of event counts (length = size of target group)
- event¶
The event that we are listening to
- it¶
Returns the pair (
i
,t
).
- it_¶
Returns the pair (
i
,t_
).
- num_events¶
Returns the total number of recorded events.
- record¶
Whether to record times and indices of events
- record_variables¶
The additional variables that will be recorded
- source¶
The source we are recording from
- 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 events (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 events.
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 = EventMonitor(G, event='spike', 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
- event_trains()[source]¶
Return a dictionary mapping event indices to arrays of event times. Equivalent to calling
values('t')
.- Returns
event_trains : dict
Dictionary that stores an array with the event times for each neuron index.
See also
- values(var)[source]¶
Return a dictionary mapping neuron indices to arrays of variable values at the time of the events (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 events
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 = EventMonitor(G, event='spike', 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¶
Example advanced/custom_events