Skip to content

Commit

Permalink
fix apply_estimator for num_peaks feature
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk committed Feb 10, 2025
1 parent 47a3be8 commit aab97fd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion py_neuromodulation/features/sharpwaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,23 @@ def calc_feature(self, data: np.ndarray) -> dict:

# the key_name stays, since the estimator function stays between peaks and troughs
for key_name, estimator in self.estimator_key_map.items():
if "num_peaks" in key_name:
if len(dict_ch_features[key_name]) == 0:
# might happen if num_peaks was written in estimator
# e.g. estimator["mean"] = ["num_peaks"]
# for conveniance this doesn't raise an exception
continue

feature_results[key_name] = estimator(
[
list(dict_ch_features[key_name].values())[0],
list(dict_ch_features[key_name].values())[1],
]
)
# add here also the num_peaks features
if self.sw_settings.sharpwave_features.num_peaks:
key_name = f"{ch_name}_Sharpwave_num_peaks_{filter_name}"
feature_results[key_name] = np_mean([dict_ch_features[key_name]["Peak"],
dict_ch_features[key_name]["Trough"]])
else:
# otherwise, save all write all "flattened" key value pairs in feature_results
for key, subdict in dict_ch_features.items():
Expand Down

0 comments on commit aab97fd

Please sign in to comment.