def test_raise_warnings(): """basic: Test raise_warnings""" import efel efel.reset() import numpy trace = {} trace['T'] = numpy.arange(0, 100, 0.1) trace['V'] = numpy.ones(len(trace['T'])) * -80.0 trace['stim_start'] = [25] trace['stim_end'] = [75] import warnings with warnings.catch_warnings(record=True) as warning: warnings.simplefilter("always") feature_value = efel.getFeatureValues( [trace], ['AP_amplitude'])[0]['AP_amplitude'] nt.assert_equal(feature_value, None) nt.assert_equal(len(warning), 1) nt.assert_true( "Error while calculating feature AP_amplitude" in str(warning[0].message)) with warnings.catch_warnings(record=True) as warning: warnings.simplefilter("always") feature_value = efel.getFeatureValues( [trace], ['AP_amplitude'], raise_warnings=False)[0]['AP_amplitude'] nt.assert_equal(feature_value, None) nt.assert_equal(len(warning), 0)
def test_unfinished_peak(): """basic: Test if unfinished peak doesn't break Spikecount""" import efel efel.setIntSetting('strict_stiminterval', True) dt = 0.1 v = numpy.zeros(int(100 / dt)) - 70.0 v[int(20 / dt):int(25 / dt)] = 20. v[int(40 / dt):int(45 / dt)] = 20. v[int(60 / dt):int(65 / dt)] = 20. trace = {} trace['T'] = numpy.arange(len(v)) * dt trace['V'] = v trace['stim_start'] = [10] trace['stim_end'] = [70] traces_results = efel.getFeatureValues([trace], ['Spikecount']) spikecount = traces_results[0]['Spikecount'][0] nt.assert_equal(spikecount, 3) # When the signal at the end of the trace is larger than the threshold, # Spikecount and possibly other features cannont be estimated. v[int(80 / dt):] = -19 traces_results = efel.getFeatureValues([trace], ['Spikecount']) spikecount = traces_results[0]['Spikecount'][0] nt.assert_equal(spikecount, 3)
def test_setDerivativeThreshold(): """basic: Test setDerivativeThreshold""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_begin_voltage'] feature_values = \ efel.getFeatureValues( [trace], features) AP_begin_voltage_orig = feature_values[0]['AP_begin_voltage'][1] efel.setDerivativeThreshold(5) feature_values = \ efel.getFeatureValues( [trace], features) AP_begin_voltage = feature_values[0]['AP_begin_voltage'][1] nt.assert_almost_equal(AP_begin_voltage, -51.6400489995987) nt.assert_not_equal(AP_begin_voltage, AP_begin_voltage_orig)
def test_consecutive_traces(): """basic: Test if features from two different traces give other results""" import efel efel.reset() import numpy stim_start = 31.2 stim_end = 431.2 data1 = numpy.loadtxt( 'testdata/basic/zero_ISI_log_slope_skip95824004.abf.csv') time1 = data1[:, 0] voltage1 = data1[:, 1] trace1 = {} trace1['T'] = time1 trace1['V'] = voltage1 trace1['stim_start'] = [stim_start] trace1['stim_end'] = [stim_end] feature_name = 'peak_time' import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") feature_values1 = \ efel.getFeatureValues( [trace1], [feature_name]) data2 = numpy.loadtxt( 'testdata/basic/AP_begin_indices_95810005.abf.csv') voltage2 = data2 time2 = numpy.arange(len(voltage2)) * 0.1 trace2 = {} trace2['T'] = time2 trace2['V'] = voltage2 trace2['stim_start'] = [stim_start] trace2['stim_end'] = [stim_end] with warnings.catch_warnings(): warnings.simplefilter("ignore") feature_values2 = \ efel.getFeatureValues( [trace2], [feature_name]) nt.assert_not_equal( len(feature_values1[0][feature_name]), len(feature_values2[0][feature_name]))
def test_consecutive_traces(): """basic: Test if features from two different traces give other results""" import efel efel.reset() import numpy stim_start = 31.2 stim_end = 431.2 time1 = efel.io.load_fragment('%s#col=1' % zeroISIlog1_url) voltage1 = efel.io.load_fragment('%s#col=2' % zeroISIlog1_url) trace1 = {} trace1['T'] = time1 trace1['V'] = voltage1 trace1['stim_start'] = [stim_start] trace1['stim_end'] = [stim_end] feature_name = 'peak_time' feature_values1 = \ efel.getFeatureValues( [trace1], [feature_name], raise_warnings=False) test_data_path = os.path.join( testdata_dir, 'basic', 'AP_begin_indices_95810005.abf.csv') data2 = numpy.loadtxt(test_data_path) voltage2 = data2 time2 = numpy.arange(len(voltage2)) * 0.1 trace2 = {} trace2['T'] = time2 trace2['V'] = voltage2 trace2['stim_start'] = [stim_start] trace2['stim_end'] = [stim_end] feature_values2 = \ efel.getFeatureValues( [trace2], [feature_name], raise_warnings=False) nt.assert_not_equal( len(feature_values1[0][feature_name]), len(feature_values2[0][feature_name]))
def test_derivwindow1(): """basic: Test DerivativeWindow""" import efel efel.reset() stim_start = 100.0 stim_end = 1000.0 time = efel.io.load_fragment('%s#col=1' % derivwindow1_url) voltage = efel.io.load_fragment('%s#col=2' % derivwindow1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_begin_voltage'] feature_values = \ efel.getFeatureValues( [trace], features) AP_begin_voltage = feature_values[0]['AP_begin_voltage'][0] nt.assert_almost_equal(AP_begin_voltage, -45.03627393790836) efel.reset() efel.setDoubleSetting('interp_step', 0.01) feature_values = \ efel.getFeatureValues( [trace], features) AP_begin_voltage = feature_values[0]['AP_begin_voltage'][0] nt.assert_almost_equal(AP_begin_voltage, -83.57661997973835) efel.reset() efel.setDoubleSetting('interp_step', 0.01) efel.setIntSetting('DerivativeWindow', 30) feature_values = \ efel.getFeatureValues( [trace], features) AP_begin_voltage = feature_values[0]['AP_begin_voltage'][0] nt.assert_almost_equal(AP_begin_voltage, -45.505521563640386)
def test_spikecount1(): """basic: Test Spikecount 1""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['peak_indices', 'Spikecount'] feature_values = \ efel.getFeatureValues( [trace], features) peak_indices = feature_values[0]['peak_indices'] spikecount = feature_values[0]['Spikecount'][0] nt.assert_equal(len(peak_indices), spikecount)
def test_decay_time_constant_after_stim2(): """basic: decay_time_constant_after_stim 2""" import efel efel.reset() import numpy stim_start = 100.0 stim_end = 1000.0 test_data_path = joinp(testdata_dir, 'basic', 'tau20.0.csv') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] trace = { 'T': time, 'V': voltage, 'stim_start': [stim_start], 'stim_end': [stim_end], 'decay_start_after_stim': [1.0], 'decay_end_after_stim': [10.0] } features = ['decay_time_constant_after_stim'] feature_values = efel.getFeatureValues([trace], features)[0] nt.assert_almost_equal( 20.0, feature_values['decay_time_constant_after_stim'][0], places=1)
def test_strict_stiminterval(): """basic: Test strict_stiminterval""" import efel for strict, n_of_spikes in [(False, 5), (True, 3)]: efel.reset() efel.setIntSetting("strict_stiminterval", strict) stim_start = 600.0 stim_end = 750.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['peak_indices', 'peak_time', 'Spikecount'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) peak_indices = feature_values[0]['peak_indices'] peak_time = feature_values[0]['peak_time'] spikecount = feature_values[0]['Spikecount'] nt.assert_equal(len(peak_indices), n_of_spikes) nt.assert_equal(len(peak_time), n_of_spikes) nt.assert_equal(spikecount, n_of_spikes)
def test_min_AHP_indices_strict(): """basic: Test min_AHP_indices with strict_stiminterval""" import efel for strict, n_of_ahp in [(False, 17), (True, 16)]: efel.reset() efel.setIntSetting('strict_stiminterval', strict) stim_start = 700.0 stim_end = 2700.0 time = efel.io.load_fragment('%s#col=1' % ahptest1_url) voltage = efel.io.load_fragment('%s#col=2' % ahptest1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['min_AHP_indices', 'AHP_time_from_peak', 'peak_time'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) min_AHP_indices = feature_values[0]['min_AHP_indices'] AHP_time_from_peak = feature_values[0]['AHP_time_from_peak'] nt.assert_equal(len(min_AHP_indices), n_of_ahp) nt.assert_equal(len(AHP_time_from_peak), n_of_ahp)
def test_mean_frequency1(): """basic: Test mean_frequency 1""" import efel efel.reset() trace, time, voltage, stim_start, stim_end = load_data( 'mean_frequency1', interp=True) features = ['mean_frequency', 'peak_time'] feature_values = \ efel.getFeatureValues( [trace], features) peak_times = feature_values[0]['peak_time'] stim_spikes = peak_times[numpy.where((stim_start <= peak_times) & (peak_times <= stim_end))] n_of_spikes = len(stim_spikes) mean_frequency = float(n_of_spikes) * 1000 / \ (stim_spikes[-1] - stim_start) nt.assert_almost_equal( feature_values[0]['mean_frequency'][0], mean_frequency)
def test_min_AHP_indices(): """basic: Test min_AHP_indices""" import efel efel.reset() stim_start = 650.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['min_AHP_indices'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) min_AHP_indices = feature_values[0]['min_AHP_indices'] nt.assert_equal(len(min_AHP_indices), 5)
def test_mean_frequency1(): """basic: Test mean_frequency 1""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['mean_frequency'] feature_values = \ efel.getFeatureValues( [trace], features) nt.assert_almost_equal(feature_values[0]['mean_frequency'][0], 15.2858453)
def test_mean_frequency1(): """basic: Test mean_frequency 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 test_data_path = joinp(testdata_dir, 'basic', 'mean_frequency_1.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['mean_frequency'] feature_values = \ efel.getFeatureValues( [trace], features) nt.assert_almost_equal(feature_values[0]['mean_frequency'][0], 15.2858453)
def test_spikecount2(): """basic: Test Spikecount 2: test empty trace""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 time = numpy.arange(0, 1000.0, 0.1) voltage = numpy.ones(len(time)) * -80.0 trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['Spikecount'] feature_values = \ efel.getFeatureValues( [trace], features) spikecount = feature_values[0]['Spikecount'][0] nt.assert_equal(spikecount, 0)
def test_APlast_amp(): """basic: Test APlast_amp""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_amplitude', 'APlast_amp'] feature_values = \ efel.getFeatureValues( [trace], features) APlast_amp = feature_values[0]['APlast_amp'][0] AP_amplitude = feature_values[0]['APlast_amp'] nt.assert_equal(APlast_amp, AP_amplitude[-1])
def test_ISI_log_slope_skip(): """basic: Test ISI_log_slope_skip""" import efel import numpy stim_start = 31.2 stim_end = 431.2 data = numpy.loadtxt( 'testdata/basic/zero_ISI_log_slope_skip95824004.abf.csv') time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['ISI_log_slope_skip'] import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") feature_values = \ efel.getFeatureValues( [trace], features) nt.assert_equal(feature_values[0]['ISI_log_slope_skip'], None)
def test_ap_amplitude_from_voltagebase1(): """basic: Test AP_amplitude_from_voltagebase 1""" import efel import numpy stim_start = 500.0 stim_end = 900.0 data = numpy.loadtxt('testdata/basic/mean_frequency_1.txt') time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_amplitude_from_voltagebase', 'peak_voltage', 'voltage_base'] feature_values = \ efel.getFeatureValues( [trace], features) voltage_base = feature_values[0]['voltage_base'][0] for peak_voltage, ap_amplitude_from_voltagebase in zip( feature_values[0]['peak_voltage'], feature_values[0]['AP_amplitude_from_voltagebase']): nt.assert_almost_equal(peak_voltage - voltage_base, ap_amplitude_from_voltagebase)
def test_spikecount1(): """basic: Test Spikecount 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 test_data_path = joinp(testdata_dir, 'basic', 'mean_frequency_1.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['peak_indices', 'Spikecount'] feature_values = \ efel.getFeatureValues( [trace], features) peak_indices = feature_values[0]['peak_indices'] spikecount = feature_values[0]['Spikecount'][0] nt.assert_equal(len(peak_indices), spikecount)
def test_voltagebase1(): """basic: Test voltagebase 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 test_data_path = joinp(testdata_dir, 'basic', 'mean_frequency_1.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['voltage_base'] feature_values = \ efel.getFeatureValues( [trace], features) voltage_base = numpy.mean(voltage[numpy.where( (time >= 0.9 * stim_start) & (time <= stim_start))]) nt.assert_almost_equal(voltage_base, feature_values[0]['voltage_base'][0])
def test_ohmic_input_resistance_vb_ssse(): """basic: Test ohmic_input_resistance_vb_ssse""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['ohmic_input_resistance_vb_ssse', 'voltage_deflection_vb_ssse'] stimulus_current = 10.0 efel.setDoubleSetting('stimulus_current', stimulus_current) feature_values = \ efel.getFeatureValues( [trace], features) voltage_deflection = feature_values[0]['voltage_deflection_vb_ssse'][0] ohmic_input_resistance = \ feature_values[0]['ohmic_input_resistance_vb_ssse'][0] nt.assert_equal( ohmic_input_resistance, voltage_deflection / stimulus_current)
def get_features(conductances): feature_values = collections.defaultdict(dict) traces = [] times = [] voltages = [] for step_number in range(3): time, voltage = grcsteps.steps(step_number, conductances) trace = {} # dictionary with time, voltage start and end vectors. trace['T'] = time trace['V'] = voltage trace['stim_start'] = [100] trace['stim_end'] = [500] traces = [trace] # a think is a list from a dictionary result = efel.getFeatureValues(traces, FEATURES, raise_warnings=False) for feature_name, feature_list in result[0].items(): if feature_list is not None and len(feature_list) > 0: feature_values[step_number][ feature_name] = np.mean(feature_list) else: feature_values[step_number][feature_name] = None times.append(time) voltages.append(voltage) return feature_values, times, voltages
def test_mean_frequency1(): """basic: Test mean_frequency 1""" import efel import numpy stim_start = 500.0 stim_end = 900.0 data = numpy.loadtxt('testdata/basic/mean_frequency_1.txt') time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['mean_frequency'] feature_values = \ efel.getFeatureValues( [trace], features) nt.assert_almost_equal(feature_values[0]['mean_frequency'], 15.2858453)
def test_spikecount_libv4peakindices(): """basic: Test Spikecount in combination with LibV4 peak_indices""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['peak_indices', 'Spikecount'] test_peak = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'DependencyV5_LibV4peakindices.txt') efel.setDependencyFileLocation(test_peak) feature_values = \ efel.getFeatureValues( [trace], features) peak_indices = feature_values[0]['peak_indices'] spikecount = feature_values[0]['Spikecount'][0] nt.assert_equal(len(peak_indices), 5) nt.assert_equal(len(peak_indices), spikecount)
def test_voltagebase1(): """basic: Test voltagebase 1""" import numpy import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['voltage_base'] feature_values = \ efel.getFeatureValues( [trace], features) voltage_base = numpy.mean(voltage[numpy.where( (time >= 0.9 * stim_start) & (time <= stim_start))]) nt.assert_almost_equal(voltage_base, feature_values[0]['voltage_base'][0], places=5)
def test_getmeanfeaturevalues(): """basic: Test getMeanFeatureValues""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] feature_values = \ efel.getFeatureValues( [trace], ['AP_amplitude', 'BPAPHeightLoc1'], raise_warnings=False) mean_feature_values = efel.getMeanFeatureValues( [trace], [ 'AP_amplitude', 'BPAPHeightLoc1'], raise_warnings=False) nt.assert_equal(numpy.mean(feature_values[0]['AP_amplitude']), mean_feature_values[0]['AP_amplitude'])
def test_ap_amplitude_from_voltagebase1(): """basic: Test AP_amplitude_from_voltagebase 1""" import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_amplitude_from_voltagebase', 'peak_voltage', 'voltage_base'] feature_values = \ efel.getFeatureValues( [trace], features) voltage_base = feature_values[0]['voltage_base'][0] for peak_voltage, ap_amplitude_from_voltagebase in zip( feature_values[0]['peak_voltage'], feature_values[0]['AP_amplitude_from_voltagebase']): nt.assert_almost_equal(peak_voltage - voltage_base, ap_amplitude_from_voltagebase)
def test_APlast_amp(): """basic: Test APlast_amp""" import efel import numpy stim_start = 500.0 stim_end = 900.0 data = numpy.loadtxt('testdata/basic/mean_frequency_1.txt') time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_amplitude', 'APlast_amp'] feature_values = \ efel.getFeatureValues( [trace], features) APlast_amp = feature_values[0]['APlast_amp'][0] AP_amplitude = feature_values[0]['APlast_amp'] nt.assert_equal(APlast_amp, AP_amplitude[-1])
def test_ISI_semilog_slope(): """basic: Test ISI_semilog_slope""" import numpy import efel efel.reset() stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['ISI_values', 'ISI_semilog_slope'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) isi_values = feature_values[0]['ISI_values'] x_values = numpy.arange(0, len(isi_values)) + 1.0 # fit x_values = x_values log_isi_values = numpy.log(isi_values) slope, _ = numpy.polyfit(x_values, log_isi_values, 1) nt.assert_almost_equal(feature_values[0]['ISI_semilog_slope'][0], slope)
def test_zero_ISI_log_slope_skip(): """basic: Test zero ISI_log_slope_skip""" import efel efel.reset() stim_start = 31.2 stim_end = 431.2 time = efel.io.load_fragment('%s#col=1' % zeroISIlog1_url) voltage = efel.io.load_fragment('%s#col=2' % zeroISIlog1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['ISI_log_slope_skip'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) nt.assert_equal(feature_values[0]['ISI_log_slope_skip'], None)
def analyse_RmpRiTau_trace(time, soma_voltage, stim_start, stim_end, current_amplitude): """Analyse the output of the RmpRiTau protocol""" # Import the eFeature Extraction Library import efel # Prepare the trace data trace = {} trace['T'] = time trace['V'] = soma_voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] # Calculate the necessary eFeatures efel_results = efel.getFeatureValues([trace], [ 'voltage_base', 'steady_state_voltage_stimend', 'decay_time_constant_after_stim' ]) voltage_base = efel_results[0]['voltage_base'][0] ss_voltage = efel_results[0]['steady_state_voltage_stimend'][0] dct = efel_results[0]['decay_time_constant_after_stim'][0] # Calculate input resistance input_resistance = float(ss_voltage - voltage_base) / current_amplitude rmpritau_dict = {} rmpritau_dict['Rmp'] = '%.6g' % voltage_base rmpritau_dict['Rmp_Units'] = 'mV' rmpritau_dict['Rin'] = '%.6g' % input_resistance rmpritau_dict['Rin_Units'] = 'MOhm' rmpritau_dict['Tau'] = '%.6g' % dct rmpritau_dict['Tau_Units'] = 'ms' print('Resting membrane potential is %s %s' % (rmpritau_dict['Rmp'], rmpritau_dict['Rmp_Units'])) print('Input resistance is %s %s' % (rmpritau_dict['Rin'], rmpritau_dict['Rin_Units'])) print('Time constant is %s %s' % (rmpritau_dict['Tau'], rmpritau_dict['Tau_Units'])) import json with open('rmp_ri_tau.json', 'w') as rmpritau_json_file: json.dump(rmpritau_dict, rmpritau_json_file, sort_keys=True, indent=4, separators=(',', ': '))
def generate_prediction(self, model: sciunit.Model, verbose: bool = False) -> float: efel.reset() stim_start = 10.0 # ms stim_dur = 50.0 # ms stim_amp = -1.0 # nA efel.setDoubleSetting('stimulus_current', stim_amp) model.inject_soma_square_current(current={'delay':stim_start, 'duration':stim_dur, 'amplitude':stim_amp}) trace = model.get_soma_membrane_potential_eFEL_format(tstop=stim_start+stim_dur+stim_start, start=stim_start, stop =stim_start+stim_dur) prediction = efel.getFeatureValues([trace], ['ohmic_input_resistance_vb_ssse'])[0]["ohmic_input_resistance_vb_ssse"][0] return prediction
def eval_efel(feature_name, target, data, dt=0.02, stims=None, index=None): def diff_lists(lis1, lis2): if lis1 is None and lis2 is None: return 0 if lis1 is None: lis1 = [0] if lis2 is None: lis2 = [0] len1, len2 = len(lis1), len(lis2) if len1 > len2: lis2 = np.concatenate((lis2, np.zeros(len1 - len2)), axis=0) if len2 > len1: lis1 = np.concatenate((lis1, np.zeros(len2 - len1)), axis=0) return np.sqrt(safe_mean((lis1 - lis2)**2)) all_features = [] time = np.cumsum([dt for i in range(time_stamps)]) curr_trace_target, curr_trace_data = {}, {} stim_start, stim_end = starting_time_stamp*dt, ending_time_stamp*dt curr_trace_target['T'] = time curr_trace_target['V'] = target curr_trace_target['stim_start'] = [stim_start] curr_trace_target['stim_end'] = [stim_end] traces = [curr_trace_target] nan_inds_bol = np.isnan(data).any(axis=1) nan_inds = [i for i, x in enumerate(nan_inds_bol) if x] #testing if len(nan_inds) > 0: print(nan_inds, "nan inds") data = np.delete(data,nan_inds,axis=1) for i in range(len(data)): curr_trace_data = {} curr_trace_data['T'] = time curr_trace_data['V'] = data[i,:] if len(data[i,:]) != 10000 or len(curr_trace_data['V']) != 10000: print(len(data[i,:])) #print(data[i,9980:9990], 'at', i) print(np.where(np.isnan(data[i,:]))) #print(len(curr_trace_data['V'])) print(1/0) curr_trace_data['stim_start'] = [stim_start] curr_trace_data['stim_end'] = [stim_end] traces.append(curr_trace_data) efelstart = timer.time() traces_results = efel.getFeatureValues(traces, [feature_name], raise_warnings=False) #print("EFEL eval took: ", timer.time()-efelstart) diff_features = [] for i in range(len(data)): #testing diff_features.append(diff_lists(traces_results[0][feature_name], traces_results[i+1][feature_name])) return diff_features
def sag_ratio1(hyper_num): sag_ratio=efel.getFeatureValues(hyper_sweeps,['sag_ratio1']) sum=0 for i in range(0,hyper_num): sag=sag_ratio[i] sag['sag_ratio1']=np.append(sag['sag_ratio1'],[]) sag=sag['sag_ratio1'] if sag.all(): sag=sag[0] else: sag=0 sum=sum+sag average=sum/hyper_num return average
def _test_expected_value(feature_name, expected_values): """Test expected values for feature""" for trace_name, expected_value in expected_values.items(): trace = _load_trace(trace_name) feature_values = efel.getFeatureValues([trace], [feature_name]) if expected_value is None: nt.assert_true(feature_values[0][feature_name] is None) else: nt.assert_true( numpy.allclose(feature_values[0][feature_name], expected_value))
def ave_sag_amplitude(hyper_num): sag_amplitude=efel.getFeatureValues(hyper_sweeps,['sag_amplitude']) sum=0 for i in range(0,hyper_num): sag_amp=sag_amplitude[i] sag_amp['sag_amplitude']=np.append(sag_amp['sag_amplitude'],[]) sag_amp=sag_amp['sag_amplitude'] if sag_amp.all(): sag_amp=sag_amp[0] else: sag_amp=0 sum=sum+sag_amp average=sum/hyper_num return average
def more_challenging(model): ''' Isolate harder code, still wrangling data types. When this is done, EFEL might be able to report back about input resistance. ''' single_spike = {} single_spike['APWaveForm'] = [float(v) for v in model.vm_rheobase] #temp_vm single_spike['T'] = [ float(t) for t in model.vm_rheobase.times.rescale('ms') ] single_spike['V'] = [float(v) for v in model.vm_rheobase] #temp_vm single_spike['stim_start'] = [float(model.protocol['Time_Start'])] single_spike['stimulus_current'] = [model.model.rheobase_current] single_spike['stim_end'] = [trace15['T'][-1]] single_spike = [single_spike] ## # How EFEL could learn about input resistance of model ## trace_ephys_prop = {} trace_ephys_prop[ 'stimulus_current'] = model.druckmann2013_input_resistance_currents[ 0] # = druckmann2013_input_resistance_currents[0] trace_ephys_prop['V'] = [float(v) for v in model.vminh] trace_ephys_prop['T'] = [float(t) for t in model.vminh.times.rescale('ms')] trace_ephys_prop['stim_end'] = [trace15['T'][-1]] trace_ephys_prop['stim_start'] = [float(model.inh_protocol['Time_Start']) ] # = in_current_filter[0]['Time_End'] trace_ephys_props = [trace_ephys_prop] efel_results_inh = efel.getFeatureValues(trace_ephys_props, list(efel.getFeatureNames())) # efel_results_ephys = efel.getFeatureValues(trace_ephys_prop, list(efel.getFeatureNames())) # return efel_results_inh
def evaluate(individual, target_voltage1=-80, target_voltage2=-60): """ Evaluate a neuron model with parameters e_pas and g_pas, extracts features from resulting traces and returns a tuple with abs(voltage_base-target_voltage1) and abs(steady_state_voltage-target_voltage2) """ neuron.h.v_init = target_voltage1 soma = neuron.h.Section() soma.insert('pas') soma.g_pas = individual[0] soma.e_pas = individual[1] clamp = neuron.h.IClamp(0.5, sec=soma) stim_start = 500 stim_end = 1000 clamp.amp = 1.0 clamp.delay = stim_start clamp.dur = 100000 voltage = neuron.h.Vector() voltage.record(soma(0.5)._ref_v) time = neuron.h.Vector() time.record(neuron.h._ref_t) neuron.h.tstop = stim_end neuron.h.run() trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] traces = [trace] features = efel.getFeatureValues(traces, ["voltage_base", "steady_state_voltage"]) voltage_base = features[0]["voltage_base"][0] steady_state_voltage = features[0]["steady_state_voltage"][0] return abs(target_voltage1 - voltage_base), \ abs(target_voltage2 - steady_state_voltage)
def test_AP_begin_indices1(): """basic: Test AP_begin_indices 1""" import efel efel.reset() import numpy stim_start = 31.2 stim_end = 431.2 test_data_path = os.path.join( testdata_dir, 'basic', 'AP_begin_indices_95810005.abf.csv') voltage = numpy.loadtxt(test_data_path) time = numpy.arange(len(voltage)) * 0.1 trace = {} trace['V'] = voltage trace['T'] = time trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = [ 'AP_begin_indices', 'AP_amplitude', 'peak_time', 'AP_duration_half_width'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) # Make sure the amount of peak_times, AP_begin_indices and AP_amplitude is # the same in this trace # There was originally an issue in this case due to the 'width' value # in AP_begin_indices, which caused a segmentation fault nt.assert_equal( len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['AP_amplitude'])) nt.assert_equal( len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['peak_time'])) nt.assert_equal( len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['AP_duration_half_width']))
def spikecount(self, delay, duration, soma_trace): trace = {} traces=[] trace['T'] = soma_trace[0] trace['V'] = soma_trace[1] trace['stim_start'] = [delay] trace['stim_end'] = [delay + duration] traces.append(trace) traces_results = efel.getFeatureValues(traces, ['Spikecount']) spikecount = traces_results[0]['Spikecount'] return spikecount
def generate_prediction(self, model: sciunit.Model, verbose: bool = False) -> Optional[float]: efel.reset() stim_start = 10.0 # ms stim_dur = 5.0 # ms stim_amp = 15.0 # nA efel.setDoubleSetting('stimulus_current', stim_amp) model.inject_soma_square_current(current={'delay':stim_start, 'duration':stim_dur, 'amplitude':stim_amp}) trace = model.get_soma_membrane_potential_eFEL_format(tstop=stim_start+stim_dur+stim_start, start=stim_start, stop =stim_start+stim_dur) output = efel.getFeatureValues([trace], ['AP_duration_half_width'])[0]["AP_duration_half_width"] prediction = output[0] if output else None return prediction
def get_sag_curve(nwbfile, fmtkey, ic_stim, stim_start=5000, stim_end=7000): ii = [] ss = [] for _ic_stim in ic_stim: trace = analysis.read_trace(nwbfile, fmtkey % abs(_ic_stim), stim_start=stim_start, stim_end=stim_end) ii.append(_ic_stim) ss.append(100 * (1 - efel.getFeatureValues( [trace], ['sag_ratio2'])[0]['sag_ratio2'][0])) return np.array(ii).T, np.array(ss).T
def cclamp(self, model, amp, delay, dur): if self.base_directory: self.path_temp_data = self.base_directory + 'temp_data/' + 'depol_block/' + model.name + '/' else: self.path_temp_data = model.base_directory + 'temp_data/' + 'depol_block/' try: if not os.path.exists(self.path_temp_data) and self.save_all: os.makedirs(self.path_temp_data) except OSError as e: if e.errno != 17: raise pass file_name = self.path_temp_data + 'cclamp_' + str(amp) + '.p' if self.force_run or (os.path.isfile(file_name) is False): trace = {} traces=[] t, v = model.get_vm(amp, delay, dur, 'soma', 0.5, 'soma', 0.5) #print "- running amplitude: " + str(amp) + " on model: " + model.name + " at: " + str(model.soma) + "(" + str(0.5) + ")" #t, v = model.run_cclamp() trace['T'] = t trace['V'] = v trace['stim_start'] = [delay] trace['stim_end'] = [delay + dur] traces.append(trace) traces_results = efel.getFeatureValues(traces, ['Spikecount']) traces.append(traces_results) if self.save_all: pickle.dump(traces, gzip.GzipFile(file_name, "wb")) else: traces = pickle.load(gzip.GzipFile(file_name, "rb")) return traces
def test_failing_int_feature(): """basic: Test failing int feature""" import efel efel.reset() trace = {} trace['T'] = numpy.arange(0, 100, 0.1) trace['V'] = numpy.ones(len(trace['T'])) * -80.0 trace['stim_start'] = [25] trace['stim_end'] = [75] feature_value = efel.getFeatureValues( [trace], ['burst_number'], raise_warnings=False)[0]['burst_number'] nt.assert_equal(feature_value, None)
def test_decay_time_constant_after_stim2(): """basic: Test decay_time_constant_after_stim 2""" import efel efel.reset() trace, time, voltage, stim_start, stim_end = load_data( 'tau20.0', interp=True) features = ['decay_time_constant_after_stim'] feature_values = efel.getFeatureValues([trace], features)[0] nt.assert_almost_equal( 19.9, feature_values['decay_time_constant_after_stim'][0], places=1)
def main(): """Main""" # Use numpy to read the trace data from the txt file data = numpy.loadtxt(os.path.join(os.path.dirname(__file__), 'example_trace1.txt')) # Time is the first column time = data[:, 0] # Voltage is the second column voltage = data[:, 1] # Now we will construct the datastructure that will be passed to eFEL # A 'trace' is a dictionary trace1 = {} # Set the 'T' (=time) key of the trace trace1['T'] = time # Set the 'V' (=voltage) key of the trace trace1['V'] = voltage # Set the 'stim_start' (time at which a stimulus starts, in ms) # key of the trace # Warning: this need to be a list (with one element) trace1['stim_start'] = [700] # Set the 'stim_end' (time at which a stimulus end) key of the trace # Warning: this need to be a list (with one element) trace1['stim_end'] = [2700] # Multiple traces can be passed to the eFEL at the same time, so the # argument should be a list traces = [trace1] # Now we pass 'traces' to the efel and ask it to calculate the feature # values traces_results = efel.getFeatureValues(traces, ['AP_amplitude', 'voltage_base']) # The return value is a list of trace_results, every trace_results # corresponds to one trace in the 'traces' list above (in same order) for trace_results in traces_results: # trace_result is a dictionary, with as keys the requested features for feature_name, feature_values in trace_results.items(): print("Feature %s has the following values: %s" % \ (feature_name, ', '.join([str(x) for x in feature_values])))
def test_interpolate(): """basic: Test interpolate""" import efel efel.reset() trace, time, voltage, stim_start, stim_end = load_data('mean_frequency1', interp=True) features = ['voltage'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) interp_voltage = feature_values[0]['voltage'] nt.assert_equal(len(interp_voltage), len(voltage)) nt.assert_true(numpy.allclose(interp_voltage, voltage))
def _calculate_features(self, recordings): """For each recorded step, calculate the features.""" features_from_simulation = {} for segment in recordings.segments: step_name = segment.name feature_names = self.observation[step_name].keys() trace = { 'T': segment.analogsignals[0].times.rescale('ms').magnitude, 'V': segment.analogsignals[0].rescale('mV').magnitude, 'stim_start': [segment.epochs[0].times], 'stim_end': [segment.epochs[0].times + segment.epochs[0].durations] } features = efel.getFeatureValues([trace], feature_names)[0] features_from_simulation[step_name] = dict([(k, {'value': v[0]}) for k, v in features.items()]) return features_from_simulation
def extract_somatic_spiking_features(self, traces, delay, duration): # soma trace = {} traces_for_efel = [] trace['T'] = traces['T'] trace['V'] = traces['v_stim'] trace['stim_start'] = [delay] trace['stim_end'] = [delay + duration] traces_for_efel.append(trace) efel.setDoubleSetting('interp_step', 0.025) efel.setDoubleSetting('DerivativeThreshold', 40.0) traces_results = efel.getFeatureValues( traces_for_efel, ['inv_first_ISI', 'AP_begin_time', 'doublet_ISI']) return traces_results
def test_steady_state_voltage1(): """basic: Test steady_state_voltage""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 test_data_path = os.path.join( testdata_dir, 'basic', 'mean_frequency_1.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['steady_state_voltage'] feature_values = \ efel.getFeatureValues( [trace], features)[0] begin_time = stim_end end_time = max(time) steady_state_voltage = numpy.mean(voltage[numpy.where( (time <= end_time) & (time > begin_time) )]) nt.assert_almost_equal(steady_state_voltage, feature_values['steady_state_voltage'][0])
def test_decay_time_constant_after_stim1(): """basic: decay_time_constant_after_stim 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 test_data_path = os.path.join( testdata_dir, 'basic', 'mean_frequency_1.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = { 'T': time, 'V': voltage, 'stim_start': [stim_start], 'stim_end': [stim_end], } features = ['decay_time_constant_after_stim'] feature_values = efel.getFeatureValues([trace], features)[0] expected = decay_time_constant_after_stim( trace['T'], trace['V'], stim_end + 1.0, stim_end + 10.0, trace['stim_start'][0], trace['stim_end'][0]) nt.assert_almost_equal( expected, feature_values['decay_time_constant_after_stim'][0])
def _get_peak_times(self, responses, raise_warnings=False): efel_trace = self._construct_somatic_efel_trace(responses) if efel_trace is None: peak_times = None else: self._setup_efel() import efel peaks = efel.getFeatureValues( [efel_trace], ["peak_time"], raise_warnings=raise_warnings ) peak_times = peaks[0]["peak_time"] efel.reset() return peak_times
def test_decay_time_constant_after_stim1(): """basic: Test decay_time_constant_after_stim 1""" import efel efel.reset() trace, time, voltage, stim_start, stim_end = load_data('mean_frequency1', interp=True) features = ['decay_time_constant_after_stim'] feature_values = efel.getFeatureValues([trace], features)[0] expected = decay_time_constant_after_stim(time, voltage, stim_end + 1.0, stim_end + 10.0, stim_start, stim_end) nt.assert_almost_equal(expected, feature_values['decay_time_constant_after_stim'][0])
def test_AP_begin_indices1(): """basic: Test AP_begin_indices 1""" import efel efel.reset() import numpy stim_start = 31.2 stim_end = 431.2 voltage = numpy.loadtxt('testdata/basic/AP_begin_indices_95810005.abf.csv') time = numpy.arange(len(voltage)) * 0.1 trace = {} trace['V'] = voltage trace['T'] = time trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = [ 'AP_begin_indices', 'AP_amplitude', 'peak_time', 'AP_duration_half_width' ] import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") feature_values = \ efel.getFeatureValues( [trace], features) # Make sure the amount of peak_times, AP_begin_indices and AP_amplitude is # the same in this trace # There was originally an issue in this case due to the 'width' value # in AP_begin_indices, which caused a segmentation fault nt.assert_equal(len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['AP_amplitude'])) nt.assert_equal(len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['peak_time'])) nt.assert_equal(len(feature_values[0]['AP_begin_indices']), len(feature_values[0]['AP_duration_half_width']))
def test_min_voltage_between_spikes1(): """basic: Test min_voltage_between_spikes 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 time = efel.io.load_fragment('%s#col=1' % meanfrequency1_url) voltage = efel.io.load_fragment('%s#col=2' % meanfrequency1_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['min_voltage_between_spikes', 'peak_indices', 'voltage'] feature_values = \ efel.getFeatureValues( [trace], features) peak_indices = feature_values[0]['peak_indices'] min_voltage_between_spikes = feature_values[ 0]['min_voltage_between_spikes'] fel_voltage = feature_values[0]['voltage'] for index, min_voltage_between_spikes_value in zip( list(range(len(peak_indices[:-1]))), min_voltage_between_spikes): nt.assert_almost_equal( numpy.min( fel_voltage[ peak_indices[index]:peak_indices[ index + 1]]), min_voltage_between_spikes_value)
def extract_demo_ap_features(file, features, extract_average=False): """Extract electrophysiological features from an abf file about AP recording. features: list. All features to be extracted. extrace_average: Average the values of the same sweep.""" result = [] visited = [] for f in file: traces = abf2trace(f) cellid = getCellID(f) if cellid in visited: continue cur_result = efel.getFeatureValues(traces, features, raise_warnings=False) cur_result = {cellid: cur_result} visited.append(cellid) if not extract_average: result.append( pd.DataFrame( ((cellid, ind + 1, itemk, itemv[0]) if itemv else (cellid, ind + 1, itemk, None) for cellid, v in cur_result.items() for ind, vv in enumerate(v) for itemk, itemv in vv.items()), columns=["CellID", "trace", "featureName", "featureValue"], )) else: with warnings.catch_warnings(): warnings.simplefilter('ignore') result.append( pd.DataFrame( ((cellid, ind + 1, "mean_" + itemk, itemv.mean()) if isinstance(itemv, np.ndarray) else (cellid, ind + 1, itemk, None) for cellid, v in cur_result.items() for ind, vv in enumerate(v) for itemk, itemv in vv.items()), columns=[ "CellID", "trace", "featureName", "featureValue" ], )) return pd.concat(result, ignore_index=True)
def test_steady_state_voltage1(): """basic: Test steady_state_voltage""" import efel efel.reset() trace, time, voltage, stim_start, stim_end = load_data( 'mean_frequency1', interp=True) features = ['steady_state_voltage'] feature_values = \ efel.getFeatureValues( [trace], features)[0] steady_state_voltage = numpy.mean(voltage[numpy.where(time >= stim_end)]) nt.assert_almost_equal(steady_state_voltage, feature_values['steady_state_voltage'][0])
def test_spikecount_stimint1(): """basic: Test Spikecount_stimint 1""" import numpy import efel efel.reset() stim_start = 700.0 stim_end = 2700.0 time = efel.io.load_fragment('%s#col=1' % spikeoutsidestim_url) voltage = efel.io.load_fragment('%s#col=2' % spikeoutsidestim_url) trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['peak_time', 'Spikecount_stimint', 'Spikecount'] feature_values = \ efel.getFeatureValues( [trace], features) peak_times = feature_values[0]['peak_time'] spikecount = feature_values[0]['Spikecount'][0] spikecount_stimint = feature_values[0]['Spikecount_stimint'][0] interval_peaktimes, = \ numpy.where((peak_times >= stim_start) & (peak_times <= stim_end)) nt.assert_equal( len(interval_peaktimes), spikecount_stimint) nt.assert_equal( spikecount, spikecount_stimint + 2)
def test_min_voltage_between_spikes1(): """basic: Test min_voltage_between_spikes 1""" import efel efel.reset() import numpy stim_start = 500.0 stim_end = 900.0 data = numpy.loadtxt('testdata/basic/mean_frequency_1.txt') time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['min_voltage_between_spikes', 'peak_indices', 'voltage'] feature_values = \ efel.getFeatureValues( [trace], features) peak_indices = feature_values[0]['peak_indices'] min_voltage_between_spikes = feature_values[0][ 'min_voltage_between_spikes'] fel_voltage = feature_values[0]['voltage'] for index, min_voltage_between_spikes_value in zip( range(len(peak_indices[:-1])), min_voltage_between_spikes): nt.assert_almost_equal( numpy.min(fel_voltage[peak_indices[index]:peak_indices[index + 1]]), min_voltage_between_spikes_value)
def test_ap_amplitude_outside_stim(): """basic: Test AP amplitude with spike outside stim""" import efel efel.reset() import numpy stim_start = 700.0 stim_end = 2700.0 test_data_path = os.path.join( testdata_dir, 'basic', 'spike_outside_stim.txt') data = numpy.loadtxt(test_data_path) time = data[:, 0] voltage = data[:, 1] trace = {} trace['T'] = time trace['V'] = voltage trace['stim_start'] = [stim_start] trace['stim_end'] = [stim_end] features = ['AP_amplitude', 'peak_time'] feature_values = \ efel.getFeatureValues( [trace], features, raise_warnings=False) # Make sure AP_amplitude doesn't pick up the two spikes outside of # the stimulus # (which are present in peak_time) nt.assert_equal( len(feature_values[0]['AP_amplitude']) + 2, len(feature_values[0]['peak_time']))