def on_pB_select_data_clicked(self): self.ui.label_data_loaded.setText("Loading\nData") self.ui.qled_data_loaded.setOffColour(3) self.ui.qled_data_loaded.setOnColour(3) self.session = QtGui.QFileDialog.getExistingDirectory(parent=None, caption="Select Data Directory") self.ui.cB_trial_start_frames.clear() if os.path.isfile(self.session+self.front_video_path): self.front_video = cv2.VideoCapture(self.session + self.front_video_path) self.adc = tlf.load_raw_data(self.session + self.adc_path, numchannels=8, dtype=np.uint16).dataMatrix self.adc_ss = tlf.subsample_basis_data(self.adc, self.rec_freq, self.ss_freq, 'fir', 29) front_counter = tlf.load_colum_from_csv(self.session + self.front_counter_path, 0) self.corrected_frame_numbers = front_counter - front_counter[0] sync = np.squeeze(tlf.load_raw_data(self.session + self.sync_path, numchannels=1, dtype=np.uint8).dataMatrix) sync_diff = np.diff(sync.astype('int8')) self.cam_shutter_closing_samples = np.squeeze((sync_diff < -0.9).nonzero()) self.ui.qled_data_loaded.setValue(True) self.ui.label_data_loaded.setText("Data\nLoaded") self.ui.qled_data_loaded.setOffColour(1) self.ui.qled_data_loaded.setOnColour(2) self.data_loaded = True analysis_path = os.path.join(self.session, self.analysis_folder) if os.path.exists(analysis_path): # Add the list of good trials to the combobox self.analysis_exists = True session_hdf5 = pd.HDFStore(analysis_path+self.analysis_file_name) trials_start_stop_info = session_hdf5[self.fronttrials_key] start_frames_strlist =np.char.mod('%d', trials_start_stop_info[self.trials_info_start_frame].tolist()) self.ui.cB_trial_start_frames.addItems(start_frames_strlist) if self.paw_events_key in session_hdf5: # Add the lists of paw touch events to their comboboxes paw_events = session_hdf5[self.paw_events_key]; """:type : pd.DataFrame""" self.ui.cB_br_paw_frames.addItems([str(x) for x in paw_events[paw_events[self.brpaw] != -1][self.brpaw]]) self.ui.cB_bl_paw_frames.addItems([str(x) for x in paw_events[paw_events[self.blpaw] != -1][self.blpaw]]) self.ui.cB_fr_paw_frames.addItems([str(x) for x in paw_events[paw_events[self.frpaw] != -1][self.frpaw]]) self.ui.cB_fl_paw_frames.addItems([str(x) for x in paw_events[paw_events[self.flpaw] != -1][self.flpaw]]) if self.good_trials_key in session_hdf5: # Add the list of good_tirls to its combobox good_trials = session_hdf5[self.good_trials_key]; """:type : pd.Series""" self.ui.cB_selected_trials.addItems([str(x) for x in good_trials]) if self.trajectories_key in session_hdf5: trajectories = session_hdf5[self.trajectories_key]; """:type : pd.DataFrame""" self.ui.cB_trajectory_name.addItems(list(set(trajectories[self.name_traj_point].tolist()))) session_hdf5.close() else: self.ui.qled_data_loaded.setValue(False) self.ui.label_data_loaded.setText("No Data\nLoaded") self.ui.qled_data_loaded.setOffColour(1) self.ui.qled_data_loaded.setOnColour(2) self.data_loaded = False
fn_amp = "C:\George\Data\ECoG_Chronic_Recordings\\2014_08_06_Jpak65_Anesthesia_PawStimulation_Electrical\\2014_08_06_JPak65_PawStimulation_BackRight_200uA_2ms_Amp.bin" sampling_freq = 20000 threshold = 10000 filt_cutoff_freq = None minduration = 10 pick_out_or_in = True data_raw_events = tl.load_raw_event_trace(fn_adc, number_of_channels=1, dtype=np.uint16) event_times, event_values = tl.create_piezosensor_events( data_raw_events.dataMatrix, threshold, sampling_freq, filt_cutoff_freq, minduration, pick_out_or_in) data_raw_amp = tl.load_raw_data(fn_amp, 128) sub_tl_data, sub_tl_avg_data, sub_time_axis = tl.time_lock_raw_data( data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], sub_sample_freq=1000) #sub_tl_hp_data, sub_tl_hp_avg_data, sub_time_axis = tl.time_lock_raw_data(data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], high_pass_cutoff=400, rectify=False, sub_sample_freq=1000) #sub_tl_hpr_data, sub_tl_hpr_avg_data, sub_time_axis = tl.time_lock_raw_data(data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], high_pass_cutoff=400, rectify=True, sub_sample_freq=1000) fn_adc2 = "C:\George\Data\ECoG_Chronic_Recordings\\14_06_03_Jpak65_Anesthesia_Stimulations\\14_06_03_stimulation_manual_paw_qtip2\stim.bin" fn_amp2 = "C:\George\Data\ECoG_Chronic_Recordings\\14_06_03_Jpak65_Anesthesia_Stimulations\\14_06_03_stimulation_manual_paw_qtip2\\amplifier.bin" sampling_freq = 8000 threshold = 1e7
threshold = 0.0003 cell_1_data_raw_spikes = tl.load_raw_event_trace(fn_adc_c1, number_of_channels=8, channel_used=0, dtype=np.uint16) cell_1_event_times, cell_1_eventdata_in_V = tl.create_spike_triggered_events( cell_1_data_raw_spikes.dataMatrix, threshold=threshold, inter_spike_time_distance=0.001, amp_gain=1000, sampling_freq=sampling_freq, amp_y_digitization=65536, amp_y_range=10) cell_1_event_times = cell_1_event_times[1:-120] cell_1_data_raw_amp = tl.load_raw_data(fn_amp_c1, 64) cell_1_tl_sub_reref_avg, sub_time_axis = tl.time_lock_raw_data( cell_1_data_raw_amp.dataMatrix, cell_1_event_times, times_to_cut=[-0.2, 0.2], sampling_freq=sampling_freq, baseline_time=[-0.2, -0.05], sub_sample_freq=2000, avg_reref=True, keep_trials=False) x_of_bad_channels = np.array([19, 136, 214, 87, 516]) #For 420 spikes average y_of_bad_channels = np.array([88, 68, 94, -119, 64]) cell_1_tl_sub_reref_avg_nbc, bad_channels_cell_1_tl_sub_reref_avg = bad_channel_removal( x_of_bad_channels, y_of_bad_channels, cell_1_tl_sub_reref_avg)
sampling_freq = 30000 #Cell 1 fn_adc_c1 = "C:\\George\\Data\\ECoG_Juxta_Paired_Recordings\\2014_12_05_Jpak77\\2014_12_05_Jpak77_JuxtaCell1_ADC_Cell1.bin" fn_amp_c1 = "C:\\George\\Data\\ECoG_Juxta_Paired_Recordings\\2014_12_05_Jpak77\\2014_12_05_Jpak77_JuxtaCell1_Amp_Cell1.bin" threshold = 0.0003 cell_1_data_raw_spikes = tl.load_raw_event_trace(fn_adc_c1, number_of_channels=8, channel_used=0, dtype=np.uint16) cell_1_event_times, cell_1_eventdata_in_V = tl.create_spike_triggered_events(cell_1_data_raw_spikes.dataMatrix, threshold = threshold, inter_spike_time_distance=0.001, amp_gain=1000, sampling_freq=sampling_freq, amp_y_digitization=65536, amp_y_range=10) cell_1_event_times = cell_1_event_times[1:-120] cell_1_data_raw_amp = tl.load_raw_data(fn_amp_c1, 64) cell_1_tl_sub_reref_avg, sub_time_axis = tl.time_lock_raw_data(cell_1_data_raw_amp.dataMatrix, cell_1_event_times, times_to_cut=[-0.2, 0.2], sampling_freq=sampling_freq, baseline_time=[-0.2, -0.05], sub_sample_freq=2000, avg_reref = True, keep_trials=False) x_of_bad_channels = np.array([19, 136, 214, 87, 516]) #For 420 spikes average y_of_bad_channels = np.array([88, 68, 94, -119, 64]) cell_1_tl_sub_reref_avg_nbc, bad_channels_cell_1_tl_sub_reref_avg = bad_channel_removal(x_of_bad_channels, y_of_bad_channels, cell_1_tl_sub_reref_avg) pf.plot_video_topoplot(cell_1_tl_sub_reref_avg_nbc, sub_time_axis, pf.grid_layout_64channels(bad_channels_cell_1_tl_sub_reref_avg), times_to_plot = [-0.06, 0.1], time_step = 0.001, sampling_freq = 1000, zlimits = [-60, 60], filename = 'C:\George\Analysis\Jpak77_Juxta\\Cell_1_LFPs.avi') cell_1_tl_reref_avg, time_axis = tl.time_lock_raw_data(cell_1_data_raw_amp.dataMatrix, cell_1_event_times, times_to_cut=[-0.2, 0.2], sampling_freq=sampling_freq, baseline_time=[-0.15, -0.05], sub_sample_freq=None, high_pass_cutoff = None, avg_reref = True, keep_trials=False)
def on_pB_select_data_clicked(self): self.ui.label_data_loaded.setText("Loading\nData") self.ui.qled_data_loaded.setOffColour(3) self.ui.qled_data_loaded.setOnColour(3) self.session = QtGui.QFileDialog.getExistingDirectory( parent=None, caption="Select Data Directory") self.ui.cB_trial_start_frames.clear() if os.path.isfile(self.session + self.front_video_path): self.front_video = cv2.VideoCapture(self.session + self.front_video_path) self.adc = tlf.load_raw_data(self.session + self.adc_path, numchannels=8, dtype=np.uint16).dataMatrix self.adc_ss = tlf.subsample_basis_data(self.adc, self.rec_freq, self.ss_freq, 'fir', 29) front_counter = tlf.load_colum_from_csv( self.session + self.front_counter_path, 0) self.corrected_frame_numbers = front_counter - front_counter[0] sync = np.squeeze( tlf.load_raw_data(self.session + self.sync_path, numchannels=1, dtype=np.uint8).dataMatrix) sync_diff = np.diff(sync.astype('int8')) self.cam_shutter_closing_samples = np.squeeze( (sync_diff < -0.9).nonzero()) self.ui.qled_data_loaded.setValue(True) self.ui.label_data_loaded.setText("Data\nLoaded") self.ui.qled_data_loaded.setOffColour(1) self.ui.qled_data_loaded.setOnColour(2) self.data_loaded = True analysis_path = os.path.join(self.session, self.analysis_folder) if os.path.exists(analysis_path ): # Add the list of good trials to the combobox self.analysis_exists = True session_hdf5 = pd.HDFStore(analysis_path + self.analysis_file_name) trials_start_stop_info = session_hdf5[self.fronttrials_key] start_frames_strlist = np.char.mod( '%d', trials_start_stop_info[ self.trials_info_start_frame].tolist()) self.ui.cB_trial_start_frames.addItems(start_frames_strlist) if self.paw_events_key in session_hdf5: # Add the lists of paw touch events to their comboboxes paw_events = session_hdf5[self.paw_events_key] """:type : pd.DataFrame""" self.ui.cB_br_paw_frames.addItems([ str(x) for x in paw_events[ paw_events[self.brpaw] != -1][self.brpaw] ]) self.ui.cB_bl_paw_frames.addItems([ str(x) for x in paw_events[ paw_events[self.blpaw] != -1][self.blpaw] ]) self.ui.cB_fr_paw_frames.addItems([ str(x) for x in paw_events[ paw_events[self.frpaw] != -1][self.frpaw] ]) self.ui.cB_fl_paw_frames.addItems([ str(x) for x in paw_events[ paw_events[self.flpaw] != -1][self.flpaw] ]) if self.good_trials_key in session_hdf5: # Add the list of good_tirls to its combobox good_trials = session_hdf5[self.good_trials_key] """:type : pd.Series""" self.ui.cB_selected_trials.addItems( [str(x) for x in good_trials]) if self.trajectories_key in session_hdf5: trajectories = session_hdf5[self.trajectories_key] """:type : pd.DataFrame""" self.ui.cB_trajectory_name.addItems( list(set(trajectories[self.name_traj_point].tolist()))) session_hdf5.close() else: self.ui.qled_data_loaded.setValue(False) self.ui.label_data_loaded.setText("No Data\nLoaded") self.ui.qled_data_loaded.setOffColour(1) self.ui.qled_data_loaded.setOnColour(2) self.data_loaded = False
fn_adc = "C:\George\Data\ECoG_Chronic_Recordings\\2014_08_06_Jpak65_Anesthesia_PawStimulation_Electrical\\2014_08_06_JPak65_PawStimulation_BackRight_200uA_2ms_ADC.bin" fn_amp = "C:\George\Data\ECoG_Chronic_Recordings\\2014_08_06_Jpak65_Anesthesia_PawStimulation_Electrical\\2014_08_06_JPak65_PawStimulation_BackRight_200uA_2ms_Amp.bin" sampling_freq = 20000 threshold = 10000 filt_cutoff_freq = None minduration = 10 pick_out_or_in = True data_raw_events = tl.load_raw_event_trace(fn_adc, number_of_channels= 1, dtype=np.uint16) event_times, event_values = tl.create_piezosensor_events(data_raw_events.dataMatrix, threshold, sampling_freq, filt_cutoff_freq, minduration, pick_out_or_in) data_raw_amp = tl.load_raw_data(fn_amp, 128) sub_tl_data, sub_tl_avg_data, sub_time_axis = tl.time_lock_raw_data(data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], sub_sample_freq=1000) #sub_tl_hp_data, sub_tl_hp_avg_data, sub_time_axis = tl.time_lock_raw_data(data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], high_pass_cutoff=400, rectify=False, sub_sample_freq=1000) #sub_tl_hpr_data, sub_tl_hpr_avg_data, sub_time_axis = tl.time_lock_raw_data(data_raw_amp.dataMatrix, event_times, times_to_cut=[-2, 2], sampling_freq=sampling_freq, baseline_time=[-0.5, 0], high_pass_cutoff=400, rectify=True, sub_sample_freq=1000) fn_adc2 = "C:\George\Data\ECoG_Chronic_Recordings\\14_06_03_Jpak65_Anesthesia_Stimulations\\14_06_03_stimulation_manual_paw_qtip2\stim.bin" fn_amp2 = "C:\George\Data\ECoG_Chronic_Recordings\\14_06_03_Jpak65_Anesthesia_Stimulations\\14_06_03_stimulation_manual_paw_qtip2\\amplifier.bin" sampling_freq = 8000 threshold = 1e7 filt_cutoff_freq = 1000 minduration = 100 pick_out_or_in = True data_raw_events2 = tl.load_raw_event_trace(fn_adc2, number_of_channels=1) event_times2, event_values2 = tl.create_piezosensor_events(data_raw_events2.dataMatrix, threshold, sampling_freq, filt_cutoff_freq, minduration, pick_out_or_in)