-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.py
142 lines (131 loc) · 4.25 KB
/
analyze.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pickle as pkl
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from cfg import cfg
fptr = "%s/%s.pkl" %(cfg.saveFolder, cfg.simLabel)
fptr = open("data/sim.pkl", "rb")
pkld = pkl.load(fptr)
fptr.close()
net = pkld['net']
sim = pkld['simData']
voltage = {}
current = {}
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val']
id = cell.gid
if cell['tags']['cellType']['stim'] == 'i':
spikes = 0
for spkid in sim['spkid']:
if id == spkid:
spikes = spikes + 1
model = cell['tags']['cellType']['model']
if model in current:
current[model].append([ stim, spikes ])
else:
current[model] = [[ stim, spikes ]]
except:
pass
plt.title("# spikes")
for model in current:
x, y = zip(*current[model])
plt.plot( x, y, label=model)
plt.legend()
plt.xlabel("current")
plt.ylabel("# spikes")
plt.show()
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val'] - 70
id = cell.gid
if cell['tags']['cellType']['stim'] == 'v':
trace = np.array( sim['NaV1.7']['cell_%i' %(id)] )
peak = trace.min()
model = "%s:%s" %( cell['tags']['cellType']['model'], 'NaV1.7' )
if model in voltage:
voltage[model].append([ stim, peak ])
else:
voltage[model] = [[ stim, peak ]]
except:
pass
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val'] - 70
id = cell.gid
if cell['tags']['cellType']['stim'] == 'v':
trace = np.array( sim['NaV1.8']['cell_%i' %(id)] )
peak = trace.min()
model = "%s:%s" %( cell['tags']['cellType']['model'], 'NaV1.8' )
if model in voltage:
voltage[model].append([ stim, peak ])
else:
voltage[model] = [[ stim, peak ]]
except:
pass
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val'] - 70
id = cell.gid
if cell['tags']['cellType']['stim'] == 'v':
trace = np.array( sim['NaV1.8T']['cell_%i' %(id)] )
peak = trace.min()
model = "%s:%s" %( cell['tags']['cellType']['model'], 'NaV1.8T' )
if model in voltage:
voltage[model].append([ stim, peak ])
else:
voltage[model] = [[ stim, peak ]]
except:
pass
plt.title("NaV peak current")
for model in voltage:
x , y = zip(*voltage[model])
plt.plot( x, y, label=model)
plt.legend()
plt.xlabel("voltage clamp (mV)")
plt.ylabel("peak current (mA/cm2)")
plt.show()
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val'] - 70
id = cell.gid
if cell['tags']['cellType']['stim'] == 'v':
trace = np.array( sim['NaV1.7']['cell_%i' %(id)] )
peak = trace.min()
model = "%s:%s" %( cell['tags']['cellType']['model'], 'NaV1.7' )
if model in voltage:
voltage[model].append([ stim, peak ])
else:
voltage[model] = [[ stim, peak ]]
except:
pass
fig = plt.figure()
fig.suptitle('Voltage Response (AP)')
gs = gridspec.GridSpec(2, 1, hspace=0, wspace=0, figure = fig)
custom = fig.add_subplot(gs[0,0])
mandge = fig.add_subplot(gs[1,0])
t = sim['t']
for cell in net['cells']:
try:
stim = cell['tags']['cellType']['val']
id = cell.gid
if stim in [ 0.2 , 0.24, 0.28, 0.32, 0.36 ]:
if cell['tags']['cellType']['stim'] == 'i':
model = cell['tags']['cellType']['model']
if model == 'customSoma':
trace = np.array( sim['v']['cell_%i' %(id)] )
custom.plot(sim['t'], trace, label = 'custom:%f mA/cm2' %(stim) )
if model == 'mandge':
trace = np.array( sim['v']['cell_%i' %(id)] )
mandge.plot(sim['t'], trace, label = 'mandge:%f mA/cm2' %(stim) )
except:
pass
custom.legend()
mandge.legend()
custom.set_xlim(250,300)
mandge.set_xlim(250,300)
plt.xlabel("time (ms)")
plt.ylabel("voltage (mV)")
plt.show()
#del(net)
#del(sim)