def get_tamplitude(self): """ return the time a the peak in the current trace""" #stf.peak_index() does not update cursors!!! self.update() return stf.peak_index()*self._dt
def peakalign(): """ Shift the selected traces in the currently active channel to align the peaks. """ # Measure peak indices in the selected traces pidx = [] for i in stf.get_selected_indices(): stf.set_trace(i) pidx.append(stf.peak_index()) # Find the earliest peak pref = min(pidx) # Align the traces j = 0 shifted_traces = [] for i in stf.get_selected_indices(): stf.set_trace(i) shift = int(pref - pidx[j]) shifted_traces.append(np.roll(stf.get_trace(), shift)) j += 1 return stf.new_window_list(shifted_traces)
def ppr_peak(): # Get function values decay_func = stf.leastsq(0) # Create time from fit start to next peak x = np.arange(stf.get_fit_start(), stf.peak_index()) # Create fitted curve up until peak trace = [(decay_func['Offset'] + decay_func['Amp_0'] * np.exp(-(ind/10.0)/decay_func['Tau_0'])) for ind, val in enumerate(x)] # Find peak value peak_val = stf.get_peak()-stf.get_base() print('The measured peak is {0} pA'.format(peak_val)) # Find value of fit at peak fit_peak = trace[-1] - stf.get_base() print('Tau is {0} pA'.format(decay_func['Tau_0'])) print('The fitted peak is {0} pA'.format(fit_peak)) print('The baseline is {0} pA'.format(stf.get_base())) # stf.new_window(trace) final_peak = peak_val - fit_peak print('The final peak is {0} pA'.format(final_peak)) return True
def get_tamplitude(self): """ return the time a the peak in the current trace""" #stf.peak_index() does not update cursors!!! self.update() return stf.peak_index() * self._dt
def fit_experiment(params, pulse_length, function_to_fit): num_sweeps = stf.get_size_channel() stf.set_channel(0) stf.set_trace(0) #jjm_analysis.set_params(params); #stf.measure(); #this is in samples #peak_index = stf.peak_index(); #stf.set_fit_start(peak_index, is_time=False); #fit_start_time = peak_index*stf.get_sampling_interval(); #stf.set_fit_end(fit_start_time+pulse_length-(10*stf.get_sampling_interval()), is_time=True); #fit_func = stf.leastsq(function_to_fit); #fit_func['Baseline(pA)']=stf.get_base(); #fit_df = pd.DataFrame(fit_func, index=[0]); fits = [] traces = [] for x in range(0, num_sweeps): stf.set_trace(x) jjm_analysis.set_params(params) stf.measure() #this is in samples peak_index = stf.peak_index() stf.set_fit_start(peak_index, is_time=False) fit_start_time = peak_index * stf.get_sampling_interval() stf.set_fit_end(fit_start_time + pulse_length - (10 * stf.get_sampling_interval()), is_time=True) sweep_fit = stf.leastsq(function_to_fit) sweep_fit['Baseline(pA)'] = stf.get_base() fits.append(sweep_fit) traces.append(x) fit_df = pd.DataFrame(fits) return (fit_df)
def glu_iv(pulses=13, subtract_base=True): """Calculates an iv from a repeated series of fast application and voltage pulses. Keyword arguments: pulses -- Number of pulses for the iv. subtract_base -- If True (default), baseline will be subtracted. Returns: True if successful. """ # Some ugly definitions for the time being # Cursors are in ms here. gFitEnd = 330.6 # fit end cursor is variable gFSelect = 0 # Monoexp gDictSize = stf.leastsq_param_size( gFSelect) + 2 # Parameters, chisqr, peak value gBaseStart = 220.5 # Start and end of the baseline before the control pulse, in ms gBaseEnd = 223.55 gPeakStart = 223.55 # Start and end of the peak cursors for the control pulse, in ms gPeakEnd = 253.55 if (gDictSize < 0): print('Couldn\'t retrieve function id=%d, aborting now.' % gFSelect) return False if (not (stf.check_doc())): print('Couldn\'t find an open file; aborting now.') return False # analyse iv, subtract baseline if requested: ivtools.analyze_iv(pulses) if (subtract_base == True): if (not (stf.set_base_start(gBaseStart, True))): return False if (not (stf.set_base_end(gBaseEnd, True))): return False stf.measure() stf.select_all() stf.subtract_base() # set cursors: if (not (stf.set_peak_start(gPeakStart, True))): return False if (not (stf.set_peak_end(gPeakEnd, True))): return False if (not (stf.set_base_start(gBaseStart, True))): return False if (not (stf.set_base_end(gBaseEnd, True))): return False if (not (stf.set_fit_end(gFitEnd, True))): return False if (not (stf.set_peak_mean(3))): return False if (not (stf.set_peak_direction("both"))): return False # A list for dictionary keys and values: dict_keys = [] dict_values = np.empty((gDictSize, stf.get_size_channel())) firstpass = True for n in range(0, stf.get_size_channel()): if (stf.set_trace(n) == False): print('Couldn\'t set a new trace; aborting now.') return False print('Analyzing trace %d of %d' % (n + 1, stf.get_size_channel())) # set the fit window cursors: if (not (stf.set_fit_start(stf.peak_index()))): return False # Least-squares fitting: p_dict = stf.leastsq(gFSelect) if (p_dict == 0): print('Couldn\'t perform a fit; aborting now.') return False # Create an empty list: tempdict_entry = [] row = 0 for k, v in p_dict.iteritems(): if (firstpass == True): dict_keys.append(k) dict_values[row][n] = v row = row + 1 if (firstpass): dict_keys.append("Peak amplitude") dict_values[row][n] = stf.get_peak() - stf.get_base() firstpass = False retDict = dict() # Create the dictionary for the table: entry = 0 for elem in dict_keys: retDict[elem] = dict_values[entry].tolist() entry = entry + 1 return stf.show_table_dictlist(retDict)
def glu_iv( pulses = 13, subtract_base=True ): """Calculates an iv from a repeated series of fast application and voltage pulses. Keyword arguments: pulses -- Number of pulses for the iv. subtract_base -- If True (default), baseline will be subtracted. Returns: True if successful. """ # Some ugly definitions for the time being # Cursors are in ms here. gFitEnd = 330.6 # fit end cursor is variable gFSelect = 0 # Monoexp gDictSize = stf.leastsq_param_size( gFSelect ) + 2 # Parameters, chisqr, peak value gBaseStart = 220.5 # Start and end of the baseline before the control pulse, in ms gBaseEnd = 223.55 gPeakStart = 223.55 # Start and end of the peak cursors for the control pulse, in ms gPeakEnd = 253.55 if ( gDictSize < 0 ): print('Couldn\'t retrieve function id=%d, aborting now.'%gFSelect) return False if ( not(stf.check_doc()) ): print('Couldn\'t find an open file; aborting now.') return False # analyse iv, subtract baseline if requested: ivtools.analyze_iv( pulses ) if ( subtract_base == True ): if ( not(stf.set_base_start( gBaseStart, True )) ): return False if ( not(stf.set_base_end( gBaseEnd, True )) ): return False stf.measure() stf.select_all() stf.subtract_base() # set cursors: if ( not(stf.set_peak_start( gPeakStart, True )) ): return False if ( not(stf.set_peak_end( gPeakEnd, True )) ): return False if ( not(stf.set_base_start( gBaseStart, True )) ): return False if ( not(stf.set_base_end( gBaseEnd, True )) ): return False if ( not(stf.set_fit_end( gFitEnd, True )) ): return False if ( not(stf.set_peak_mean( 3 )) ): return False if ( not(stf.set_peak_direction( "both" )) ): return False # A list for dictionary keys and values: dict_keys = [] dict_values = np.empty( (gDictSize, stf.get_size_channel()) ) firstpass = True for n in range( 0, stf.get_size_channel() ): if ( stf.set_trace( n ) == False ): print('Couldn\'t set a new trace; aborting now.') return False print('Analyzing trace %d of %d'%( n+1, stf.get_size_channel() ) ) # set the fit window cursors: if ( not(stf.set_fit_start( stf.peak_index() )) ): return False # Least-squares fitting: p_dict = stf.leastsq( gFSelect ) if ( p_dict == 0 ): print('Couldn\'t perform a fit; aborting now.') return False # Create an empty list: tempdict_entry = [] row = 0 for k, v in p_dict.iteritems(): if ( firstpass == True ): dict_keys.append( k ) dict_values[row][n] = v row = row+1 if ( firstpass ): dict_keys.append( "Peak amplitude" ) dict_values[row][n] = stf.get_peak()-stf.get_base() firstpass = False retDict = dict() # Create the dictionary for the table: entry = 0 for elem in dict_keys: retDict[ elem ] = dict_values[entry].tolist() entry = entry+1 return stf.show_table_dictlist( retDict )