Example #1
0
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)
Example #2
0
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)
Example #3
0
def test_ISI_log_slope_skip():
    """basic: Test ISI_log_slope_skip"""

    import efel
    efel.reset()
    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)
Example #4
0
def test_getDistance1():
    """basic: Test getDistance 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]

    nt.assert_almost_equal(
        3.09045815935,
        efel.getDistance(
            trace,
            'AP_amplitude',
            50,
            10))
Example #5
0
def test_APlast_amp():
    """basic: Test APlast_amp"""

    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 = ['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])
Example #6
0
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)
Example #7
0
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)
Example #8
0
    def calculate_feature(self, responses, raise_warnings=False):
        """Calculate feature value"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            feature_value = None
        else:
            self._setup_efel()

            import efel
            values = efel.getMeanFeatureValues(
                [efel_trace],
                [self.efel_feature_name],
                raise_warnings=raise_warnings)
            feature_value = values[0][self.efel_feature_name]

            efel.reset()

        logger.debug(
            'Calculated value for %s: %s',
            self.name,
            str(feature_value))

        return feature_value
Example #9
0
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)
Example #10
0
def test_version():
    """basic: Test if version number exists"""

    import efel
    efel.reset()

    nt.assert_true(efel.version is not None)
Example #11
0
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)
Example #12
0
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'])
Example #13
0
def test_getDistance_error_dist():
    """basic: Test getDistance error_dist option"""

    import efel
    efel.reset()

    stim_start = 400.0
    stim_end = 500.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]

    score_normal = efel.getDistance(
        trace,
        'AP_amplitude',
        50,
        10)
    score_150 = efel.getDistance(
        trace,
        'AP_amplitude',
        50,
        10,
        error_dist=150)

    nt.assert_almost_equal(score_normal, 250)
    nt.assert_almost_equal(score_150, 150)
Example #14
0
def test_getFeatureNameExists():
    """basic: Test FeatureNameExists"""

    import efel
    efel.reset()
    nt.assert_true(efel.FeatureNameExists('voltage_base'))
    nt.assert_false(efel.FeatureNameExists('voltage_base_wrong'))
Example #15
0
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)
Example #16
0
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)
Example #17
0
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)
Example #18
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])
Example #19
0
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)
Example #20
0
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)
Example #21
0
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)
Example #22
0
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])
Example #23
0
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)
Example #24
0
def test_getDistance1():
    """basic: Test getDistance 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]

    nt.assert_almost_equal(
        3.09045815935,
        efel.getDistance(
            trace,
            'AP_amplitude',
            50,
            10))
Example #25
0
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)
Example #26
0
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)
Example #27
0
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)
Example #28
0
    def calculate_score(self, responses, trace_check=False):
        """Calculate the score"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            score = self.max_score
        else:
            self._setup_efel()

            import efel
            score = efel.getDistance(
                efel_trace,
                self.efel_feature_name,
                self.exp_mean,
                self.exp_std,
                trace_check=trace_check,
                error_dist=self.max_score
            )
            if self.force_max_score:
                score = min(score, self.max_score)

            efel.reset()

        logger.debug('Calculated score for %s: %f', self.name, score)

        return score
Example #29
0
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)
Example #30
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)
Example #31
0
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))
Example #32
0
def test_failing_double_feature():
    """basic: Test failing double 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],
        ['AP_amplitude'], raise_warnings=False)[0]['AP_amplitude']

    nt.assert_equal(feature_value, None)
Example #33
0
def test_nonexisting_feature():
    """basic: Test nonexisting 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]

    nt.assert_raises(
        TypeError,
        efel.getFeatureValues,
        [trace],
        ['nonexisting_feature'])
Example #34
0
def test_stimstart_stimend():
    """basic: Test exception when stimstart or stimend are wrong"""

    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']

    nt.assert_raises(
        Exception,
        efel.getFeatureValues, [trace], features)

    trace['stim_start'] = [stim_end]
    trace['stim_end'] = [stim_start]

    nt.assert_raises(
        Exception,
        efel.getFeatureValues, [trace], features)

    trace['stim_start'] = [stim_start, stim_end]
    trace['stim_end'] = [stim_end]

    nt.assert_raises(
        Exception,
        efel.getFeatureValues, [trace], features)

    del trace['stim_start']

    nt.assert_raises(
        Exception,
        efel.getFeatureValues, [trace], features)
Example #35
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])
Example #36
0
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])
Example #37
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
Example #38
0
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])
Example #39
0
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)
Example #40
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']))
Example #41
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

    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']))
Example #42
0
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])
Example #43
0
    def _setup_efel(self):
        """Set up efel before extracting the feature"""

        import efel

        efel.reset()

        if self.threshold is not None:
            efel.setThreshold(self.threshold)

        if self.interp_step is not None:
            efel.setDoubleSetting("interp_step", self.interp_step)

        if self.double_settings is not None:
            for setting_name, setting_value in self.double_settings.items():
                efel.setDoubleSetting(setting_name, setting_value)

        if self.int_settings is not None:
            for setting_name, setting_value in self.int_settings.items():
                efel.setIntSetting(setting_name, setting_value)
