Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix AHP_slow_time and min_AHP_values #394

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions efel/cppcore/SpikeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ int SpikeEvent::burst_begin_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::burst_end_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"burst_begin_indices"});
int retVal = intFeatures.at("burst_begin_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

static int __strict_burst_mean_freq(const vector<double>& PVTime,
Expand Down Expand Up @@ -695,7 +698,10 @@ int SpikeEvent::interburst_min_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::interburst_min_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"interburst_min_indices"});
int retVal = intFeatures.at("interburst_min_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

static int __postburst_min_indices(const vector<double>& t,
Expand Down Expand Up @@ -767,7 +773,10 @@ int SpikeEvent::postburst_min_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::postburst_min_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"postburst_min_indices"});
int retVal = intFeatures.at("postburst_min_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

int SpikeEvent::time_to_interburst_min(mapStr2intVec& IntFeatureData,
Expand Down Expand Up @@ -897,7 +906,10 @@ int SpikeEvent::postburst_slow_ahp_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::postburst_slow_ahp_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"postburst_slow_ahp_indices"});
int retVal = intFeatures.at("postburst_slow_ahp_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

int SpikeEvent::time_to_postburst_slow_ahp(mapStr2intVec& IntFeatureData,
Expand Down Expand Up @@ -1010,7 +1022,10 @@ int SpikeEvent::postburst_fast_ahp_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::postburst_fast_ahp_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"postburst_fast_ahp_indices"});
int retVal = intFeatures.at("postburst_fast_ahp_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

static int __postburst_adp_peak_indices(const vector<double>& t, const vector<double>& v,
Expand Down Expand Up @@ -1077,7 +1092,10 @@ int SpikeEvent::postburst_adp_peak_indices(mapStr2intVec& IntFeatureData,
int SpikeEvent::postburst_adp_peak_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"postburst_adp_peak_indices"});
int retVal = intFeatures.at("postburst_adp_peak_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

int SpikeEvent::time_to_postburst_fast_ahp(mapStr2intVec& IntFeatureData,
Expand Down
20 changes: 16 additions & 4 deletions efel/cppcore/SpikeShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,10 @@ int SpikeShape::min_AHP_indices(mapStr2intVec& IntFeatureData,
int SpikeShape::min_AHP_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return -1;
const auto& intFeatures = getFeatures(IntFeatureData, {"min_AHP_indices"});
int retVal = intFeatures.at("min_AHP_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

// Difference with SpikeShape is that this function doesn't return -1 if there are no
Expand Down Expand Up @@ -550,7 +553,10 @@ int SpikeShape::AHP_depth_abs_slow(mapStr2intVec& IntFeatureData,
int SpikeShape::AHP_slow_time(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return -1;
const auto& doubleFeatures = getFeatures(DoubleFeatureData, {"AHP_depth_abs_slow"});
int retVal = doubleFeatures.at("AHP_depth_abs_slow").size();
if (retVal <= 0) return -1;
return retVal;
}

// *** AHP_depth_slow ***
Expand Down Expand Up @@ -818,7 +824,10 @@ int SpikeShape::ADP_peak_indices(mapStr2intVec& IntFeatureData,
int SpikeShape::ADP_peak_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"ADP_peak_indices"});
int retVal = intFeatures.at("ADP_peak_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

// strict_stiminterval should be True when using this feature
Expand Down Expand Up @@ -994,7 +1003,10 @@ int SpikeShape::min_between_peaks_indices(mapStr2intVec& IntFeatureData,
int SpikeShape::min_between_peaks_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
return 1;
const auto& intFeatures = getFeatures(IntFeatureData, {"min_between_peaks_indices"});
int retVal = intFeatures.at("min_between_peaks_indices").size();
if (retVal <= 0) return -1;
return retVal;
}

// *** AP_duration_half_width according to E8 and E16 ***
Expand Down
5 changes: 4 additions & 1 deletion efel/cppcore/cfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ int cFeature::getFeature(string strName, vector<T>& vec) {
return -1;
}
vec = getMapData<T>(strName, *dataMap);
if (vec.empty()) GErrorStr += "Feature [" + strName + "] data is missing\n";
if (vec.empty()) {
GErrorStr += "Feature [" + strName + "] data is missing\n";
return -1;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will turn empty lists into None

}

logger << "Calculated feature " << strName << ":" << vec << endl;
return vec.size();
Expand Down
4 changes: 2 additions & 2 deletions efel/pyfeatures/pyfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def spikes_per_burst():
burst_begin_indices = get_cpp_feature("burst_begin_indices")
burst_end_indices = get_cpp_feature("burst_end_indices")

if burst_begin_indices is None:
if burst_begin_indices is None or len(burst_begin_indices) < 1:
return None

ap_per_bursts = []
Expand All @@ -304,7 +304,7 @@ def spikes_per_burst():
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:
if spikes_per_burst_values is None or len(spikes_per_burst_values) < 2:
return None

return spikes_per_burst_values[:-1] - spikes_per_burst_values[1:]
Expand Down
16 changes: 8 additions & 8 deletions tests/testdata/allfeatures/expectedresults.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@
"interburst_60percent_indices": null,
"interburst_60percent_values": null,
"interburst_duration": null,
"interburst_min_indices": [],
"interburst_min_values": [],
"interburst_min_indices": null,
"interburst_min_values": null,
"interburst_voltage": [
-38.820613862535545
],
Expand Down Expand Up @@ -624,7 +624,7 @@
"strict_burst_number": [
1
],
"strict_interburst_voltage": [],
"strict_interburst_voltage": null,
"time": [
0.0,
0.1,
Expand Down Expand Up @@ -30632,7 +30632,7 @@
"time_to_first_spike": [
8.000000000092427
],
"time_to_interburst_min": [],
"time_to_interburst_min": null,
"time_to_last_spike": [
1937.7999999986964
],
Expand Down Expand Up @@ -60680,7 +60680,7 @@
"spikes_per_burst": [
2
],
"spikes_per_burst_diff": [],
"spikes_per_burst_diff": null,
"spikes_in_burst1_burst2_diff": null,
"spikes_in_burst1_burstlast_diff": null,
"depol_block": null,
Expand Down Expand Up @@ -60723,7 +60723,7 @@
"strict_burst_mean_freq": [
7.99041151
],
"strict_interburst_voltage": [],
"strict_interburst_voltage": null,
"ADP_peak_amplitude": [
0.0,
2.6873666528663236,
Expand All @@ -60748,8 +60748,8 @@
-41.12299346923828,
-38.12341871769886
],
"interburst_min_indices": [],
"interburst_min_values": [],
"interburst_min_indices": null,
"interburst_min_values": null,
"postburst_min_indices": [
26465
],
Expand Down