File: tutorial_1g_recording_membrane_potentials.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 (83 lines) | stat: -rw-r--r-- 2,735 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
.. currentmodule:: brian

Tutorial 1g: Recording membrane potentials
******************************************

In the previous part of this tutorial, we plotted a raster plot of
the firing times of the network. In this tutorial, we introduce
a way to record the value of the membrane potential for a neuron
during the simulation, and plot it. We continue as before:

  ::

    from brian import *
    
    tau = 20 * msecond        # membrane time constant
    Vt = -50 * mvolt          # spike threshold
    Vr = -60 * mvolt          # reset value
    El = -49 * mvolt          # resting potential (same as the reset)
    psp = 0.5 * mvolt         # postsynaptic potential size
    
    G = NeuronGroup(N=40, model='dV/dt = -(V-El)/tau : volt',
                  threshold=Vt, reset=Vr)
    
    C = Connection(G, G)
    C.connect_random(sparseness=0.1, weight=psp)

This time we won't record the spikes.

Recording states
~~~~~~~~~~~~~~~~

Now we introduce a second type of monitor, the :class:`StateMonitor`.
The first argument is the group to monitor, and the second is
the state variable to monitor. The keyword ``record`` can be
an integer, list or the value ``True``. If it is an integer ``i``,
the monitor will record the state of the variable for neuron ``i``.
If it's a list of integers, it will record the states for
each neuron in the list. If it's set to ``True`` it will record
for all the neurons in the group.

  ::

    M = StateMonitor(G, 'V', record=0)

And then we continue as before:

  ::

    G.V = Vr + rand(40) * (Vt - Vr)

But this time we run it for a shorter time so we can look at
the output in more detail:

  ::

    run(200 * msecond)

Having run the simulation, we plot the results using the
``plot`` command from PyLab which has the same syntax as the Matlab
:class:`plot`` command, i.e. ``plot(xvals,yvals,...)``. The :class:`StateMonitor`
monitors the times at which it monitored a value in the
array ``M.times``, and the values in the array ``M[0]``. The notation
``M[i]`` means the array of values of the monitored state
variable for neuron ``i``.

In the following lines, we scale the times so that they're
measured in ms and the values so that they're measured in
mV. We also label the plot using PyLab's ``xlabel``, ``ylabel`` and
``title`` functions, which again mimic the Matlab equivalents.

  ::

    plot(M.times / ms, M[0] / mV)
    xlabel('Time (in ms)')
    ylabel('Membrane potential (in mV)')
    title('Membrane potential for neuron 0')
    show()

.. image:: images/tutorials/1g.jpg

You can clearly see the leaky integration exponential decay
toward the resting potential, as well as the jumps when a
spike was received.