Example #44
0
    def calculate_feature(self, responses, raise_warnings=False):
        """Calculate feature value"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            feature_value = None
        else:

            import efel
            efel.reset()

            values = efel.getMeanFeatureValues([efel_trace],
                                               [self.efel_feature_name],
                                               raise_warnings=raise_warnings)
            feature_value = values[0][self.efel_feature_name]

            efel.reset()

        return feature_value
Example #45
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)
Example #46
0
def test_getDistance1():
    """basic: Test getDistance 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]

    nt.assert_almost_equal(3.09045815935,
                           efel.getDistance(trace, 'AP_amplitude', 50, 10))
    def generate_prediction(self, model: sciunit.Model) -> Dict[float, float]:
        self.traces = []
        self.run_times = {}
        efel.reset()
        stim_list = list(map(float, self.observation.keys()))
        run_stim_ = functools.partial(self.run_stim, model)

        # multiprocessing giving errors regards to [xcb] ?!
        # npool = multiprocessing.cpu_count() - 1
        # with Pool(npool, maxtasksperchild=1) as pool:
        # results = pool.map(run_stim_, stim_list, chunksize=1)

        results = []
        for stim_inj in stim_list:
            results.append(run_stim_(stim_inj))

        # construct prediction with structure similar to observation
        prediction = {}
        for ind, stim_inj in enumerate(stim_list):
            prediction[stim_inj] = results[ind]
        return prediction
Example #48
0
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)
Example #49
0
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']))
Example #50
0
def test_getDistance_trace_check():
    """basic: Test getDistance trace_check option"""

    import numpy
    import efel
    efel.reset()

    dt = 0.1

    # voltage trace at constant -70 mV
    v = numpy.zeros(int(100 / dt)) - 70.0

    # create 'spikes' at 20, 40 and 60 ms
    v[int(20 / dt):int(25 / dt)] = 20.
    v[int(40 / dt):int(45 / dt)] = 20.
    v[int(60 / dt):int(65 / dt)] = 20.

    traces = []
    trace = {}
    trace['T'] = numpy.arange(len(v)) * dt
    trace['V'] = v
    trace['stim_start'] = [10]
    trace['stim_end'] = [70]
    traces.append(trace)

    nt.assert_almost_equal(efel.getDistance(trace, 'Spikecount', 0, 1), 3.0)

    trace['stim_end'] = [50]

    efel.reset()
    nt.assert_almost_equal(
        efel.getDistance(trace, 'Spikecount', 0, 1, trace_check=False), 3.0)

    efel.reset()
    nt.assert_almost_equal(efel.getDistance(trace, 'Spikecount', 0, 1), 250.0)
Example #51
0
    def calculate_score(self, responses):
        """Calculate the score"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            score = 250.0
        else:
            import efel
            efel.reset()

            if self.threshold:
                efel.setThreshold(self.threshold)

            score = efel.getDistance(efel_trace, self.efel_feature_name,
                                     self.exp_mean, self.exp_std)

            efel.reset()

        logger.debug('Calculated score for %s: %f', self.name, score)

        return score
Example #52
0
def test_steady_state_voltage_stimend():
    """basic: steady_state_voltage_stimend 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 = ['steady_state_voltage_stimend']

    feature_values = \
        efel.getFeatureValues(
            [trace],
            features)[0]

    stim_duration = stim_end - stim_start
    begin_time = stim_end - 0.1 * stim_duration
    end_time = stim_end
    steady_state_voltage_stimend = [
        numpy.mean(voltage[numpy.where((time < end_time)
                                       & (time >= begin_time))])
    ]

    nt.assert_almost_equal(steady_state_voltage_stimend,
                           feature_values['steady_state_voltage_stimend'])
Example #53
0
    def _setup_efel(self):
        """Set up efel before extracting the feature"""

        import efel
        efel.reset()

        if self.threshold is not None:
            efel.setThreshold(self.threshold)

        if self.stimulus_current is not None:
            efel.setDoubleSetting('stimulus_current', self.stimulus_current)

        if self.interp_step is not None:
            efel.setDoubleSetting('interp_step', self.interp_step)

        if self.double_settings is not None:
            for setting_name, setting_value in self.double_settings.items():
                efel.setDoubleSetting(setting_name, setting_value)

        if not efel.FeatureNameExists(self.efel_feature_name):
            raise ValueError("eFEL doesn't have a feature called %s" %
                             self.efel_feature_name)
