TimedArray class¶

(Shortest import: from brian2 import TimedArray)

class brian2.input.timedarray.TimedArray(values, dt, name=None)[source]

A function of time built from an array of values. The returned object can be used as a function, including in model equations etc. The resulting function has to be called as funcion_name(t) if the provided value array is one-dimensional and as function_name(t, i) if it is two-dimensional.

Parameters

values : ndarray or Quantity

An array of values providing the values at various points in time. This array can either be one- or two-dimensional. If it is two-dimensional it’s first dimension should be the time.

The time distance between values in the values array.

name : str, optional

A unique name for this object, see Nameable for details. Defaults to '_timedarray*'.

Notes

For time values corresponding to elements outside of the range of values provided, the first respectively last element is returned.

Examples

>>> from brian2 import *
>>> ta = TimedArray([1, 2, 3, 4] * mV, dt=0.1*ms)
>>> print(ta(0.3*ms))
4. mV
>>> G = NeuronGroup(1, 'v = ta(t) : volt')
>>> mon = StateMonitor(G, 'v', record=True)
>>> net = Network(G, mon)
>>> net.run(1*ms)
...
>>> print(mon[0].v)
[ 1.  2.  3.  4.  4.  4.  4.  4.  4.  4.] mV
>>> ta2d = TimedArray([[1, 2], [3, 4], [5, 6]]*mV, dt=0.1*ms)
>>> G = NeuronGroup(4, 'v = ta2d(t, i%2) : volt')
>>> mon = StateMonitor(G, 'v', record=True)
>>> net = Network(G, mon)
>>> net.run(0.2*ms)
...
>>> print(mon.v[:])
[[ 1.  3.]
[ 2.  4.]
[ 1.  3.]
[ 2.  4.]] mV


Attributes

 implementations Container for implementing functions for different targets This container can be extended by other codegeneration targets/devices The key has to be the name of the target, the value is a tuple of functions, the first for a 1d array, the second for a 2d array.

Methods

 Return whether this function (if interpreted as a function of time) should be considered constant over a timestep.

Details

implementations

Container for implementing functions for different targets This container can be extended by other codegeneration targets/devices The key has to be the name of the target, the value is a tuple of functions, the first for a 1d array, the second for a 2d array. The functions have to take three parameters: (values, dt, name), i.e. the array values, their physical dimensions, the dt of the TimedArray, and the name of the TimedArray. The functions have to return a function that takes the owner argument (out of which they can get the context’s dt as owner.clock.dt_) and returns the code.

is_locally_constant(dt)[source]

Return whether this function (if interpreted as a function of time) should be considered constant over a timestep. This is most importantly used by TimedArray so that linear integration can be used. In its standard implementation, always returns False.

Parameters

dt : float

The length of a timestep (without units).

Returns

constant : bool

Whether the results of this function can be considered constant over one timestep of length dt.