Skip to content

Commit

Permalink
move burst_number and strict_burst_number to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Jan 5, 2024
1 parent eebc16e commit 31b7212
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 41 deletions.
8 changes: 4 additions & 4 deletions docs/source/eFeatures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ The burst detection can be fine-tuned by changing the setting strict_burst_facto
)
)

`LibV1`_ : burst_number
~~~~~~~~~~~~~~~~~~~~~~~
`Python efeature`_ : burst_number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The number of bursts

Expand All @@ -413,8 +413,8 @@ The number of bursts

burst_number = len(burst_mean_freq)

`LibV5`_ : strict_burst_number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`Python efeature`_ : strict_burst_number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The number of bursts

Expand Down
2 changes: 0 additions & 2 deletions efel/DependencyV5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ LibV1:adaptation_index2 #LibV1:peak_time #LibV1:interpolate
LibV1:spike_width2 #LibV5:min_AHP_indices #LibV1:interpolate
LibV1:AP_width #LibV5:peak_indices #LibV5:min_AHP_indices #LibV1:interpolate
LibV1:burst_mean_freq #LibV1:burst_ISI_indices #LibV1:peak_time #LibV1:interpolate
LibV1:burst_number #LibV1:burst_mean_freq #LibV1:interpolate
LibV1:interburst_voltage #LibV1:burst_ISI_indices #LibV1:interpolate
LibV1:AP_height #LibV1:peak_voltage #LibV1:interpolate
LibV1:AP_amplitude #LibV5:AP_begin_indices #LibV1:peak_voltage #LibV1:peak_time #LibV1:interpolate
Expand Down Expand Up @@ -125,7 +124,6 @@ LibV5:AP_width_between_threshold #LibV5:min_between_peaks_indices #LibV1:inte
LibV5:burst_begin_indices #LibV5:all_ISI_values #LibV1:interpolate
LibV5:burst_end_indices #LibV5:burst_begin_indices #LibV1:interpolate
LibV5:strict_burst_mean_freq #LibV1:peak_time #LibV5:burst_begin_indices #LibV5:burst_end_indices #LibV1:interpolate
LibV5:strict_burst_number #LibV5:strict_burst_mean_freq #LibV1:interpolate
LibV5:strict_interburst_voltage #LibV5:peak_indices #LibV5:burst_begin_indices #LibV1:interpolate
LibV5:ADP_peak_indices #LibV5:min_AHP_indices #LibV5:min_between_peaks_indices #LibV1:interpolate
LibV5:ADP_peak_values #LibV5:ADP_peak_indices #LibV1:interpolate
Expand Down
2 changes: 0 additions & 2 deletions efel/cppcore/FillFptrTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ int FillFptrTable() {
FptrTableV1["AHP_slow_time"] = &LibV1::AHP_slow_time;
FptrTableV1["AHP_depth"] = &LibV1::AHP_depth;
FptrTableV1["AHP_depth_slow"] = &LibV1::AHP_depth_slow;
FptrTableV1["burst_number"] = &LibV1::burst_number;
FptrTableV1["AP_amplitude_diff"] = &LibV1::AP_amplitude_diff;
FptrTableV1["AHP_depth_diff"] = &LibV1::AHP_depth_diff;

Expand Down Expand Up @@ -210,7 +209,6 @@ int FillFptrTable() {
FptrTableV5["burst_begin_indices"] = &LibV5::burst_begin_indices;
FptrTableV5["burst_end_indices"] = &LibV5::burst_end_indices;
FptrTableV5["strict_burst_mean_freq"] = &LibV5::strict_burst_mean_freq;
FptrTableV5["strict_burst_number"] = &LibV5::strict_burst_number;
FptrTableV5["strict_interburst_voltage"] = &LibV5::strict_interburst_voltage;

FptrTableV5["ADP_peak_indices"] = &LibV5::ADP_peak_indices;
Expand Down
11 changes: 0 additions & 11 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,6 @@ int LibV1::burst_mean_freq(mapStr2intVec& IntFeatureData,
return retVal;
}

int LibV1::burst_number(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
const auto& doubleFeatures =
getFeatures(DoubleFeatureData, {"burst_mean_freq"});
vector<int> BurstNum;
BurstNum.push_back(doubleFeatures.at("burst_mean_freq").size());
setVec(IntFeatureData, StringData, "burst_number", BurstNum);
return BurstNum.size();
}

// reminder: first ISI value is ignored in burst_ISI_indices if IgnoreFirstISI=1
static int __interburst_voltage(const vector<int>& BurstIndex,
const vector<int>& PeakIndex,
Expand Down
2 changes: 0 additions & 2 deletions efel/cppcore/LibV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ int AHP_depth(mapStr2intVec& IntFeatureData,
int AHP_depth_slow(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
int burst_number(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);
int AP_amplitude_diff(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
Expand Down
11 changes: 0 additions & 11 deletions efel/cppcore/LibV5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,17 +2258,6 @@ int LibV5::strict_burst_mean_freq(mapStr2intVec& IntFeatureData,
return retVal;
}

int LibV5::strict_burst_number(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
const auto& doubleFeatures =
getFeatures(DoubleFeatureData, {"strict_burst_mean_freq"});
vector<int> BurstNum;
BurstNum.push_back(doubleFeatures.at("strict_burst_mean_freq").size());
setVec(IntFeatureData, StringData, "strict_burst_number", BurstNum);
return BurstNum.size();
}

static int __strict_interburst_voltage(const vector<int>& burst_begin_indices,
const vector<int>& PeakIndex,
const vector<double>& T,
Expand Down
3 changes: 0 additions & 3 deletions efel/cppcore/LibV5.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ int burst_end_indices(mapStr2intVec& IntFeatureData,
int strict_burst_mean_freq(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
int strict_burst_number(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
int strict_interburst_voltage(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
Expand Down
2 changes: 0 additions & 2 deletions efel/cppcore/cfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ void cFeature::fillfeaturetypes() {
featuretypes["amp_drop_second_last"] = "double";
featuretypes["max_amp_difference"] = "double";
featuretypes["depolarized_base"] = "double";
featuretypes["burst_number"] = "int";

// LibV5
featuretypes["ISI_log_slope"] = "double";
Expand Down Expand Up @@ -212,7 +211,6 @@ void cFeature::fillfeaturetypes() {
featuretypes["burst_begin_indices"] = "int";
featuretypes["burst_end_indices"] = "int";
featuretypes["strict_burst_mean_freq"] = "double";
featuretypes["strict_burst_number"] = "int";
featuretypes["strict_interburst_voltage"] = "double";

featuretypes["ADP_peak_indices"] = "int";
Expand Down
25 changes: 25 additions & 0 deletions efel/pyfeatures/pyfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
'spikes_in_burst1_burst2_diff',
'spikes_in_burst1_burstlast_diff',
'impedance',
'burst_number',
'strict_burst_number'
]


Expand Down Expand Up @@ -92,6 +94,29 @@ def spike_count_stimint() -> numpy.ndarray:
return numpy.array([res])


def burst_number() -> numpy.ndarray:
"""The number of bursts."""
burst_mean_freq = _get_cpp_feature("burst_mean_freq")
if burst_mean_freq is None:
return numpy.array([0])
return numpy.array([burst_mean_freq.size])


def strict_burst_number() -> numpy.ndarray:
"""Calculate the strict burst number.
This implementation does not assume that every spike belongs to a burst.
The first spike is ignored by default. This can be changed by setting
ignore_first_ISI to 0.
The burst detection can be fine-tuned by changing the setting
strict_burst_factor. Default value is 2.0."""
burst_mean_freq = _get_cpp_feature("strict_burst_mean_freq")
if burst_mean_freq is None:
return numpy.array([0])
return numpy.array([burst_mean_freq.size])


def impedance():
from scipy.ndimage.filters import gaussian_filter1d

Expand Down
1 change: 0 additions & 1 deletion tests/DependencyV5_LibV5peakindices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ LibV1:adaptation_index2 #LibV1:peak_time
LibV1:spike_width2 #LibV5:min_AHP_indices
LibV1:AP_width #LibV5:peak_indices #LibV5:min_AHP_indices
LibV1:burst_mean_freq #LibV1:burst_ISI_indices #LibV1:peak_time
LibV1:burst_number #LibV1:burst_mean_freq
LibV1:interburst_voltage #LibV1:burst_ISI_indices
LibV1:AP_height #LibV1:peak_voltage
LibV1:AP_amplitude #LibV5:AP_begin_indices #LibV1:peak_voltage
Expand Down
2 changes: 1 addition & 1 deletion tests/test_allfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_allfeatures_on_constant_voltage():
"steady_state_voltage", "steady_state_voltage_stimend",
"voltage_deflection", "voltage_deflection_begin", "voltage_deflection_vb_ssse",
"depol_block", "depol_block_bool", "voltage_base", "Spikecount",
"Spikecount_stimint"
"Spikecount_stimint", "burst_number", "strict_burst_number"
]

for field in array_fields:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ def test_failing_int_feature():

feature_value = efel.getFeatureValues(
[trace],
['burst_number'], raise_warnings=False)[0]['burst_number']
['burst_number'], raise_warnings=False)[0]['burst_number'][0]

assert feature_value is None
assert feature_value == 0


def test_empty_trace():
Expand Down

0 comments on commit 31b7212

Please sign in to comment.