~ubuntu-branches/ubuntu/precise/brian/precise

« back to all changes in this revision

Viewing changes to tutorials/tutorial1_basic_concepts/tutorial_1g_recording_membrane_potentials.py

  • Committer: Bazaar Package Importer
  • Author(s): Yaroslav Halchenko
  • Date: 2010-11-02 18:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20101102181915-ivwy29820copccu2
Tags: upstream-1.2.2~svn2229
ImportĀ upstreamĀ versionĀ 1.2.2~svn2229

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Tutorial 1g: Recording membrane potentials
 
3
******************************************
 
4
 
 
5
In the previous part of this tutorial, we plotted a raster plot of
 
6
the firing times of the network. In this tutorial, we introduce
 
7
a way to record the value of the membrane potential for a neuron
 
8
during the simulation, and plot it. We continue as before:
 
9
'''
 
10
from brian import *
 
11
 
 
12
tau = 20 * msecond        # membrane time constant
 
13
Vt = -50 * mvolt          # spike threshold
 
14
Vr = -60 * mvolt          # reset value
 
15
El = -49 * mvolt          # resting potential (same as the reset)
 
16
psp = 0.5 * mvolt         # postsynaptic potential size
 
17
 
 
18
G = NeuronGroup(N=40, model='dV/dt = -(V-El)/tau : volt',
 
19
              threshold=Vt, reset=Vr)
 
20
 
 
21
C = Connection(G, G)
 
22
C.connect_random(sparseness=0.1, weight=psp)
 
23
'''
 
24
This time we won't record the spikes.
 
25
 
 
26
Recording states
 
27
~~~~~~~~~~~~~~~~
 
28
 
 
29
Now we introduce a second type of monitor, the :class:`StateMonitor`.
 
30
The first argument is the group to monitor, and the second is
 
31
the state variable to monitor. The keyword ``record`` can be
 
32
an integer, list or the value ``True``. If it is an integer ``i``,
 
33
the monitor will record the state of the variable for neuron ``i``.
 
34
If it's a list of integers, it will record the states for
 
35
each neuron in the list. If it's set to ``True`` it will record
 
36
for all the neurons in the group.
 
37
'''
 
38
M = StateMonitor(G, 'V', record=0)
 
39
'''
 
40
And then we continue as before:
 
41
'''
 
42
G.V = Vr + rand(40) * (Vt - Vr)
 
43
'''
 
44
But this time we run it for a shorter time so we can look at
 
45
the output in more detail:
 
46
'''
 
47
run(200 * msecond)
 
48
'''
 
49
Having run the simulation, we plot the results using the
 
50
``plot`` command from PyLab which has the same syntax as the Matlab
 
51
:class:`plot`` command, i.e. ``plot(xvals,yvals,...)``. The :class:`StateMonitor`
 
52
monitors the times at which it monitored a value in the
 
53
array ``M.times``, and the values in the array ``M[0]``. The notation
 
54
``M[i]`` means the array of values of the monitored state
 
55
variable for neuron ``i``.
 
56
 
 
57
In the following lines, we scale the times so that they're
 
58
measured in ms and the values so that they're measured in
 
59
mV. We also label the plot using PyLab's ``xlabel``, ``ylabel`` and
 
60
``title`` functions, which again mimic the Matlab equivalents.
 
61
'''
 
62
plot(M.times / ms, M[0] / mV)
 
63
xlabel('Time (in ms)')
 
64
ylabel('Membrane potential (in mV)')
 
65
title('Membrane potential for neuron 0')
 
66
show()
 
67
'''
 
68
.. image:: images/tutorials/1g.jpg
 
69
 
 
70
You can clearly see the leaky integration exponential decay
 
71
toward the resting potential, as well as the jumps when a
 
72
spike was received.
 
73
'''