def jjm_resistance(baseline_start, baseline_end, cap_trans_start, cap_trans_end, amplitude): #time arguments in msec, amplitude argument in mV stf.set_channel(0) stf.set_base_start(baseline_start, True) stf.set_base_end(baseline_end, True) stf.set_peak_start(cap_trans_start, True) stf.set_peak_end(cap_trans_end, True) stf.measure() baseline = float(stf.get_base()) peak = float(stf.get_peak()) real_peak = baseline - peak amplitude = float(amplitude) amplitude_V = amplitude / (10**(3)) real_peak_A = real_peak / (10**(12)) Rs_Ohm = amplitude_V / abs(real_peak_A) Rs = Rs_Ohm / (10**(6)) return (real_peak, Rs)
def jjm_peak(baseline_start, baseline_end, p_start, p_end): #time arguments in msec, amplitude argument in mV stf.set_channel(0) stf.set_base_start(baseline_start, True) stf.set_base_end(baseline_end, True) stf.set_peak_start(p_start, True) stf.set_peak_end(p_end, True) stf.measure() baseline = float(stf.get_base()) peak = float(stf.get_peak()) real_peak = abs(baseline - peak) return (real_peak)
def plot_traces(plotwindow=None, ichannel=0, vchannel=1): """ Show traces in a figure Parameters ---------- plotwindow : (float, float), optional Plot window (in ms from beginning of trace) None for whole trace. Default: None ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 1) ax_currents = stfio_plot.StandardAxis( fig, gs[:3, 0], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis( fig, gs[3:, 0], hasx=False, hasy=False, sharex=ax_currents) if plotwindow is not None: istart = int(plotwindow[0]/dt) istop = int(plotwindow[1]/dt) else: istart = 0 istop = None for ntrace in range(stf.get_size_channel()): stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace()[istart:istop] ax_currents.plot(np.arange(len(trace))*dt, trace) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace()[istart:istop] ax_voltages.plot(np.arange(len(trace))*dt, trace) # Reset active channel stf.set_channel(ichannel) stfio_plot.plot_scalebars( ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=0)) stfio_plot.plot_scalebars( ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=1))
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 plot_traces(plotwindow=None, ichannel=0, vchannel=1): """ Show traces in a figure Parameters ---------- plotwindow : (float, float), optional Plot window (in ms from beginning of trace) None for whole trace. Default: None ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 1) ax_currents = stfio_plot.StandardAxis(fig, gs[:3, 0], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis(fig, gs[3:, 0], hasx=False, hasy=False, sharex=ax_currents) if plotwindow is not None: istart = int(plotwindow[0] / dt) istop = int(plotwindow[1] / dt) else: istart = 0 istop = None for ntrace in range(stf.get_size_channel()): stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace()[istart:istop] ax_currents.plot(np.arange(len(trace)) * dt, trace) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace()[istart:istop] ax_voltages.plot(np.arange(len(trace)) * dt, trace) # Reset active channel stf.set_channel(ichannel) stfio_plot.plot_scalebars(ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=0)) stfio_plot.plot_scalebars(ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=1))
def iv(peakwindow=None, basewindow=None, pulsewindow=None, erev=None, peakmode="both", ichannel=0, vchannel=1, exclude=None): """ Compute and plot an IV curve for currents Parameters ---------- peakwindow : (float, float), optional Window for peak measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None basewindow : (float, float), optional Window for baseline measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None pulsewindow : (float, float), optional Window for voltage pulse measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None erev : float, optional End of v clamp pulse in ms or None to determine automatically. Default: None peakmode : string, optional Peak direction - one of "up", "down", "both" or "mean". Default: "up" ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 exclude : list of ints, optional List of trace indices to be excluded from the analysis. Default: None Returns ------- v_commands : numpy.ndarray Command voltages ipeaks : numpy.ndarray Peak currents gpeaks : numpy.ndarray Peak normalized conductances g_fit : numpy.ndarray Half-maximal voltage and slope of best-fit Boltzmann function """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() olddirection = stf.get_peak_direction() v_commands = [] ipeaks = [] if basewindow is not None: stf.base.cursor_time = basewindow fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 8) ax_currents = stfio_plot.StandardAxis(fig, gs[:3, :4], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis(fig, gs[3:, :4], hasx=False, hasy=False, sharex=ax_currents) for ntrace in range(stf.get_size_channel()): if exclude is not None: if ntrace in exclude: continue stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace() ax_currents.plot(np.arange(len(trace)) * dt, trace) # Measure only downward peaks (inward currents) if peakmode is "mean": stf.set_peak_direction("up") stf.set_peak_mean(-1) else: stf.set_peak_direction(peakmode) # Set peak computation to single sampling point stf.set_peak_mean(1) if peakwindow is not None: stf.peak.cursor_time = peakwindow stf.measure() if basewindow is not None: ipeaks.append(stf.peak.value - stf.base.value) else: ipeaks.append(stf.peak.value) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace() ax_voltages.plot(np.arange(len(trace)) * dt, trace) stf.set_peak_direction("up") stf.set_peak_mean(-1) if pulsewindow is not None: stf.peak.cursor_time = pulsewindow stf.measure() v_commands.append(stf.peak.value) stfio_plot.plot_scalebars(ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=0)) stfio_plot.plot_scalebars(ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=1)) v_commands = np.array(v_commands) ipeaks = np.array(ipeaks) if erev is None: # Find first zero crossing in ipeaks: for npulse in range(ipeaks.shape[0] - 1): if np.sign(ipeaks[npulse]) != np.sign(ipeaks[npulse + 1]): # linear interpolation m1 = (ipeaks[npulse + 1] - ipeaks[npulse]) / ( v_commands[npulse + 1] - v_commands[npulse]) c1 = ipeaks[npulse] - m1 * v_commands[npulse] erev = -c1 / m1 break if erev is None: sys.stderr.write( "Could not determine reversal potential. Aborting now\n") return None # Reset peak computation to single sampling point stf.set_peak_mean(1) stf.set_peak_direction(olddirection) # Reset active channel stf.set_channel(ichannel) # Compute conductances: gpeaks, g_fit = gv(ipeaks, v_commands, erev) ax_ipeaks = plot_iv(ipeaks, v_commands, stf.get_yunits(channel=ichannel), stf.get_yunits(channel=1), fig, 222) ax_ipeaks.set_title("Peak current") ax_gpeaks = plot_gv(gpeaks, v_commands, stf.get_yunits(channel=vchannel), g_fit, fig, 224) ax_gpeaks.set_title("Peak conductance") stf.show_table_dictlist({ "Voltage ({0})".format(stf.get_yunits(channel=vchannel)): v_commands.tolist(), "Peak current ({0})".format(stf.get_yunits(channel=ichannel)): ipeaks.tolist(), "Peak conductance (g/g_max)": gpeaks.tolist(), }) return v_commands, ipeaks, gpeaks, g_fit
def timeconstants(fitwindow, pulsewindow, ichannel=0, vchannel=1): """ Compute and plot decay time constants Parameters ---------- fitwindow : (float, float), optional Window for fitting time constant (time in ms from beginning of sweep) None for current cursor settings. Default: None pulsewindow : (float, float), optional Window for voltage pulse measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 Returns ------- v_commands : numpy.ndarray Command voltages taus : numpy.ndarray Time constants """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() v_commands = [] taus = [] fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 8) ax_currents = stfio_plot.StandardAxis(fig, gs[:3, :4], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis(fig, gs[3:, :4], hasx=False, hasy=False, sharex=ax_currents) for ntrace in range(stf.get_size_channel()): stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace() ax_currents.plot(np.arange(len(trace)) * dt, trace) if fitwindow is not None: stf.fit.cursor_time = fitwindow res = stf.leastsq(0, False) taus.append(res['Tau_0']) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace() ax_voltages.plot(np.arange(len(trace)) * dt, trace) stf.set_peak_direction("up") stf.set_peak_mean(-1) if pulsewindow is not None: stf.peak.cursor_time = pulsewindow stf.measure() v_commands.append(stf.peak.value) stfio_plot.plot_scalebars(ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=ichannel)) stfio_plot.plot_scalebars(ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=vchannel)) v_commands = np.array(v_commands) taus = np.array(taus) ax_taus = plot_iv(taus, v_commands, "ms", stf.get_yunits(channel=vchannel), fig, 122) # Reset peak computation to single sampling point stf.set_peak_mean(1) # Reset active channel stf.set_channel(ichannel) # Compute conductances: stf.show_table_dictlist({ "Voltage ({0})".format(stf.get_yunits(channel=vchannel)): v_commands.tolist(), "Taus (ms)": taus.tolist(), }) return v_commands, taus
def iv(peakwindow=None, basewindow=None, pulsewindow=None, erev=None, peakmode="both", ichannel=0, vchannel=1, exclude=None): """ Compute and plot an IV curve for currents Parameters ---------- peakwindow : (float, float), optional Window for peak measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None basewindow : (float, float), optional Window for baseline measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None pulsewindow : (float, float), optional Window for voltage pulse measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None erev : float, optional End of v clamp pulse in ms or None to determine automatically. Default: None peakmode : string, optional Peak direction - one of "up", "down", "both" or "mean". Default: "up" ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 exclude : list of ints, optional List of trace indices to be excluded from the analysis. Default: None Returns ------- v_commands : numpy.ndarray Command voltages ipeaks : numpy.ndarray Peak currents gpeaks : numpy.ndarray Peak normalized conductances g_fit : numpy.ndarray Half-maximal voltage and slope of best-fit Boltzmann function """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() olddirection = stf.get_peak_direction() v_commands = [] ipeaks = [] if basewindow is not None: stf.base.cursor_time = basewindow fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 8) ax_currents = stfio_plot.StandardAxis( fig, gs[:3, :4], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis( fig, gs[3:, :4], hasx=False, hasy=False, sharex=ax_currents) for ntrace in range(stf.get_size_channel()): if exclude is not None: if ntrace in exclude: continue stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace() ax_currents.plot(np.arange(len(trace))*dt, trace) # Measure only downward peaks (inward currents) if peakmode is "mean": stf.set_peak_direction("up") stf.set_peak_mean(-1) else: stf.set_peak_direction(peakmode) # Set peak computation to single sampling point stf.set_peak_mean(1) if peakwindow is not None: stf.peak.cursor_time = peakwindow stf.measure() if basewindow is not None: ipeaks.append(stf.peak.value-stf.base.value) else: ipeaks.append(stf.peak.value) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace() ax_voltages.plot(np.arange(len(trace))*dt, trace) stf.set_peak_direction("up") stf.set_peak_mean(-1) if pulsewindow is not None: stf.peak.cursor_time = pulsewindow stf.measure() v_commands.append(stf.peak.value) stfio_plot.plot_scalebars( ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=0)) stfio_plot.plot_scalebars( ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=1)) v_commands = np.array(v_commands) ipeaks = np.array(ipeaks) if erev is None: # Find first zero crossing in ipeaks: for npulse in range(ipeaks.shape[0]-1): if np.sign(ipeaks[npulse]) != np.sign(ipeaks[npulse+1]): # linear interpolation m1 = (ipeaks[npulse+1]-ipeaks[npulse]) / ( v_commands[npulse+1]-v_commands[npulse]) c1 = ipeaks[npulse] - m1*v_commands[npulse] erev = -c1/m1 break if erev is None: sys.stderr.write( "Could not determine reversal potential. Aborting now\n") return None # Reset peak computation to single sampling point stf.set_peak_mean(1) stf.set_peak_direction(olddirection) # Reset active channel stf.set_channel(ichannel) # Compute conductances: gpeaks, g_fit = gv(ipeaks, v_commands, erev) ax_ipeaks = plot_iv( ipeaks, v_commands, stf.get_yunits(channel=ichannel), stf.get_yunits(channel=1), fig, 222) ax_ipeaks.set_title("Peak current") ax_gpeaks = plot_gv( gpeaks, v_commands, stf.get_yunits(channel=vchannel), g_fit, fig, 224) ax_gpeaks.set_title("Peak conductance") stf.show_table_dictlist({ "Voltage ({0})".format( stf.get_yunits(channel=vchannel)): v_commands.tolist(), "Peak current ({0})".format( stf.get_yunits(channel=ichannel)): ipeaks.tolist(), "Peak conductance (g/g_max)": gpeaks.tolist(), }) return v_commands, ipeaks, gpeaks, g_fit
def timeconstants(fitwindow, pulsewindow, ichannel=0, vchannel=1): """ Compute and plot decay time constants Parameters ---------- fitwindow : (float, float), optional Window for fitting time constant (time in ms from beginning of sweep) None for current cursor settings. Default: None pulsewindow : (float, float), optional Window for voltage pulse measurement (time in ms from beginning of sweep) None for current cursor settings. Default: None ichannel : int, optional current channel number. Default: 0 vchannel : int, optional voltage channel number. Default: 1 Returns ------- v_commands : numpy.ndarray Command voltages taus : numpy.ndarray Time constants """ import stf if not stf.check_doc(): return None nchannels = stf.get_size_recording() if nchannels < 2: sys.stderr.write( "Function requires 2 channels (0: current; 1: voltage)\n") return dt = stf.get_sampling_interval() v_commands = [] taus = [] fig = stf.mpl_panel(figsize=(12, 8)).fig fig.clear() gs = gridspec.GridSpec(4, 8) ax_currents = stfio_plot.StandardAxis( fig, gs[:3, :4], hasx=False, hasy=False) ax_voltages = stfio_plot.StandardAxis( fig, gs[3:, :4], hasx=False, hasy=False, sharex=ax_currents) for ntrace in range(stf.get_size_channel()): stf.set_trace(ntrace) stf.set_channel(ichannel) trace = stf.get_trace() ax_currents.plot(np.arange(len(trace))*dt, trace) if fitwindow is not None: stf.fit.cursor_time = fitwindow res = stf.leastsq(0, False) taus.append(res['Tau_0']) # Measure pulse amplitude stf.set_channel(vchannel) trace = stf.get_trace() ax_voltages.plot(np.arange(len(trace))*dt, trace) stf.set_peak_direction("up") stf.set_peak_mean(-1) if pulsewindow is not None: stf.peak.cursor_time = pulsewindow stf.measure() v_commands.append(stf.peak.value) stfio_plot.plot_scalebars( ax_currents, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=ichannel)) stfio_plot.plot_scalebars( ax_voltages, xunits=stf.get_xunits(), yunits=stf.get_yunits(channel=vchannel)) v_commands = np.array(v_commands) taus = np.array(taus) ax_taus = plot_iv( taus, v_commands, "ms", stf.get_yunits(channel=vchannel), fig, 122) # Reset peak computation to single sampling point stf.set_peak_mean(1) # Reset active channel stf.set_channel(ichannel) # Compute conductances: stf.show_table_dictlist({ "Voltage ({0})".format( stf.get_yunits(channel=vchannel)): v_commands.tolist(), "Taus (ms)": taus.tolist(), }) return v_commands, taus