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.CodeRunnerRecord values of state variables during a run
To extract recorded values after a run, use the
tattribute 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)), whereindicesare the array indices which were recorded. When indexing theStateMonitordirectly, 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]].vwill 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 :
GroupWhich object to record values from.
variables : str, sequence of str, True
Which variables to record, or
Trueto 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
clockargument.clock :
Clock, optionalThe update clock to be used. If neither a clock, nor the
dtargument 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
CodeObjectclass 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 thewhenkeyword to a different value if this is not what you want.Note that
record=Trueonly 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
recordThe array of recorded indices record_variablesThe 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
StateMonitorwill not record the last simulated values since itswhenattribute 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
StateMonitorhas been already run, but a run with a length of0*msdoes 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) >>> print((np.array_str(mon.v[:], precision=3))) [[ 1. 0.98 0.961 0.942 0.923]] >>> print((mon.t[:])) [ 0. 100. 200. 300. 400.] us >>> print((np.array_str(G.v[:], precision=3))) # last value had not been recorded [ 0.905] >>> mon.record_single_timestep() >>> print((mon.t[:])) [ 0. 100. 200. 300. 400. 500.] us >>> print((np.array_str(mon.v[:], precision=3))) [[ 1. 0.98 0.961 0.942 0.923 0.905]]
-
Tutorials and examples using this¶
- Tutorial 2-intro-to-brian-synapses
- Tutorial 1-intro-to-brian-neurons
- Tutorial 3-intro-to-brian-simulations
- Example phase_locking
- Example COBAHH
- Example adaptive_threshold
- Example compartmental/lfp
- Example compartmental/bipolar_with_inputs
- Example compartmental/hodgkin_huxley_1952
- Example compartmental/bipolar_with_inputs2
- Example compartmental/bipolar_cell
- Example compartmental/hh_with_spikes
- Example compartmental/spike_initiation
- Example compartmental/infinite_cable
- Example synapses/STDP
- Example synapses/nonlinear
- Example synapses/gapjunctions
- Example synapses/synapses
- Example synapses/jeffress
- Example frompapers/Platkiewicz_Brette_2011
- Example frompapers/Clopath_et_al_2010_homeostasis
- Example frompapers/Rossant_et_al_2011bis
- Example frompapers/Morris_Lecar_1981
- Example frompapers/Rothman_Manis_2003
- Example frompapers/Hindmarsh_Rose_1984
- Example frompapers/Izhikevich_2007
- Example frompapers/Touboul_Brette_2008
- Example frompapers/Brette_Gerstner_2005
- Example frompapers/Brette_Guigon_2003
- Example frompapers/Wang_Buszaki_1996
- Example frompapers/Destexhe_et_al_1998
- Example frompapers/Brette_2012/Fig1
- Example frompapers/Brette_2012/Fig4
- Example frompapers/Brette_2012/Fig3CF
- Example frompapers/Brette_2012/Fig5A
- Example frompapers/Brette_2012/Fig3AB
- Example frompapers/Stimberg_et_al_2018/example_4_synrel
- Example frompapers/Stimberg_et_al_2018/example_4_rsmean
- Example frompapers/Stimberg_et_al_2018/example_2_gchi_astrocyte
- 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_5_astro_ring
- Example standalone/STDP_standalone
- Example advanced/stochastic_odes
- Example advanced/compare_GSL_to_conventional
- Example advanced/custom_events