Skip to content

Commit

Permalink
Delay_b_Bug_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lisaa2504 committed Nov 14, 2024
1 parent abddc4b commit 5621fec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bletl/heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
36 changes: 36 additions & 0 deletions tests/test_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 >= 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

0 comments on commit 5621fec

Please sign in to comment.