Skip to content

Commit

Permalink
add bpap_attenuation as a multitrace feature
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Jan 4, 2024
1 parent f778c6a commit eebc16e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
24 changes: 24 additions & 0 deletions efel/pyfeatures/multitrace.py
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
39 changes: 39 additions & 0 deletions tests/test_multitrace.py
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

0 comments on commit eebc16e

Please sign in to comment.