Example #54
0
    def calculate_feature(self, responses, raise_warnings=False):
        """Calculate feature value"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            feature_value = None
        else:
            self._setup_efel()

            import efel
            values = efel.getMeanFeatureValues([efel_trace],
                                               [self.efel_feature_name],
                                               raise_warnings=raise_warnings)
            feature_value = values[0][self.efel_feature_name]

            efel.reset()

        logger.debug('Calculated value for %s: %s', self.name,
                     str(feature_value))

        return feature_value
Example #55
0
    def calculate_score(self, responses, trace_check=False):
        """Calculate the score"""

        efel_trace = self._construct_efel_trace(responses)

        if efel_trace is None:
            score = 250.0
        else:
            self._setup_efel()

            import efel
            score = efel.getDistance(efel_trace,
                                     self.efel_feature_name,
                                     self.exp_mean,
                                     self.exp_std,
                                     trace_check=trace_check)

            efel.reset()

        logger.debug('Calculated score for %s: %f', self.name, score)

        return score
Example #56
0
def test_empty_trace():
    """basic: Test results for empty trace"""

    import efel
    efel.reset()

    import numpy

    max_time = 3000.0
    stim_start = 700.0
    stim_end = 2700.0
    dt = 0.02

    time = numpy.arange(0.0, max_time, dt)
    voltage = -80.0 * numpy.ones(len(time))

    trace = {}

    trace['T'] = time
    trace['V'] = voltage
    trace['stim_start'] = [stim_start]
    trace['stim_end'] = [stim_end]

    features = [
        'time_to_last_spike',
        'inv_time_to_first_spike',
        'inv_first_ISI',
        'inv_second_ISI',
        'inv_third_ISI',
        'inv_fourth_ISI',
        'inv_fifth_ISI',
        'inv_last_ISI']

    # efel.getFeatureValues([trace], features)

    for feature, value in \
            efel.getFeatureValues([trace], features)[0].items():

        nt.assert_equal(value[0], 0.0)
Example #57
0
def test_sag_ratio2():
    """basic: Test sag_ratio2"""

    import efel
    efel.reset()

    stim_start = 800.0
    stim_end = 3800.0

    time = efel.io.load_fragment('%s#col=1' % sagtrace1_url)
    voltage = efel.io.load_fragment('%s#col=2' % sagtrace1_url)

    trace = {}

    trace['T'] = time
    trace['V'] = voltage
    trace['stim_start'] = [stim_start]
    trace['stim_end'] = [stim_end]

    features = [
        'sag_ratio2',
        'minimum_voltage',
        'steady_state_voltage_stimend',
        'voltage_base']

    feature_values = \
        efel.getFeatureValues(
            [trace],
            features)

    steady_state_voltage_stimend = \
        feature_values[0]['steady_state_voltage_stimend'][0]
    minimum_voltage = feature_values[0]['minimum_voltage'][0]
    voltage_base = feature_values[0]['voltage_base'][0]
    sag_ratio2 = feature_values[0]['sag_ratio2'][0]
    nt.assert_equal(
        sag_ratio2,
        (voltage_base - steady_state_voltage_stimend) /
        (voltage_base - minimum_voltage))
Example #58
0
def test_maximum_voltage_from_voltagebase():
    """basic: Test maximum_voltage_from_voltagebase"""

    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 = ['maximum_voltage_from_voltagebase', 'voltage_base']

    feature_values = \
        efel.getFeatureValues(
            [trace],
            features)[0]

    maximum_voltage = numpy.max(voltage[numpy.where(
        (time <= stim_end) & (time >= stim_start)
    )])

    voltage_base = feature_values['voltage_base'][0]

    maximum_voltage_from_voltagebase = maximum_voltage - voltage_base

    nt.assert_almost_equal(
        maximum_voltage_from_voltagebase,
        feature_values['maximum_voltage_from_voltagebase'][0])
Example #59
0
def test_voltagebase1():
    """basic: Test voltagebase 1"""

    import efel
    efel.reset()

    trace, time, voltage, stim_start, stim_end = load_data(
        'mean_frequency1', interp=True)

    features = ['voltage_base']

    feature_values = \
        efel.getFeatureValues(
            [trace],
            features)

    interp_time, interp_voltage = interpolate(time, voltage, 0.1)

    voltage_base = numpy.mean(interp_voltage[numpy.where(
        (interp_time >= 0.9 * stim_start) & (interp_time <= stim_start))])

    nt.assert_almost_equal(voltage_base, feature_values[0]['voltage_base'][0],
                           places=5)
Example #60
0
    def calculate_score(self, responses, trace_check=False):
        """Calculate the score"""

        if self.efel_feature_name.startswith(
                "bpo_"):  # check if internal feature
            score = self.get_bpo_score(responses)

        elif self.exp_mean is None:
            score = 0

        else:
            efel_trace = self._construct_efel_trace(responses)

            if efel_trace is None:
                score = 250.0
            else:
                self._setup_efel()

                import efel

                score = efel.getDistance(
                    efel_trace,
                    self.efel_feature_name,
                    self.exp_mean,
                    self.exp_std,
                    trace_check=trace_check,
                    error_dist=self.max_score,
                )

                if self.force_max_score:
                    score = min(score, self.max_score)

                efel.reset()

        logger.debug("Calculated score for %s: %f", self.name, score)

        return score