EventMonitor class

(Shortest import: from brian2 import EventMonitor)

class brian2.monitors.spikemonitor.EventMonitor(source, event, variables=None, when=None, order=None, name='eventmonitor*', codeobj_class=None)[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 and t store all the indices and event times, respectively. Alternatively, you can get a dictionary mapping neuron indices to event trains, by calling the event_trains method.

Parameters:

source : NeuronGroup

The source of events to record.

record : bool

Whether or not to record each event in i and t (the count will always be recorded).

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.

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

SpikeMonitor

Attributes

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_variables The additional variables that will be recorded
source The source we are recording from

Methods

all_values() 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).
event_trains() 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

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_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) calling values 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, """dv/dt = 100*Hz : 1
...                       v_th : 1""", threshold='v>v_th', reset='v=0')
>>> G.v_th = [0.5, 1]
>>> mon = EventMonitor(G, event='spike', variables='v')
>>> run(20*ms)
>>> all_values = mon.all_values()
>>> all_values['t'][0]
array([  4.9,   9.9,  14.9,  19.9]) * msecond
>>> all_values['v'][0]
array([ 0.5,  0.5,  0.5,  0.5])
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.

reinit()[source]

Clears all recorded spikes

resize(new_size)[source]
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, """dv/dt = 100*Hz : 1
...                       v_th : 1""", threshold='v>v_th', reset='v=0')
>>> G.v_th = [0.5, 1]
>>> mon = EventMonitor(G, event='spike', variables='v')
>>> run(20*ms)
>>> v_values = mon.values('v')
>>> v_values[0]
array([ 0.5,  0.5,  0.5,  0.5])
>>> v_values[1]
array([ 1.,  1.])