Skip to content

Commit

Permalink
Merge branch 'master' into fix-slowtime
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienJaquier authored May 21, 2024
2 parents 8ba9a9b + 85f69f5 commit 434f8b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions efel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ def get_mean_feature_values(
return featureDicts # type: ignore


def register_feature(feature_function: Callable):
"""Register a new feature."""
pyfeatures.all_pyfeatures.append(feature_function.__name__)
setattr(pyfeatures, feature_function.__name__, feature_function)


reset()


Expand Down
27 changes: 27 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from efel.api import get_feature_values
from efel.api import set_setting
from efel.api import get_distance
from efel.api import register_feature


testdata_dir = Path(__file__).parent / 'testdata'
Expand Down Expand Up @@ -4522,3 +4523,29 @@ def test_spontaneous_firing():
numpy.testing.assert_allclose(ap_fall_time, ap_fall_time_expected)
numpy.testing.assert_allclose(ap_rise_rate, ap_rise_rate_expected)
numpy.testing.assert_allclose(ap_fall_rate, ap_fall_rate_expected)


def test_register_feature():
"""basic: Test register 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]

def new_feature():
v = efel.pyfeatures.get_cpp_feature("voltage")
stim_start = efel.pyfeatures.pyfeatures._get_cpp_data("stim_start")
return numpy.array([v[0], stim_start])

efel.register_feature(new_feature)
result = efel.get_feature_values([trace], ["new_feature"])[0]["new_feature"]
assert result[0] == -80.0
assert result[1] == 25.0

# remove it to keep other tests untouched
del efel.pyfeatures.new_feature
del efel.pyfeatures.all_pyfeatures[-1]

0 comments on commit 434f8b3

Please sign in to comment.