diff --git a/docs/source/eFeatures.rst b/docs/source/eFeatures.rst index 33ba0a3b..3fd66868 100644 --- a/docs/source/eFeatures.rst +++ b/docs/source/eFeatures.rst @@ -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]]) diff --git a/efel/pyfeatures/pyfeatures.py b/efel/pyfeatures/pyfeatures.py index ee86fab8..cd637b9e 100644 --- a/efel/pyfeatures/pyfeatures.py +++ b/efel/pyfeatures/pyfeatures.py @@ -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' ] @@ -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() diff --git a/efel/tests/featurenames.json b/efel/tests/featurenames.json index 6cd0a986..980bf763 100644 --- a/efel/tests/featurenames.json +++ b/efel/tests/featurenames.json @@ -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", @@ -180,4 +183,4 @@ "interburst_min_values", "time_to_interburst_min", "AHP_depth_slow" -] +] \ No newline at end of file diff --git a/efel/tests/test_basic.py b/efel/tests/test_basic.py index d48c41a6..926d1c55 100644 --- a/efel/tests/test_basic.py +++ b/efel/tests/test_basic.py @@ -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] diff --git a/efel/tests/testdata/allfeatures/expectedresults.json b/efel/tests/testdata/allfeatures/expectedresults.json index 54657f64..33c802c8 100644 --- a/efel/tests/testdata/allfeatures/expectedresults.json +++ b/efel/tests/testdata/allfeatures/expectedresults.json @@ -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 ], @@ -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 ] -} +} \ No newline at end of file