-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bpap_attenuation as a multitrace feature
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Contains the features that are computed using multiple traces.""" | ||
|
||
|
||
import numpy as np | ||
|
||
import efel | ||
|
||
|
||
def bpap_attenuation(soma_trace: dict, dendrite_trace: dict) -> float: | ||
"""Computes the attenuation of backpropagating action potential. | ||
Backpropagating action potential is the action potential that is initiated | ||
in the soma and propagates to the dendrite. The attenuation is the ratio | ||
of the amplitude of the action potential in the soma and the dendrite. | ||
The attenuation is computed by first subtracting the resting potential | ||
from the voltage traces. | ||
""" | ||
f_values = efel.getFeatureValues([soma_trace, dendrite_trace], ["voltage_base"]) | ||
vb_soma = f_values[0]["voltage_base"][0] | ||
vb_dend = f_values[1]["voltage_base"][0] | ||
v_soma = soma_trace["V"] | ||
v_dend = dendrite_trace["V"] | ||
res = (np.max(v_soma) - vb_soma) / (np.max(v_dend) - vb_dend) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Unit tests for the multitrace module.""" | ||
|
||
from pathlib import Path | ||
import efel | ||
from efel.io import load_ascii_input | ||
from efel.pyfeatures.multitrace import bpap_attenuation | ||
|
||
|
||
testdata_dir = Path(__file__).parent / "testdata" | ||
meanfrequency1_url = testdata_dir / "basic" / "mean_frequency_1.txt" | ||
|
||
|
||
def test_bpap_attenuation(): | ||
efel.reset() | ||
stim_start, stim_end = 1.0, 2.0 # dummy values not used in this feature | ||
|
||
time, voltage = load_ascii_input(meanfrequency1_url) | ||
soma_trace = dendrite_trace = { | ||
"T": time, | ||
"V": voltage, | ||
"stim_start": [stim_start], | ||
"stim_end": [stim_end], | ||
} | ||
assert bpap_attenuation(soma_trace, dendrite_trace) == 1.0 | ||
|
||
# test voltage base subtraction | ||
soma_trace = { | ||
"T": time, | ||
"V": voltage, | ||
"stim_start": [stim_start], | ||
"stim_end": [stim_end], | ||
} | ||
# subtract 10 mv from V of soma_trace | ||
soma_trace["V"] = soma_trace["V"] - 10 | ||
assert bpap_attenuation(soma_trace, dendrite_trace) == 1.0 | ||
|
||
# divide by 2 | ||
soma_trace["V"] = voltage / 2 | ||
assert bpap_attenuation(soma_trace, dendrite_trace) == 0.5 |