-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_triggered_ephys.py
411 lines (280 loc) · 17.1 KB
/
event_triggered_ephys.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import os
import numpy as np
from analysis import *
class EventTriggeredEphys(QtGui.QWidget):
def __init__(self, parent):
super(EventTriggeredEphys, self).__init__(parent)
self.parent = parent
layout = QtGui.QGridLayout()
#Default: july 11, 2016 experiment
self.parent.root_dir = '/media/cat/12TB/in_vivo/tim/cat/'
#self.parent.root_dir = '/media/cat/500GB/in_vivo/tim/cat/'
self.parent.n_sec = 3
self.selected_recording = '/media/cat/12TB/in_vivo/tim/cat/2017_04_19_visual_ephys/track1/LED_flash_60_100ms_3sec_170419_145514_lfp_250hz.tsf'
self.selected_sort = '/media/cat/12TB/in_vivo/tim/cat/2017_04_19_visual_ephys/track1/LED_flash_60_100ms_3sec_170419_145514_lfp_250hz_rec0_digch0_ontimes.txt'
row_index = 0 #Keep track of button/box row
#**************************************************************************************
#******************************** SELECT ANIMAL & SESSION *****************************
#**************************************************************************************
self.vid_analysis_lbl = QLabel('EVENT TRIGGERED EPHYS', self)
self.vid_analysis_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.vid_analysis_lbl.setStyleSheet('color: blue')
layout.addWidget(self.vid_analysis_lbl, row_index, 0); row_index+=1
#Select recording
self.button_select_recording = QPushButton('Select Recording')
self.button_select_recording.setMaximumWidth(200)
self.button_select_recording.clicked.connect(self.slct_recording1)
layout.addWidget(self.button_select_recording, row_index, 0)
#self.parent.selected_recording = os.getcwd()
self.selected_recording = self.selected_recording
self.select_recording_lbl = QLabel(os.path.split(self.selected_recording)[1], self)
layout.addWidget(self.select_recording_lbl, row_index,1); row_index+=1
#Select recording
self.button_select_sort = QPushButton('Select Event File')
self.button_select_sort.setMaximumWidth(200)
self.button_select_sort.clicked.connect(self.slct_event_file)
layout.addWidget(self.button_select_sort, row_index, 0)
self.selected_sort = self.selected_sort
self.select_sort_lbl = QLabel(os.path.split(self.selected_sort)[1], self)
layout.addWidget(self.select_sort_lbl, row_index,1)
selected_unit_lbl = QLabel('Unit #:', self)
layout.addWidget(selected_unit_lbl, row_index, 5)
#self.filter_list = ['nofilter', 'butterworth', 'chebyshev']
self.comboBox_selected_unit = QtGui.QComboBox(self)
self.comboBox_selected_unit.addItem('')
layout.addWidget(self.comboBox_selected_unit, row_index, 6)
self.comboBox_selected_unit.activated[str].connect(self.slct_unit); self.selected_filter = "" #Set default
self.selected_unit_spikes_lbl = QLabel('', self)
layout.addWidget(self.selected_unit_spikes_lbl, row_index, 7)
for k in range(2): layout.addWidget(QLabel(' '*40, self), row_index,0); row_index+=1
#**************************************************************************************
#***************************** PRE-PROCESSING HEADER **********************************
#**************************************************************************************
self.preprocess_lbl = QLabel('PRE-PROCESSING', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
self.button2 = QPushButton('Filter ==>')
self.button2.setMaximumWidth(200)
self.button2.clicked.connect(self.fltr_npy)
layout.addWidget(self.button2, row_index, 0)
self.filter_list = ['butterworth', 'chebyshev']
self.comboBox_filter = QtGui.QComboBox(self)
for filter_ in self.filter_list[1:]: self.comboBox_filter.addItem(filter_)
layout.addWidget(self.comboBox_filter, row_index, 1)
self.comboBox_filter.activated[str].connect(self.slct_filter); self.selected_filter = "butterworth" #Set default
self.lowcut = QLineEdit('0.1')
self.lowcut.setMaximumWidth(50)
lowcut_lbl = QLabel('Low Cutoff (HZ):', self)
layout.addWidget(lowcut_lbl, row_index, 2)
layout.addWidget(self.lowcut, row_index, 3)
self.highcut = QLineEdit('6.0')
self.highcut.setMaximumWidth(50)
highcut_lbl = QLabel('High Cutoff (HZ):', self)
layout.addWidget(highcut_lbl, row_index, 4)
layout.addWidget(self.highcut, row_index, 5); row_index+=1
#**************************************************************************************
#******************************** COMPUTE AVERAGES ***********************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.preprocess_lbl = QLabel('EVENT TRIGGERED AVERAGES', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
row_index+=1
self.button_lfp_template = QPushButton('LFP Template')
self.button_lfp_template.setMaximumWidth(200)
self.button_lfp_template.clicked.connect(self.lfp_avg)
layout.addWidget(self.button_lfp_template, row_index, 0)
self.excluded_trials = QLineEdit(''); #parent.start_time = self.start_time
self.excluded_trials.setMaximumWidth(100)
self.excluded_trials_lbl = QLabel('Excluded Trials:', self)
self.excluded_trials_lbl.setMaximumWidth(100)
layout.addWidget(self.excluded_trials_lbl, row_index,3)
layout.addWidget(self.excluded_trials, row_index, 4)
self.n_sample_pts = QLineEdit('100'); #parent.start_time = self.start_time
self.n_sample_pts.setMaximumWidth(50)
self.n_sample_pts_lbl = QLabel('#Sample Pts:', self)
self.n_sample_pts_lbl.setMaximumWidth(100)
layout.addWidget(self.n_sample_pts_lbl, row_index,5)
layout.addWidget(self.n_sample_pts, row_index, 6)
self.voltage_scale = QLineEdit('10.0'); #parent.end_time = self.end_time
self.voltage_scale.setMaximumWidth(50)
self.voltage_scale_lbl = QLabel('Voltage Scaling', self)
self.voltage_scale_lbl.setMaximumWidth(150)
layout.addWidget(self.voltage_scale_lbl, row_index, 7)
layout.addWidget(self.voltage_scale, row_index,8); row_index+=1
self.button31 = QPushButton('CSD')
self.button31.setMaximumWidth(200)
self.button31.clicked.connect(self.csd_avg)
layout.addWidget(self.button31, row_index, 0)
self.top_channel = QLineEdit('0');
self.top_channel.setMaximumWidth(50)
self.top_channel_lbl = QLabel('Top Ch:', self)
self.top_channel_lbl.setMaximumWidth(100)
layout.addWidget(self.top_channel_lbl, row_index,3)
layout.addWidget(self.top_channel, row_index, 4)
self.bottom_channel = QLineEdit('64');
self.bottom_channel.setMaximumWidth(50)
self.bottom_channel_lbl = QLabel('Bottom Ch:', self)
self.bottom_channel_lbl.setMaximumWidth(100)
layout.addWidget(self.bottom_channel_lbl, row_index,5)
layout.addWidget(self.bottom_channel, row_index, 6); row_index+=1
self.button31 = QPushButton('Single Unit Histogram')
self.button31.setMaximumWidth(200)
self.button31.clicked.connect(self.static_stm_mouse_lever)
layout.addWidget(self.button31, row_index, 0); row_index+=1
#self.block_save = QLineEdit('10')
#self.block_save.setMaximumWidth(50)
#self.block_save_lbl = QLabel('Block Ave & Mid-Mask Pixels:', self)
#layout.addWidget(self.block_save_lbl, row_index,4)
#layout.addWidget(self.block_save, row_index,5)
#self.midline_mask = QLineEdit('5')
#self.midline_mask.setMaximumWidth(50)
#layout.addWidget(self.midline_mask, row_index,6); row_index+=1
#**************************************************************************************
#******************************** MULTI CSD MAPPING ***********************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.preprocess_lbl = QLabel('MULTI-ANIMAL CSD MAPPING', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
#Select recording
self.button_select_recording = QPushButton('Select Recordings')
self.button_select_recording.setMaximumWidth(200)
self.button_select_recording.clicked.connect(self.csd_all_pickfiles)
layout.addWidget(self.button_select_recording, row_index, 0)
#self.parent.selected_recording = os.getcwd()
self.select_recording_lbl2 = QLabel('', self)
layout.addWidget(self.select_recording_lbl2, row_index,1); row_index+=1
self.multi_csd = QPushButton('Multi-file CSD')
self.multi_csd.setMaximumWidth(200)
self.multi_csd.clicked.connect(self.csd_all)
layout.addWidget(self.multi_csd, row_index, 0); row_index+=1
#**************************************************************************************
#******************************** MULTI LEC MAPPING ***********************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.preprocess_lbl = QLabel('MULTI-ANIMAL LFP CLUSTER MAPPING', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
#Select recording
self.LFP_clusters_button_select_recording = QPushButton('Select .tsf Recordings')
self.LFP_clusters_button_select_recording.setMaximumWidth(200)
self.LFP_clusters_button_select_recording.clicked.connect(self.LFP_all_pickfiles)
layout.addWidget(self.LFP_clusters_button_select_recording, row_index, 0)
#self.parent.selected_recording = os.getcwd()
self.select_recording_lbl3 = QLabel('', self)
layout.addWidget(self.select_recording_lbl3, row_index,1); row_index+=1
self.ptcs_clusters_button_select_recording = QPushButton('Select .ptcs Recordings')
self.ptcs_clusters_button_select_recording.setMaximumWidth(200)
self.ptcs_clusters_button_select_recording.clicked.connect(self.ptcs_all_pickfiles)
layout.addWidget(self.ptcs_clusters_button_select_recording, row_index, 0)
#self.parent.selected_recording = os.getcwd()
self.select_recording_lbl4 = QLabel('', self)
layout.addWidget(self.select_recording_lbl4, row_index,1); row_index+=1
self.multi_LEC = QPushButton('Multi-file LECs')
self.multi_LEC.setMaximumWidth(200)
self.multi_LEC.clicked.connect(self.LEC_all)
layout.addWidget(self.multi_LEC, row_index, 0); row_index+=1
self.setLayout(layout)
#***************************************************************************************************************************************
def slct_recording1(self):
self.selected_recording = QtGui.QFileDialog.getOpenFileName(self, ".tsf", self.selected_recording,"(*.tsf)")
path_name, file_name = os.path.split(self.selected_recording)
self.select_recording_lbl.setText(file_name)
def slct_event_file(self):
self.selected_sort = QtGui.QFileDialog.getOpenFileName(self, ".ptcs or .txt or .npy)", self.selected_recording,"PTCS, TXT, NPY (*.ptcs *.txt *.npy)")
path_name, file_name = os.path.split(self.selected_sort)
self.select_sort_lbl.setText(file_name)
#Reload session list and reset session box
self.comboBox_selected_unit.clear()
if '.ptcs' in self.selected_sort:
self.Sort = Ptcs(self.selected_sort)
n_units = len(self.Sort.units)
self.selected_unit_spikes_lbl.setText(str(len(self.Sort.units[0])))
elif '.txt' in self.selected_sort:
n_units = 1
self.triggers = np.loadtxt(self.selected_sort)
self.selected_unit_spikes_lbl.setText(str(len(self.triggers)))
elif '.npy' in self.selected_sort:
n_units = 1
self.camera_pulses = np.load(self.selected_sort)
parse_camera_pulses(self); print "...# of triggers: ", len(self.triggers)
self.selected_unit_spikes_lbl.setText(str(len(self.triggers)))
print self.triggers/25000.
print self.triggers_length/25000.
for unit in range(n_units):
self.comboBox_selected_unit.addItem(str(unit))
self.slct_unit('0')
def slct_unit(self, text):
self.selected_unit = text
if '.ptcs' in self.selected_sort: self.selected_unit_spikes_lbl.setText(str(len(self.Sort.units[int(text)])))
else: self.selected_unit_spikes_lbl.setText(str(len(self.triggers)))
def lfp_avg(self):
self.triggers = np.loadtxt(self.selected_sort) #******************* LFP AVEERAGE
compute_lfp_triggered_template(self)
def csd_avg(self): #**************************** CSD
compute_csd_event_triggered(self)
def LFP_all_pickfiles(self):
self.selected_tsf_files = QtGui.QFileDialog.getOpenFileName(self, ".ptcs or .txt or .npy)", self.selected_recording,"PTCS, TXT, NPY (*.ptcs *.txt *.npy)")
path_name, file_name = os.path.split(self.selected_tsf_files)
self.select_recording_lbl3.setText(file_name)
self.selected_ptcs_files = self.selected_tsf_files.replace('_lfp_', '_ptcs_')
path_name, file_name = os.path.split(self.selected_ptcs_files)
self.select_recording_lbl4.setText(file_name)
def ptcs_all_pickfiles(self):
self.selected_ptcs_files = QtGui.QFileDialog.getOpenFileName(self, ".ptcs or .txt or .npy)", self.selected_recording,"PTCS, TXT, NPY (*.ptcs *.txt *.npy)")
path_name, file_name = os.path.split(self.selected_ptcs_files)
self.select_recording_lbl4.setText(file_name)
def csd_all_pickfiles(self):
self.selected_files = QtGui.QFileDialog.getOpenFileName(self, ".ptcs or .txt or .npy)", self.selected_recording,"PTCS, TXT, NPY (*.ptcs *.txt *.npy)")
path_name, file_name = os.path.split(self.selected_files)
self.select_sort_lbls.setText(file_name)
def csd_all(self): #**************************** MULTI FILE CSD
compute_csd_event_triggered_multi(self)
def LEC_all(self): #**************************** MULTI FILE LECs
compute_LEC_csd_event_triggered_multi(self)
def select_dff_filter(self,text):
self.selected_dff_filter=text
def select_dff_method(self, text):
self.dff_method = text
def static_stm_mouse_lever(self):
view_static_stm_events(self)
def video_stm_mouse_lever(self):
view_video_stm(self)
def bn_to_npy(self):
convert_bin_to_npy(self)
def fltr_npy(self):
filter_for_event_trigger_analysis(self)
def slct_filter(self, text):
self.selected_filter = text
print self.selected_filter
def vw_activity(self):
view_spontaneous_activity(self)
def select_dim_red(self, text):
self.selected_dim_red = text
print text
def st_space(self):
compute_dim_reduction(self)
def plt_distribution(self):
plot_3D_distribution_new(self)
def vw_ave_points(self):
view_ave_points(self)
def vw_all_points(self):
view_all_points(self)
def list_points(self):
print self.parent.glwindow.glWidget.points_selected
def clr_points(self):
self.parent.glwindow.glWidget.points_selected = []
def vid_points(self):
print "...making vid starting at frame: ", self.parent.glwindow.glWidget.points_selected[0]
video_points(self)