def sloping_base(trace=-1, method='scale'): """ Correct for linear sloping baseline in the displayed trace of the active channel. Useful for approximate correction of photobleaching during short periods of imaging. Available methods are 'scale' or 'subtract'. """ # Get trace and trace attributes selected_trace = stf.get_trace(trace) fit_start = stf.get_base_start() fit_end = stf.get_base_end() # Linear fit to baseline region fit = np.polyfit(np.arange(fit_start, fit_end, 1, int), selected_trace[fit_start:fit_end], 1) # Correct trace for sloping baseline l = stf.get_size_trace(trace) t = np.arange(0, l, 1, np.double) if method == 'subtract': corrected_trace = selected_trace - t * fit[0] elif method == 'scale': corrected_trace = selected_trace * fit[1] / (t * fit[0] + fit[1]) return stf.new_window_list([corrected_trace])
def get_base(self): """ Get baseline according to cursor possition in the given current channel/trace """ self.update() return stf.get_trace(trace = -1 ,channel = -1)[stf.get_base_start():stf.get_base_end()+1].mean()
def get_base(self): """ Get baseline according to cursor possition in the given current channel/trace """ self.update() return stf.get_trace( trace=-1, channel=-1)[stf.get_base_start():stf.get_base_end() + 1].mean()
def get_params(time): peak_1_s = stf.get_base_start(is_time=time) peak_1_e = stf.get_base_end(is_time=time) peak_2_s = stf.get_peak_start(is_time=time) peak_2_e = stf.get_peak_end(is_time=time) print(peak_1_s, peak_1_e, peak_2_s, peak_2_e) params = [peak_1_s, peak_1_e, peak_2_s, peak_2_e] if time == True: print('values are time') else: print('values are sweep indicies') return (params)
def psc_analysis(self): self.psc_data = self.metadata[self.metadata.recording_type == 'psc'] self.psc_data['ch1_self_psc'] = [False for _ in self.psc_data] self.psc_data['ch1_other_psc'] = [False for _ in self.psc_data] self.psc_data['ch2_self_psc'] = [False for _ in self.psc_data] self.psc_data['ch2_other_psc'] = [False for _ in self.psc_data] self.psc_data['ch1_self_tau'] = [False for _ in self.psc_data] self.psc_data['ch1_other_tau'] = [False for _ in self.psc_data] self.psc_data['ch2_self_tau'] = [False for _ in self.psc_data] self.psc_data['ch2_other_tau'] = [False for _ in self.psc_data] for idx, abffiles in enumerate(self.psc_data): # Initialize Channel 1 data = AbfFile(abffiles, self.path) stf.new_window_matrix(data.channel1.signal) # Cell 1 to Self advance_var = input("Cell 1: Select the traces to use, set the Peak, Baseline, and fit cursors for self.\n" "If no connection exists, type 'no connection'\n" "Type 'y' to advance to the next trace:\t") while advance_var is not 'y' or advance_var is not 'no connection': advance_var = input("You must type 'y' or 'no connection' to advance:\t") if advance_var == 'no connection': self.psc_data['ch1_self_psc'][idx] = None self.psc_data['ch1_self_tau'][idx] = None else: peaks = np.array( [np.min(trace[stf.get_peak_start():stf.get_peak_end()]) for trace in data.channel1.signal] ) bases = np.array( [np.mean(trace[stf.get_base_start():stf.get_base_end()]) for trace in data.channel1.signal] ) peak = np.mean(peaks - bases) fit = stf.leastsq(0) self.psc_data['ch1_self_psc'][idx] = peak self.psc_data['ch1_self_tau'][idx] = fit['Tau_0'] # Cell 2 to Cell 1 advance_var = input("Great, now do the same for Cell 2 onto Cell 1.\n" "Type 'y' to advance to the next trace:\t") while advance_var is not 'y' or advance_var is not 'no connection': advance_var = input("You must type 'y' or 'no connection' to advance:\t") if advance_var == 'no connection': self.psc_data['ch2_other_psc'][idx] = None self.psc_data['ch2_other_tau'][idx] = None else: peaks = np.array( [np.min(trace[stf.get_peak_start():stf.get_peak_end()]) for trace in data.channel1.signal] ) bases = np.array( [np.mean(trace[stf.get_base_start():stf.get_base_end()]) for trace in data.channel1.signal] ) peak = np.mean(peaks - bases) fit = stf.leastsq(0) self.psc_data['ch2_other_psc'][idx] = peak self.psc_data['ch2_other_tau'][idx] = fit['Tau_0'] # Initialize Channel 2 data = AbfFile(abffiles, self.path) stf.new_window_matrix(data.channel1.signal) # Cell 2 to Self advance_var = input("Cell 2: Select the traces to use, set the Peak, Baseline, and fit cursors for self.\n" "If no connection exists, type 'no connection'\n" "Type 'y' to advance to the next trace:\t") while advance_var is not 'y' or advance_var is not 'no connection': advance_var = input("You must type 'y' or 'no connection' to advance:\t") if advance_var == 'no connection': self.psc_data['ch2_self_psc'][idx] = None self.psc_data['ch2_self_tau'][idx] = None else: peaks = np.array([np.min(trace[stf.get_peak_start():stf.get_peak_end()]) for trace in data.channel1.signal]) bases = np.array( [np.mean(trace[stf.get_base_start():stf.get_base_end()]) for trace in data.channel1.signal]) peak = np.mean(peaks - bases) fit = stf.leastsq(0) self.psc_data['ch2_self_psc'][idx] = peak self.psc_data['ch2_self_tau'][idx] = fit['Tau_0'] # Cell 2 to Cell 1 advance_var = input("Great, now do the same for Cell 2 onto Cell 1.\n" "Type 'y' to advance to the next trace:\t") while advance_var is not 'y' or advance_var is not 'no connection': advance_var = input("You must type 'y' or 'no connection' to advance:\t") if advance_var == 'no connection': self.psc_data['ch1_other_psc'][idx] = None self.psc_data['ch1_other_tau'][idx] = None else: peaks = np.array([np.min(trace[stf.get_peak_start():stf.get_peak_end()]) for trace in data.channel1.signal]) bases = np.array( [np.mean(trace[stf.get_base_start():stf.get_base_end()]) for trace in data.channel1.signal]) peak = np.mean(peaks - bases) fit = stf.leastsq(0) self.psc_data['ch1_other_psc'][idx] = peak self.psc_data['ch1_other_tau'][idx] = fit['Tau_0'] self.psc_data.to_csv(os.path.join(self.path, '.stimpy', 'psc_data.csv'))