File: examples-electrophysiology_compensation_ex1.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 (54 lines) | stat: -rw-r--r-- 1,447 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
.. currentmodule:: brian

.. index::
   pair: example usage; load
   pair: example usage; plot
   pair: example usage; subplot
   pair: example usage; linspace
   pair: example usage; show

.. _example-electrophysiology_compensation_ex1:

Example: compensation_ex1 (electrophysiology)
=============================================

Example of L^p electrode compensation method. Requires binary files 
"current.npy" and "rawtrace.npy".

    Rossant et al., "A calibration-free electrode compensation method"
    J. Neurophysiol 2012

::

    import os
    
    from brian import *
    import numpy as np
    from brian.library.electrophysiology import *
    
    working_dir = os.path.dirname(__file__)
    
    # load data
    dt = 0.1*ms
    current = np.load(os.path.join(working_dir, "current.npy"))  # 10000-long vector, 1s duration
    rawtrace = np.load(os.path.join(working_dir, "trace.npy"))  # 10000-long vector, 1s duration
    t = linspace(0., 1., len(current))
    
    # launch compensation
    r = Lp_compensate(current, rawtrace, dt, p=1.0, full=True)
    
    # print best parameters
    print "Best parameters: R, tau, Vr, Re, taue:"
    print r["params"]
    
    # plot traces
    subplot(211)
    plot(t, current, 'k')
    
    subplot(212)
    plot(t, rawtrace, 'k')  # raw trace
    plot(t, r["Vfull"], 'b')  # full model trace (neuron and electrode)
    plot(t, r["Vcompensated"], 'g')  # compensated trace
    
    show()