-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvr_plot_continuous_data.py
More file actions
217 lines (156 loc) · 9.37 KB
/
vr_plot_continuous_data.py
File metadata and controls
217 lines (156 loc) · 9.37 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import vr_file_utility
import vr_open_ephys_IO
import os
import matplotlib.pylab as plt
import numpy as np
import vr_filter
import vr_plot_utility
import vr_optogenetics
def load_continuous_data(prm, channel):
vr_file_utility.create_folder_structure(prm)
channel_data_all = []
file_path = prm.get_filepath() + '100_CH' + str(channel) + '.continuous' #todo this should bw in params, it is 100 for me, 105 for Tizzy (I don't have _0)
channel_data = vr_open_ephys_IO.get_data_continuous(prm, file_path)
channel_data_all.append(channel_data)
channel_data_all = np.asarray(channel_data_all)
return channel_data_all[:,:]
def plot_continuous_data(prm, channel_data_all, channel):
start_time = 0 # in ms
end_time = (np.array((100,500,1000,5000)))+ start_time # in ms
for t, times in enumerate(end_time):
end_time = times
#plot continuous data
fig = plt.figure(figsize = (14,8))
ax = fig.add_subplot(111)
ax.plot(np.arange(start_time,end_time,(1/30)),channel_data_all[0,(start_time*30):(end_time*30)])
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.locator_params(axis = 'x', nbins=7) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=7) # set number of ticks on y axis
ax.set_xlabel('Time (ms)', fontsize=18, labelpad = 20)
ax.set_ylabel('Amplitude (uV)', fontsize=18, labelpad = 20)
vr_plot_utility.adjust_spines(ax, ['left','bottom'])
vr_plot_utility.adjust_spine_thickness(ax)
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.15, right = 0.92, top = 0.92)
fig.savefig(prm.get_filepath() + 'Electrophysiology/continuous/raw/CH' + str(channel) + '_' + str(end_time) + 'ms.png', dpi=200)
plt.close()
def plot_continuous_filtered_data(prm, channel_data_all, channel):
start_time = 0 # in ms
end_time = (np.array((25,50,100,500,1000,5000)))+ start_time # in ms
for t, times in enumerate(end_time):
end_time = times
#plot continuous data
fig = plt.figure(figsize = (14,8))
ax = fig.add_subplot(111)
ax.plot(np.arange(start_time,end_time,(1/30)),channel_data_all[0,(start_time*30):(end_time*30)])
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.locator_params(axis = 'x', nbins=7) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=7) # set number of ticks on y axis
ax.set_xlabel('Time (ms)', fontsize=18, labelpad = 20)
ax.set_ylabel('Amplitude (uV)', fontsize=18, labelpad = 20)
vr_plot_utility.adjust_spines(ax, ['left','bottom'])
vr_plot_utility.adjust_spine_thickness(ax)
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.15, right = 0.92, top = 0.92)
fig.savefig(prm.get_filepath() + 'Electrophysiology/continuous/raw/CH' + str(channel) + '_' + str(end_time) + 'ms_filtered.png', dpi=200)
plt.close()
def load_reference_channel(prm, channel):
#load .txt that tells us which channel is used as reference for the current channel
array = np.loadtxt(prm.get_filepath() + 'ref.txt')
channel_reference = int(array[channel])
#load continuous data from reference channel
referenced_data_all = []
reference = prm.get_filepath() + '100_CH' + str(channel_reference) + '.continuous' #todo this should bw in params, it is 100 for me, 105 for Tizzy (I don't have _0)
referenced_data = vr_open_ephys_IO.get_data_continuous(prm, reference)
referenced_data_all.append(referenced_data)
referenced_data_all = np.asarray(referenced_data_all)
return referenced_data_all # just first 3 seconds
def reference_channel(channel_data_all, referenced_data_all):
referenced = []
for p, point in enumerate(channel_data_all[0,:]):
referenced_value = channel_data_all[0,p] - referenced_data_all[0,p]
referenced = np.append(referenced,referenced_value)
referenced = np.asarray(referenced)
return referenced
def plot_referenced_data(prm, channel_data_all, channel):
start_time = 0 # in ms
end_time = (np.array((25,50,100,500,1000)))+ start_time # in ms
for t, times in enumerate(end_time):
end_time = times
#plot continuous data
fig = plt.figure(figsize = (14,8))
ax = fig.add_subplot(111)
ax.plot(np.arange(start_time,end_time,(1/30)),channel_data_all[(start_time*30):(end_time*30)])
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.locator_params(axis = 'x', nbins=7) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=7) # set number of ticks on y axis
ax.set_xlabel('Time (ms)', fontsize=18, labelpad = 20)
ax.set_ylabel('Amplitude (uV)', fontsize=18, labelpad = 20)
vr_plot_utility.adjust_spines(ax, ['left','bottom'])
vr_plot_utility.adjust_spine_thickness(ax)
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.15, right = 0.92, top = 0.92)
fig.savefig(prm.get_filepath() + 'Electrophysiology/continuous/referenced/CH' + str(channel) + '_' + str(end_time) + 'ms.png', dpi=200)
plt.close()
def plot_referenced_filtered_data(prm, channel_data_all, channel):
start_time = 0 # in ms
end_time = (np.array((25,50,100,500,1000)))+ start_time # in ms
for t, times in enumerate(end_time):
end_time = times
#plot continuous data
fig = plt.figure(figsize = (14,8))
ax = fig.add_subplot(111)
ax.plot(np.arange(start_time,end_time,(1/30)),channel_data_all[(start_time*30):(end_time*30)])
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.locator_params(axis = 'x', nbins=7) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=7) # set number of ticks on y axis
ax.set_xlabel('Time (ms)', fontsize=18, labelpad = 20)
ax.set_ylabel('Amplitude (uV)', fontsize=18, labelpad = 20)
vr_plot_utility.adjust_spines(ax, ['left','bottom'])
vr_plot_utility.adjust_spine_thickness(ax)
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.15, right = 0.92, top = 0.92)
fig.savefig(prm.get_filepath() + 'Electrophysiology/continuous/referenced/CH' + str(channel) + '_' + str(end_time) + 'ms_filtered.png', dpi=200)
plt.close()
def load_and_plot_continuous_raw(prm):
for c, channel in enumerate(np.arange(1,16,1)):
#load continuous data
channel_data_all = load_continuous_data(prm, channel)
#plot
plot_continuous_data(prm, channel_data_all, channel)
#filter
filtered_data_all = vr_filter.custom_filter(channel_data_all, 300, 6000, 30000, color='k')
#plot filtered data
plot_continuous_filtered_data(prm, filtered_data_all, channel)
#print('continuous raw data analysed and plotted')
def load_and_plot_continuous_referenced(prm):
for c, channel in enumerate(np.arange(1,16,1)):
#load continuous data
channel_data_all = load_continuous_data(prm, channel)
#load reference channel
referenced_data_all = load_reference_channel(prm, channel)
#reference the channel
channel_data_all = reference_channel(channel_data_all[:,0:150000], referenced_data_all)
#plot referenced data
plot_referenced_data(prm, channel_data_all, channel)
#filter referenced data
filtered_data_all = vr_filter.custom_filter(channel_data_all, 600, 6000, 30000, color='k')
#plot filtered referenced data
plot_referenced_filtered_data(prm, filtered_data_all, channel)
#print('continuous referenced data analysed and plotted')
def plot_continuous_opto(prm, channel_data_all,channel, light,nolight,theta, gamma,channel_data_all_spikes):
light_ch,no_light_ch = vr_optogenetics.split_light_and_no_light_channel(prm, channel_data_all, channel, light,nolight,theta, gamma,channel_data_all_spikes)
light = np.hstack((light,light_ch))
#light = np.take((light, np.where(light[:,4] > 0.7)))
nolight = np.hstack((nolight,no_light_ch))
#nolight = np.take((nolight, np.where(nolight[:,4] > 0.7)))
#plot
#vr_optogenetics.plot_all_opto_data(prm, light, channel, 1)
#vr_optogenetics.plot_all_opto_data(prm, nolight, channel, 2)
vr_optogenetics.plot_continuous_opto_trials(prm, light, channel, 1)
vr_optogenetics.plot_continuous_opto_trials(prm, nolight, channel, 2)
#vr_optogenetics.plot_continuous_opto_data(prm, light, channel, 1,)
#vr_optogenetics.plot_continuous_opto_data(prm, nolight, channel, 2)
#plot filtered data
#plot_continuous_filtered_data(prm, channel_data_all, channel)
#print('continuous raw data analysed and plotted')