-
Notifications
You must be signed in to change notification settings - Fork 0
/
fig_rebound_vis.py
119 lines (90 loc) · 3.23 KB
/
fig_rebound_vis.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
from plots import Plot, VPlot
from pynwb import NWBHDF5IO
import rebound_analysis
import numpy as np
class Bar(Plot):
def __init__(self, ax, markersize=7.5, linewidth=2, markeredgecolor='black', markeredgewidth=2, labelsize=10, fontweight='normal', xlabel='Hyperpolarized Voltage Deflection (mV)', ylabel='# AP'):
super(Bar, self).__init__(ax,
markersize=markersize,
linewidth=linewidth,
markeredgecolor=markeredgecolor,
markeredgewidth=markeredgewidth,
labelsize=labelsize,
fontweight=fontweight,
xlabel=xlabel,
ylabel=ylabel,
legend=True)
self.ax.set_ylim([0,5])
self.ax.set_xlim([-2,10])
self.ax.set_yticks(np.arange(1, 6, 2).tolist())
self.ax.set_xticks(np.arange(0, 12, 4).tolist())
def _format_plot(self):
super(Bar, self)._format_plot()
self.ax.legend(prop={'weight' : self.fontweight, 'size' : self.labelsize}, loc=2, frameon=False, bbox_to_anchor=(0,1.5))
def plot(self, x, y, yerr, label='', color='black'): #, xlabels=[]):
self.ax.bar(
x,
y,
yerr=yerr,
color=color,
linewidth =self.linewidth,
edgecolor='black',
width=1,
label=label
)
#self.ax.set_xticks([0,4,8])
#self.ax.set_xticklabels(['0-20','40-60','60-80'])
self._format_plot()
def plot_vm_curve(ax, current, stim_start=5000, stim_end=7000, xlim=[5000-100, 7500], key='control', color='black', highlight=None, durs=[200,500,2000], title=''):
io = NWBHDF5IO('rebound.nwb', 'r')
nwbfile = io.read()
_rb_plot = VPlot(ax)
_rb_plot.ax.set_ylim([-110,30])
_rb_plot.ax.set_title(title, fontsize=10, fontweight='normal', loc='left')
for dur in durs:
trace = rebound_analysis.analysis.read_trace(nwbfile, "%s_%g_%g" % (key, current, dur), stim_start=stim_start, stim_end=stim_end)
_rb_plot.plot(trace['T'], trace['V'], xlim=xlim, color=color)
if highlight:
dur, t_init, t_end, color = highlight
trace = rebound_analysis.analysis.read_trace(nwbfile, "%s_%g_%g" % (key, current, dur), stim_start=stim_start, stim_end=stim_end)
t = np.array(trace['T'])
v = np.array(trace['V'])
idx = np.logical_and(t >= t_init, t < t_end)
t = t[idx]
v = v[idx]
_rb_plot.plot(t, v, color=color)
io.close()
def plot_spk_hist(ax, dur, shift=0, multiplier=1, ii=np.arange(0.05, 0.55, 0.05), key='control', stim_start=7000, stim_end=7500, color='black', xlabel=True, xticks=True, label=''):
io = NWBHDF5IO('rebound.nwb', 'r')
nwbfile = io.read()
# read the data
hist = rebound_analysis.get_avg_spk(
rebound_analysis.get_rebound_spk(
nwbfile,
key+"_%g",
ii
)
)
xlabels = []
bb = Bar(ax, xlabel=('Hyperpolarized Voltage Deflection (mV)' if xlabel else ''))
if not xticks:
bb.ax.set_xticks([])
xx = []
yy = []
yyerr = []
for i, entry in enumerate(hist[dur].items()):
dd = entry[0]
mean = entry[1][0]
std = entry[1][1]
xx.append(i*multiplier+shift)
yy.append(mean)
yyerr.append(std)
xlabels.append('%g-%g'%(abs(dd[1]), abs(dd[0])))
if xlabel:
bb.ax.set_xticklabels(xlabels)
bb.plot(xx, yy, yyerr, color=color, label=label)
print (key)
print ('\t',xx)
print ('\t',yy)
print ('\t',yyerr)
io.close()