From daffd761d5837c0121138261dc056461ef076d9f Mon Sep 17 00:00:00 2001 From: Lisa Prigolovkin Date: Wed, 13 Nov 2024 17:28:20 +0100 Subject: [PATCH] Delay_b_Bug_fix --- bletl/heuristics.py | 8 ++++++-- tests/test_heuristics.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bletl/heuristics.py b/bletl/heuristics.py index 7a88feb..29158b8 100644 --- a/bletl/heuristics.py +++ b/bletl/heuristics.py @@ -46,7 +46,6 @@ def find_do_peak( """ i_total = len(x) i_silencing = numpy.argmax(x > initial_delay) - i_undershot = None for i in range(i_silencing, i_total): if y[i] < threshold_a and i_undershot is None: @@ -75,4 +74,9 @@ def find_do_peak( if overshot_since >= delay_b: # the DO has remained above the threshold for long enough break - return i_overshot + # is the data set even long enough to have remained above the threshold + if i_overshot is not None: + overshot_since = x[i_total - 1] - x[i_overshot] + if overshot_since >= delay_b: + return i_overshot + return None diff --git a/tests/test_heuristics.py b/tests/test_heuristics.py index c7f1abd..d2f9d37 100644 --- a/tests/test_heuristics.py +++ b/tests/test_heuristics.py @@ -18,3 +18,39 @@ def test_find_peak(self): assert c_peak == 60 return + + def test_find_peak_with_delay_a(self): + bldata = bletl.parse(FP_TESTFILE) + + x, y = bldata["DO"].get_timeseries("A01") + + c_peak = bletl.find_do_peak( + x, y, delay_a=5, threshold_a=70, delay_b=0, threshold_b=80, initial_delay=1 + ) + + assert c_peak == None + return + + def test_find_peak_with_delay_b(self): + bldata = bletl.parse(FP_TESTFILE) + + x, y = bldata["DO"].get_timeseries("A01") + + c_peak = bletl.find_do_peak( + x, y, delay_a=0.5, threshold_a=70, delay_b=70, threshold_b=80, initial_delay=1 + ) + + assert c_peak is not None and c_peak > 80 + return + + def test_find_peak_with_initial_delay(self): + bldata = bletl.parse(FP_TESTFILE) + + x, y = bldata["DO"].get_timeseries("A01") + + c_peak = bletl.find_do_peak( + x, y, delay_a=0.5, threshold_a=70, delay_b=4, threshold_b=80, initial_delay=15 + ) + + assert c_peak == None + return