File: examples-misc_timed_array.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (63 lines) | stat: -rw-r--r-- 1,309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; plot
   pair: example usage; run
   pair: example usage; TimedArray
   pair: example usage; clip
   pair: example usage; show
   pair: example usage; linspace
   pair: example usage; ylabel
   pair: example usage; MultiStateMonitor
   pair: example usage; NeuronGroup
   pair: example usage; sin

.. _example-misc_timed_array:

Example: timed_array (misc)
===========================

An example of the :class:`TimedArray` class used for applying input currents
to neurons.

::

    from brian import *
    
    N = 5
    duration = 100 * ms
    Vr = -60 * mV
    Vt = -50 * mV
    tau = 10 * ms
    Rmin = 1 * Mohm
    Rmax = 10 * Mohm
    freq = 50 * Hz
    k = 10 * nA
    
    eqs = '''
    dV/dt = (-(V-Vr)+R*I)/tau : volt
    R : ohm
    I : amp
    '''
    
    G = NeuronGroup(N, eqs, reset='V=Vr', threshold='V>Vt')
    G.R = linspace(Rmin, Rmax, N)
    
    t = linspace(0 * second, duration, int(duration / defaultclock.dt))
    I = clip(k * sin(2 * pi * freq * t), 0, Inf)
    G.I = TimedArray(I)
    
    M = MultiStateMonitor(G, record=True)
    
    run(duration)
    
    subplot(211)
    M['I'].plot()
    ylabel('I (amp)')
    subplot(212)
    M['V'].plot()
    ylabel('V (volt)')
    show()