Skip to content

Commit

Permalink
Offer to run all implemented algos at once
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolab committed Nov 1, 2021
1 parent 83c49de commit 1f50e1c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
27 changes: 27 additions & 0 deletions dimep/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Main Access Point for DiMEP Algorithms"""
from dimep.algo import *
from dimep.version import version
from numpy import ndarray
from typing import Dict


def available() -> None:
Expand All @@ -9,3 +11,28 @@ def available() -> None:

for algo in __all__:
print(algo)


def all(trace: ndarray, tms_sampleidx: int) -> Dict[str, float]:
"""Estimate the iMEP amplitude in the given trace with all implemented algorithms
args
----
trace:ndarray
the one-dimensional (samples,) EMG signal
tms_sampleidx: int
the sample at which the TMS pulse was applied
returns
-------
estimtes: Dict[str, float]
a dictionary of estimates, with the algorithm name as key and the estimate as value
"""
from dimep.algo import __all__

out = dict()
for algo in __all__:
out[str(algo)] = eval(algo)(trace, tms_sampleidx=tms_sampleidx)
return out
2 changes: 1 addition & 1 deletion dimep/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def bw_boundaries(bools: ndarray) -> ndarray:
"""
bools = np.asarray_chkfinite(bools)
L: ndarray = np.zeros(bools.shape[0], dtype=np.int) # type: ignore
L: ndarray = np.zeros(bools.shape[0], dtype=int) # type: ignore
i: int = 0
counter: int = 0
# all values are initially zero, i.e. belong to no cluster
Expand Down
2 changes: 1 addition & 1 deletion dimep/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.1.0"
version = "0.2.0"
47 changes: 37 additions & 10 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@ List available algorithms
from dimep.api import available
available()
Mock a trace
++++++++++++

.. code-block::
# mock a single-channel EMG signal
from numpy import random
random.seed(0)
trace = random.randn(1000)
print(trace.shape)
# >>> (1000,)
and subsequently call one (or all) of the algorithms on this mock trace, where the trace is the single-channel EMG recording, tms_sampleidx marks the onset of the TMS pulse and fs is the sampling rate.

Call all implemented algorithms at once
+++++++++++++++++++++++++++++++++++++++

.. code-block::
from dimep.api import all
all(trace, tms_sampleidx=500)
# >>> {'chen': 0.0,
# 'bawa': 5.805498168821509,
# 'bradnam': 0.0,
# 'guggenberger': 0.11904591308664515,
# 'lewis': 0.0,
# 'loyda': 0.0,
# 'odergren': 0.0,
# 'rotenberg': 26.662225635355707,
# 'summers': 0.349919002236347,
# 'wassermann': 0.7782071535040253,
# 'zewdie': 0.0,
# 'ziemann': 0.0}
Access a specific algorithm
+++++++++++++++++++++++++++
Expand All @@ -21,16 +58,6 @@ Access a specific algorithm
Call a specific algorithm
+++++++++++++++++++++++++

.. code-block::
# mock a single-channel EMG signal
from numpy import random
random.seed(0)
trace = random.randn(1000)
print(trace.shape)
# >>> (1000,)
and subsequently call one of the algorithms on this mock trace, where the trace is the single-channel EMG recording, tms_sampleidx marks the onset of the TMS pulse and fs is the sampling rate.

For example, the threshold based approach by Lewis (2007)

Expand Down

0 comments on commit 1f50e1c

Please sign in to comment.