From ad62b31abca28da0acc37a61d7aa88b6a1038fff Mon Sep 17 00:00:00 2001 From: "a.ott" Date: Mon, 6 Jul 2020 15:22:53 +0200 Subject: [PATCH] improve eod calculation/detection --- helperFunctions.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/helperFunctions.py b/helperFunctions.py index 868fccf..ee28b6c 100644 --- a/helperFunctions.py +++ b/helperFunctions.py @@ -284,15 +284,13 @@ def calculate_serial_correlation(spiketimes: np.ndarray, max_lag: int) -> np.nda return cor -def calculate_eod_frequency(time, eod): +def calculate_eod_frequency(eod, sampling_interval): # TODO for few samples very volatile measure! - up_indicies, down_indicies = threshold_crossings(eod, 0) - up_times, down_times = threshold_crossing_times(time, eod, 0, up_indicies, down_indicies) + std = np.std(eod) + peaks, _ = detect_peaks(eod, std*1) + peak_times = [p*sampling_interval for p in peaks] - if len(up_times) == 0: - return 0 - - durations = np.diff(up_times) + durations = np.diff(peak_times) mean_duration = np.mean(durations) return 1/mean_duration