Skip to content

Commit

Permalink
Merge pull request BlueBrain#274 from AurelienJaquier/new-features
Browse files Browse the repository at this point in the history
new features comparing number of spikes across bursts
  • Loading branch information
AurelienJaquier authored Mar 17, 2023
2 parents 0d90113 + 28bf8fb commit 4654237
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 5 deletions.
38 changes: 38 additions & 0 deletions docs/source/eFeatures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,41 @@ The first spike is ignored by default. This can be changed by setting ignore_fir
for idx_begin, idx_end in zip(burst_begin_indices, burst_end_indices):
spike_per_bursts.append(idx_end - idx_begin + 1)

Python efeature: spikes_per_burst_diff
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Difference of number of spikes between each burst and the next one.

The first spike is ignored by default. This can be changed by setting ignore_first_ISI to 0.

- **Required features**: spikes_per_burst
- **Units**: constant
- **Pseudocode**: ::

spikes_per_burst[:-1] - spikes_per_burst[1:]

Python efeature: spikes_in_burst1_burst2_diff
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Difference of number of spikes between the first burst and the second one.

The first spike is ignored by default. This can be changed by setting ignore_first_ISI to 0.

- **Required features**: spikes_per_burst_diff
- **Units**: constant
- **Pseudocode**: ::

numpy.array([spikes_per_burst_diff[0]])

Python efeature: spikes_in_burst1_burstlast_diff
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Difference of number of spikes between the first burst and the last one.

The first spike is ignored by default. This can be changed by setting ignore_first_ISI to 0.

- **Required features**: spikes_per_burst
- **Units**: constant
- **Pseudocode**: ::

numpy.array([spikes_per_burst[0] - spikes_per_burst[-1]])
36 changes: 35 additions & 1 deletion efel/pyfeatures/pyfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
'initburst_sahp_ssse',
'depol_block',
'depol_block_bool',
'spikes_per_burst'
'spikes_per_burst',
'spikes_per_burst_diff',
'spikes_in_burst1_burst2_diff',
'spikes_in_burst1_burstlast_diff'
]


Expand Down Expand Up @@ -272,6 +275,37 @@ def spikes_per_burst():
return numpy.array(ap_per_bursts)


def spikes_per_burst_diff():
"""Calculate the diff between the spikes in each burst and the next one"""
spikes_per_burst_values = spikes_per_burst()
if spikes_per_burst_values is None:
return None

return spikes_per_burst_values[:-1] - spikes_per_burst_values[1:]


def spikes_in_burst1_burst2_diff():
"""Calculate the diff between the spikes in 1st and 2nd bursts"""
spikes_per_burst_diff_values = spikes_per_burst_diff()
if spikes_per_burst_diff_values is None or len(
spikes_per_burst_diff_values
) < 1:
return None

return numpy.array([spikes_per_burst_diff_values[0]])


def spikes_in_burst1_burstlast_diff():
"""Calculate the diff between the spikes in 1st and last bursts"""
spikes_per_burst_values = spikes_per_burst()
if spikes_per_burst_values is None or len(spikes_per_burst_values) < 2:
return None

return numpy.array([
spikes_per_burst_values[0] - spikes_per_burst_values[-1]
])


def _get_cpp_feature(feature_name):
"""Get cpp feature"""
cppcoreFeatureValues = list()
Expand Down
5 changes: 4 additions & 1 deletion efel/tests/featurenames.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
"spike_half_width",
"spike_width2",
"spikes_per_burst",
"spikes_per_burst_diff",
"spikes_in_burst1_burst2_diff",
"spikes_in_burst1_burstlast_diff",
"steady_state_hyper",
"steady_state_voltage",
"steady_state_voltage_stimend",
Expand Down Expand Up @@ -180,4 +183,4 @@
"interburst_min_values",
"time_to_interburst_min",
"AHP_depth_slow"
]
]
82 changes: 82 additions & 0 deletions efel/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3646,3 +3646,85 @@ def test_time_to_interburst_min():
numpy.testing.assert_allclose(
time_to_interburst_min_py, time_to_interburst_min
)


def test_spikes_per_burst_diff():
"""basic: Test spikes_per_burst_diff"""
import efel
efel.reset()

time = efel.io.load_fragment('%s#col=1' % burst1_url)
voltage = efel.io.load_fragment('%s#col=2' % burst1_url)
time, voltage = interpolate(time, voltage, 0.1)

trace = {}
trace['T'] = time
trace['V'] = voltage
trace['stim_start'] = [250]
trace['stim_end'] = [1600]

features = ['spikes_per_burst_diff']

feature_values = \
efel.getFeatureValues(
[trace],
features, raise_warnings=False)

spikes_per_burst_diff = feature_values[0]['spikes_per_burst_diff']
assert list(spikes_per_burst_diff) == [1]


def test_spikes_in_burst1_burst2_diff():
"""basic: Test spikes_in_burst1_burst2_diff"""
import efel
efel.reset()

time = efel.io.load_fragment('%s#col=1' % burst1_url)
voltage = efel.io.load_fragment('%s#col=2' % burst1_url)
time, voltage = interpolate(time, voltage, 0.1)

trace = {}
trace['T'] = time
trace['V'] = voltage
trace['stim_start'] = [250]
trace['stim_end'] = [1600]

features = ['spikes_in_burst1_burst2_diff']

feature_values = \
efel.getFeatureValues(
[trace],
features, raise_warnings=False)

spikes_in_burst1_burst2_diff = feature_values[0][
'spikes_in_burst1_burst2_diff'
]
assert list(spikes_in_burst1_burst2_diff) == [1]


def test_spikes_in_burst1_burstlast_diff():
"""basic: Test spikes_in_burst1_burstlast_diff"""
import efel
efel.reset()

time = efel.io.load_fragment('%s#col=1' % burst1_url)
voltage = efel.io.load_fragment('%s#col=2' % burst1_url)
time, voltage = interpolate(time, voltage, 0.1)

trace = {}
trace['T'] = time
trace['V'] = voltage
trace['stim_start'] = [250]
trace['stim_end'] = [1600]

features = ['spikes_in_burst1_burstlast_diff']

feature_values = \
efel.getFeatureValues(
[trace],
features, raise_warnings=False)

spikes_in_burst1_burstlast_diff = feature_values[0][
'spikes_in_burst1_burstlast_diff'
]
assert list(spikes_in_burst1_burstlast_diff) == [1]
11 changes: 8 additions & 3 deletions efel/tests/testdata/allfeatures/expectedresults.json
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,12 @@
2.6602184713542556,
2.8238770245407068
],
"spikes_per_burst": [2],
"spikes_per_burst": [
2
],
"spikes_per_burst_diff": [],
"spikes_in_burst1_burst2_diff": null,
"spikes_in_burst1_burstlast_diff": null,
"steady_state_hyper": [
-39.7063975216648
],
Expand Down Expand Up @@ -60675,10 +60680,10 @@
"interburst_min_indices": [],
"interburst_min_values": [],
"time_to_interburst_min": [],
"AHP_depth_slow":[
"AHP_depth_slow": [
28.81047723194662,
32.02907786238346,
32.65404519917785,
33.435288866699345
]
}
}

0 comments on commit 4654237

Please sign in to comment.