Skip to content

Commit a25d55f

Browse files
Delay_b_Bug_fix
1 parent abddc4b commit a25d55f

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

bletl/heuristics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def find_do_peak(
4646
"""
4747
i_total = len(x)
4848
i_silencing = numpy.argmax(x > initial_delay)
49-
5049
i_undershot = None
5150
for i in range(i_silencing, i_total):
5251
if y[i] < threshold_a and i_undershot is None:
@@ -75,4 +74,9 @@ def find_do_peak(
7574
if overshot_since >= delay_b:
7675
# the DO has remained above the threshold for long enough
7776
break
78-
return i_overshot
77+
# is the data set even long enough to have remained above the threshold
78+
if i_overshot is not None:
79+
overshot_since = x[i_total] - x[i_overshot]
80+
if overshot_since >= delay_b:
81+
return i_overshot
82+
return None

tests/test_heuristics.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,39 @@ def test_find_peak(self):
1818

1919
assert c_peak == 60
2020
return
21+
22+
def test_find_peak_with_delay_a(self):
23+
bldata = bletl.parse(FP_TESTFILE)
24+
25+
x, y = bldata["DO"].get_timeseries("A01")
26+
27+
c_peak = bletl.find_do_peak(
28+
x, y, delay_a=5, threshold_a=70, delay_b=0, threshold_b=80, initial_delay=1
29+
)
30+
31+
assert c_peak == None
32+
return
33+
34+
def test_find_peak_with_delay_b(self):
35+
bldata = bletl.parse(FP_TESTFILE)
36+
37+
x, y = bldata["DO"].get_timeseries("A01")
38+
39+
c_peak = bletl.find_do_peak(
40+
x, y, delay_a=0.5, threshold_a=70, delay_b=70, threshold_b=80, initial_delay=1
41+
)
42+
43+
assert c_peak >= 80
44+
return
45+
46+
def test_find_peak_with_initial_delay(self):
47+
bldata = bletl.parse(FP_TESTFILE)
48+
49+
x, y = bldata["DO"].get_timeseries("A01")
50+
51+
c_peak = bletl.find_do_peak(
52+
x, y, delay_a=0.5, threshold_a=70, delay_b=4, threshold_b=80, initial_delay=15
53+
)
54+
55+
assert c_peak == None
56+
return

0 commit comments

Comments
 (0)