Skip to content

Commit d52e600

Browse files
Test & fix bug with find_do_peak(delay_b) kwarg
Co-authored-by: Luisa Wachtendonk<[email protected]>
1 parent abddc4b commit d52e600

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

bletl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
NoMeasurementData,
3737
)
3838

39-
__version__ = "1.5.0"
39+
__version__ = "1.5.1"

bletl/heuristics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ def find_do_peak(
7575
if overshot_since >= delay_b:
7676
# the DO has remained above the threshold for long enough
7777
break
78-
return i_overshot
78+
79+
# Did the series continue long enough after reaching the threshold?
80+
if i_overshot is not None:
81+
overshot_since = x[i_total - 1] - x[i_overshot]
82+
if overshot_since >= delay_b:
83+
return i_overshot
84+
return None

tests/test_heuristics.py

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

1919
assert c_peak == 60
2020
return
21+
22+
def test_find_no_peak_with_long_delay_a(self):
23+
bldata = bletl.parse(FP_TESTFILE)
24+
25+
x, y = bldata["DO"].get_timeseries("A01")
26+
27+
# The DO was below 70 for only ~2 h
28+
c_peak = bletl.find_do_peak(
29+
x, y, delay_a=5, threshold_a=70, delay_b=0, threshold_b=80, initial_delay=1
30+
)
31+
32+
assert c_peak is None
33+
return
34+
35+
def test_find_no_peak_with_long_delay_b(self):
36+
bldata = bletl.parse(FP_TESTFILE)
37+
38+
x, y = bldata["DO"].get_timeseries("A01")
39+
40+
# The series continues for only ~9.5 h after the peak
41+
c_peak = bletl.find_do_peak(
42+
x, y, delay_a=0.5, threshold_a=70, delay_b=12, threshold_b=80, initial_delay=1
43+
)
44+
45+
assert c_peak is None
46+
return
47+
48+
def test_find_no_peak_with_long_initial_delay(self):
49+
bldata = bletl.parse(FP_TESTFILE)
50+
51+
x, y = bldata["DO"].get_timeseries("A01")
52+
53+
# The peak is within the first ~12 h
54+
c_peak = bletl.find_do_peak(
55+
x, y, delay_a=0.5, threshold_a=70, delay_b=4, threshold_b=80, initial_delay=15
56+
)
57+
58+
assert c_peak is None
59+
return

0 commit comments

Comments
 (0)