Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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
Exemplo n.º 5
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))
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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))
Exemplo n.º 9
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
Exemplo n.º 10
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))
Exemplo n.º 11
0
def test_pydistance():
    """pyfeatures: Test python distance against cpp version"""
    mf1_trace = _load_trace('mean_frequency1')

    feature_name = 'AP_height'
    mean = 1.0
    std = 1.0

    numpy.seterr(divide='ignore')

    # Check if cpp and python the same if:
    # - baseline
    # - std = 0.0
    # - trace_check is enabled
    # - trace_check is enabled on faulty trace
    # - trace_check is disabled on faulty trace
    for args, stim_end in [
        ((mf1_trace, feature_name, mean, std, None), 900),
        ((mf1_trace, feature_name, mean, 0.0, None), 900),
        ((mf1_trace, feature_name, mean, std, True), 900),
        ((mf1_trace, feature_name, mean, std, True), 600),
        ((mf1_trace, feature_name, mean, std, False), 600),
    ]:
        efel.reset()
        mf1_trace['stim_end'] = [stim_end]
        nt.assert_equal(efel.getDistance(*args),
                        efel.api._getDistance_cpp(*args))

    # Extra sanity checks for trace_check
    mf1_trace['stim_end'] = [600]

    efel.reset()
    nt.assert_almost_equal(
        efel.getDistance(mf1_trace, feature_name, mean, std,
                         trace_check=False), 30.422218394481284)

    efel.reset()
    nt.assert_almost_equal(
        efel.api._getDistance_cpp(mf1_trace,
                                  feature_name,
                                  mean,
                                  std,
                                  trace_check=True), 250.0)
Exemplo n.º 12
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)
Exemplo n.º 13
0
def test_pydistance_featurefail():
    """pyfeatures: Test failure of feature in getdistance"""

    mf1_trace = _load_trace('mean_frequency1')

    feature_name = 'initburst_sahp'
    mean = 1.0
    std = 1.0

    efel.reset()
    nt.assert_almost_equal(
        efel.getDistance(mf1_trace, feature_name, mean, std, trace_check=True),
        250.0)
Exemplo n.º 14
0
def test_ISIs():
    """pyfeatures: Test ISIs feature"""

    mf1_trace = _load_trace('mean_frequency1')

    feature_values = efel.getFeatureValues([mf1_trace], ['ISI_values', 'ISIs'])

    nt.assert_true(
        numpy.allclose(feature_values[0]['ISIs'][1:],
                       feature_values[0]['ISI_values']))

    nt.assert_almost_equal(efel.getDistance(mf1_trace, 'ISIs', 1.0, 1.0),
                           64.25000000001484)
Exemplo n.º 15
0
    def calculate_score(self, responses):
        """Calculate the score"""

        efel_trace = self._construct_efel_trace(responses)

        import efel

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

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

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

        return score
Exemplo n.º 16
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
Exemplo n.º 17
0
def test_getDistance1():
    """basic: Test getDistance 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]

    nt.assert_almost_equal(3.09045815935,
                           efel.getDistance(trace, 'AP_amplitude', 50, 10))