def process_data(self): data = self.data run_param = self.run_param process_param = self.process_param LFP_amp = LFPy_util.data_extraction.maxabs(data['LFP'],axis=1) LFP_amp = LFP_amp.reshape([data['n_elec_x'],data['n_elec_y']]) grid_x, grid_y = np.meshgrid(data['lin_x'],data['lin_y']) signal = data['soma_v'] spike, spikes_t_vec, I = de.extract_spikes( data['t_vec'], signal, pre_dur=process_param['pre_dur'], post_dur=process_param['post_dur'], threshold=process_param['threshold'], amp_option=process_param['amp_option'], ) # Gather all spikes from the same indices as where the spike appears # in the first electrode. spike_index = process_param['spike_to_measure'] if spike.shape[0] < spike_index: raise ValueError("Found fewer spikes than process_param['spike_to_measure']") spikes = data['LFP'][:, I[spike_index, 0]:I[spike_index, 1]] amps_I = de.find_amplitude_type_I(spikes, amp_option=process_param['amp_option']) amps_II = de.find_amplitude_type_II(spikes) widths_I, widths_I_trace = de.find_wave_width_type_I(spikes, dt=data['dt']) widths_II, widths_II_trace = de.find_wave_width_type_II( spikes, dt=data['dt'], amp_option=process_param['amp_option']) widths_I = widths_I.reshape([data['n_elec_x'],data['n_elec_y']]) widths_II = widths_II.reshape([data['n_elec_x'],data['n_elec_y']]) data['LFP_amp'] = LFP_amp*1000 data['grid_x'] = grid_x data['grid_y'] = grid_y data['amps_I'] = amps_I * 1000 data['amps_II'] = amps_II * 1000 data['widths_I'] = widths_I data['widths_I_trace'] = widths_I_trace * 1000 data['widths_II'] = widths_II data['widths_II_trace'] = widths_II_trace * 1000 data['spikes'] = spikes * 1000 data['spikes_t_vec'] = spikes_t_vec
def process_data(self): data = self.data run_param = self.run_param process_param = self.process_param # Get the signal from the soma potential. signal = data['soma_v'] spike, spikes_t_vec, I = de.extract_spikes( data['t_vec'], signal, pre_dur=process_param['pre_dur'], post_dur=process_param['post_dur'], threshold=process_param['threshold'], amp_option=process_param['amp_option'], ) # Gather all spikes from the same indices as where the spike appears # in the first electrode. spike_index = process_param['spike_to_measure'] if spike.shape[0] < spike_index: raise ValueError("Found fewer spikes than process_param['spike_to_measure']") spikes = data['LFP'][:, I[spike_index, 0]:I[spike_index, 1]] amps_I = de.find_amplitude_type_I(spikes, amp_option=process_param['amp_option']) amps_II = de.find_amplitude_type_II(spikes) widths_I, widths_I_trace = de.find_wave_width_type_I(spikes, dt=data['dt']) widths_II, widths_II_trace = de.find_wave_width_type_II( spikes, threshold=process_param['width_II_thresh'], dt=data['dt'], amp_option=process_param['amp_option']) widths_III, widths_III_trace = de.find_wave_width_type_III( spikes, threshold=process_param['width_III_thresh'], dt=data['dt'], amp_option=process_param['amp_option']) p = run_param['n_phi'] n = run_param['n'] amps_I = np.reshape(amps_I, (p, n)) amps_II = np.reshape(amps_II, (p, n)) widths_I = np.reshape(widths_I, (p, n)) widths_II = np.reshape(widths_II, (p, n)) widths_III = np.reshape(widths_III, (p, n)) # Becomes vector with length n. amps_I_mean = np.mean(amps_I, 0) amps_I_std = np.std(amps_I, 0) amps_II_mean = np.mean(amps_II, 0) amps_II_std = np.std(amps_II, 0) widths_I_mean = np.mean(widths_I, 0) widths_I_std = np.std(widths_I, 0) widths_II_mean = np.mean(widths_II, 0) widths_II_std = np.std(widths_II, 0) widths_III_mean = np.mean(widths_III, 0) widths_III_std = np.std(widths_III, 0) data['amps_I_mean'] = amps_I_mean * 1000 data['amps_I_std'] = amps_I_std * 1000 data['amps_I'] = amps_I * 1000 data['amps_II_mean'] = amps_II_mean * 1000 data['amps_II_std'] = amps_II_std * 1000 data['amps_II'] = amps_II * 1000 data['widths_I_mean'] = widths_I_mean data['widths_I_std'] = widths_I_std data['widths_I'] = widths_I data['widths_I_trace'] = widths_I_trace * 1000 data['widths_II_mean'] = widths_II_mean data['widths_II_std'] = widths_II_std data['widths_II'] = widths_II data['widths_II_trace'] = widths_II_trace * 1000 data['widths_III_mean'] = widths_III_mean data['widths_III_std'] = widths_III_std data['widths_III'] = widths_III data['widths_III_trace'] = widths_III_trace * 1000 data['spikes'] = spikes * 1000 data['spikes_t_vec'] = spikes_t_vec data['r_vec'] = np.linspace(run_param['R_0'], run_param['R'], run_param['n'])
def process_data(self): data = self.data run_param = self.run_param process_param = self.process_param t_vec = np.array(data['t_vec']) v_vec = np.array(data['LFP'])*1000 x = np.array(data['elec_x']).flatten() y = np.array(data['elec_y']).flatten() z = np.array(data['elec_z']).flatten() # Calculate the radial distance to the electrodes. r = np.sqrt(x * x + y * y + z * z).flatten() # Get the signal from the soma potential. # signal = data['LFP'][0] signal = data['soma_v'] spikes, spikes_t_vec, I = de.extract_spikes( data['t_vec'], signal, pre_dur=process_param['pre_dur'], post_dur=process_param['post_dur'], threshold=process_param['threshold'], amp_option=process_param['amp_option'], ) # Gather all spikes from the same indices as where the spike appears # in the membrane potential. spike_index = process_param['spike_to_measure'] if spikes.shape[0] < spike_index: raise ValueError("Found fewer spikes than process_param['spike_to_measure']") spikes = v_vec[:, I[spike_index, 0]:I[spike_index, 1]] # Find widths of the spikes, trace can be used for plotting. widths_I, widths_I_trace = de.find_wave_width_type_I(spikes, dt=data['dt']) widths_II, widths_II_trace = de.find_wave_width_type_II( spikes, threshold=process_param['width_half_thresh'], dt=data['dt'], amp_option=self.process_param['amp_option']) amps_I = de.find_amplitude_type_I(spikes, amp_option=self.process_param['amp_option']) amps_II = de.find_amplitude_type_II(spikes) # Remove spikes which does not look nice. data['widths_I_original'] = widths_I data['widths_II_original'] = widths_II if process_param['assert_width']: low = np.where(widths_I < process_param['assert_width_I_low'])[0] high = np.where(widths_I > process_param['assert_width_I_high'])[0] ignored_spikes_I = np.union1d(low, high) low = np.where(widths_II < process_param['assert_width_II_low'])[0] high = np.where(widths_II > process_param['assert_width_II_high'])[0] ignored_spikes_II = np.union1d(low, high) ignored_spikes = np.union1d(ignored_spikes_I, ignored_spikes_II) spikes = np.delete(spikes, ignored_spikes, axis=0) widths_I = np.delete(widths_I, ignored_spikes, axis=0) widths_II = np.delete(widths_II, ignored_spikes, axis=0) amps_I = np.delete(amps_I, ignored_spikes, axis=0) amps_II = np.delete(amps_II, ignored_spikes, axis=0) x = np.delete(x, ignored_spikes, axis=0) y = np.delete(y, ignored_spikes, axis=0) z = np.delete(z, ignored_spikes, axis=0) r = np.delete(r, ignored_spikes, axis=0) self.info['ignored_spikes_cnt'] = len(ignored_spikes) # Put widths_I in bins decided by the radial distance. # Then calculate std and mean. bins = np.linspace(0, run_param['R'], self.process_param['bins'], endpoint=True) # Find the indices of the bins to which each value in r array belongs. inds = np.digitize(r, bins) # Widths and amps binned by distance. widths_I_at_r = [widths_I[inds == i] for i in range(len(bins))] widths_II_at_r = [widths_II[inds == i] for i in range(len(bins))] amps_I_at_r = [amps_I[inds == i] for i in range(len(bins))] amps_II_at_r = [amps_II[inds == i] for i in range(len(bins))] with warnings.catch_warnings(): # Ignore warnings where mean or var has zero sized array as input. warnings.simplefilter("ignore", category=RuntimeWarning) widths_I_mean = [widths_I[inds == i].mean() for i in range(len(bins))] widths_I_std = [np.sqrt(widths_I[inds == i].var()) for i in range(len(bins))] widths_II_mean = [widths_II[inds == i].mean() for i in range(len(bins))] widths_II_std = [np.sqrt(widths_II[inds == i].var()) for i in range(len(bins))] amps_I_mean = [amps_I[inds == i].mean() for i in range(len(bins))] amps_I_std = [np.sqrt(amps_I[inds == i].var()) for i in range(len(bins))] amps_II_mean = [amps_II[inds == i].mean() for i in range(len(bins))] amps_II_std = [np.sqrt(amps_II[inds == i].var()) for i in range(len(bins))] widths_I_mean = np.array(widths_I_mean) widths_II_mean = np.array(widths_II_mean) amps_I_mean = np.array(amps_I_mean) amps_II_mean = np.array(amps_II_mean) widths_I_std = np.array(widths_I_std) widths_II_std = np.array(widths_II_std) amps_I_std = np.array(amps_I_std) amps_II_std = np.array(amps_II_std) data['elec_r_all'] = r data['amps_I_mean'] = amps_I_mean data['amps_I_std'] = amps_I_std data['amps_I'] = amps_I data['amps_I_at_r'] = amps_I_at_r data['amps_II_mean'] = amps_II_mean data['amps_II_std'] = amps_II_std data['amps_II'] = amps_II data['amps_II_at_r'] = amps_II_at_r data['widths_I_mean'] = widths_I_mean data['widths_I_std'] = widths_I_std data['widths_I'] = widths_I data['widths_I_trace'] = widths_I_trace data['widths_I_at_r'] = widths_I_at_r data['widths_II_mean'] = widths_II_mean data['widths_II_std'] = widths_II_std data['widths_II'] = widths_II data['widths_II_trace'] = widths_II_trace data['widths_II_at_r'] = widths_II_at_r data['bins'] = bins data['elec_r'] = r data['spikes'] = spikes data['spikes_t_vec'] = spikes_t_vec self.info['spike_to_measure'] = process_param['spike_to_measure'] self.info['dt'] = data['dt']