StateMonitor class¶
(Shortest import: from brian2 import StateMonitor)
-
class
brian2.monitors.statemonitor.
StateMonitor
(source, variables, record, dt=None, clock=None, when='start', order=0, name='statemonitor*', codeobj_class=None)[source]¶ Bases:
brian2.groups.group.Group
,brian2.groups.group.CodeRunner
Record values of state variables during a run
To extract recorded values after a run, use the
t
attribute for the array of times at which values were recorded, and variable name attribute for the values. The values will have shape(len(indices), len(t))
, whereindices
are the array indices which were recorded. When indexing theStateMonitor
directly, the returned object can be used to get the recorded values for the specified indices, i.e. the indexing semantic refers to the indices insource
, not to the relative indices of the recorded values. For example, when recording only neurons with even numbers,mon[[0, 2]].v
will return the values for neurons 0 and 2, whereasmon.v[[0, 2]]
will return the values for the first and third recorded neurons, i.e. for neurons 0 and 4.Parameters: source :
Group
Which object to record values from.
variables : str, sequence of str, True
Which variables to record, or
True
to record all variables (note that this may use a great deal of memory).record : bool, sequence of ints
Which indices to record, nothing is recorded for
False
, everything is recorded forTrue
(warning: may use a great deal of memory), or a specified subset of indices.dt :
Quantity
, optionalThe time step to be used for the monitor. Cannot be combined with the
clock
argument.clock :
Clock
, optionalThe update clock to be used. If neither a clock, nor the
dt
argument is specified, the clock of thesource()
will be used.when : str, optional
At which point during a time step the values should be recorded. Defaults to
'start'
.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 0.
name : str, optional
A unique name for the object, otherwise will use
source.name+'statemonitor_0'
, etc.codeobj_class :
CodeObject
, optionalThe
CodeObject
class to create.Notes
Since this monitor by default records in the
'start'
time slot, recordings of the membrane potential in integrate-and-fire models may look unexpected: the recorded membrane potential trace will never be above threshold in an integrate-and-fire model, because the reset statement will have been applied already. Set thewhen
keyword to a different value if this is not what you want.Note that
record=True
only works in runtime mode for synaptic variables. This is because the actual array of indices has to be calculated and this is not possible in standalone mode, where the synapses have not been created yet at this stage. Consider using an explicit array of indices instead, i.e. something likerecord=np.arange(n_synapses)
.Examples
Record all variables, first 5 indices:
eqs = """ dV/dt = (2-V)/(10*ms) : 1 """ threshold = 'V>1' reset = 'V = 0' G = NeuronGroup(100, eqs, threshold=threshold, reset=reset) G.V = rand(len(G)) M = StateMonitor(G, True, record=range(5)) run(100*ms) plot(M.t, M.V.T) show()
Attributes
record
The array of recorded indices record_variables
The variables to record Methods
record_single_timestep
()Records a single time step. reinit
()resize
(new_size)Details
-
record
¶ The array of recorded indices
-
record_variables
¶ The variables to record
-
record_single_timestep
()[source]¶ Records a single time step. Useful for recording the values at the end of the simulation – otherwise a
StateMonitor
will not record the last simulated values since itswhen
attribute defaults to'start'
, i.e. the last recording is at the beginning of the last time step.Notes
This function will only work if the
StateMonitor
has been already run, but a run with a length of0*ms
does suffice.Examples
>>> from brian2 import * >>> G = NeuronGroup(1, 'dv/dt = -v/(5*ms) : 1') >>> G.v = 1 >>> mon = StateMonitor(G, 'v', record=True) >>> run(0.5*ms) >>> mon.v array([[ 1. , 0.98019867, 0.96078944, 0.94176453, 0.92311635]]) >>> mon.t[:] array([ 0., 100., 200., 300., 400.]) * usecond >>> G.v[:] # last value had not been recorded array([ 0.90483742]) >>> mon.record_single_timestep() >>> mon.t[:] array([ 0., 100., 200., 300., 400., 500.]) * usecond >>> mon.v[:] array([[ 1. , 0.98019867, 0.96078944, 0.94176453, 0.92311635, 0.90483742]])
-
Tutorials and examples using this¶
- Tutorial 1-intro-to-brian-neurons
- Tutorial 2-intro-to-brian-synapses
- Tutorial 3-intro-to-brian-simulations
- Example COBAHH
- Example phase_locking
- Example adaptive_threshold
- Example standalone/STDP_standalone
- Example synapses/jeffress
- Example synapses/nonlinear
- Example synapses/gapjunctions
- Example synapses/STDP
- Example synapses/synapses
- Example frompapers/Rothman_Manis_2003
- Example frompapers/Platkiewicz_Brette_2011
- Example frompapers/Destexhe_et_al_1998
- Example frompapers/Brette_Guigon_2003
- Example frompapers/Touboul_Brette_2008
- Example frompapers/Clopath_et_al_2010_homeostasis
- Example frompapers/Wang_Buszaki_1996
- Example frompapers/Brette_Gerstner_2005
- Example frompapers/Rossant_et_al_2011bis
- Example frompapers/Brette_2012/Fig5A
- Example frompapers/Brette_2012/Fig3CF
- Example frompapers/Brette_2012/Fig1
- Example frompapers/Brette_2012/Fig3AB
- Example frompapers/Brette_2012/Fig4
- Example frompapers/Stimberg_et_al_2018/example_4_rsmean
- Example frompapers/Stimberg_et_al_2018/example_3_io_synapse
- Example frompapers/Stimberg_et_al_2018/example_1_COBA
- Example frompapers/Stimberg_et_al_2018/example_4_synrel
- Example frompapers/Stimberg_et_al_2018/example_5_astro_ring
- Example frompapers/Stimberg_et_al_2018/example_2_gchi_astrocyte
- Example compartmental/hh_with_spikes
- Example compartmental/hodgkin_huxley_1952
- Example compartmental/lfp
- Example compartmental/infinite_cable
- Example compartmental/spike_initiation
- Example compartmental/bipolar_with_inputs
- Example compartmental/bipolar_cell
- Example compartmental/bipolar_with_inputs2
- Example advanced/compare_GSL_to_conventional
- Example advanced/custom_events
- Example advanced/stochastic_odes