Skip to content

Commit

Permalink
Test & fix bug with find_do_peak(delay_b) kwarg
Browse files Browse the repository at this point in the history
Co-authored-by: Luisa Wachtendonk<[email protected]>
  • Loading branch information
lisaa2504 committed Nov 18, 2024
1 parent abddc4b commit d52e600
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bletl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
NoMeasurementData,
)

__version__ = "1.5.0"
__version__ = "1.5.1"
8 changes: 7 additions & 1 deletion bletl/heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ def find_do_peak(
if overshot_since >= delay_b:
# the DO has remained above the threshold for long enough
break
return i_overshot

# Did the series continue long enough after reaching 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
39 changes: 39 additions & 0 deletions tests/test_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,42 @@ def test_find_peak(self):

assert c_peak == 60
return

def test_find_no_peak_with_long_delay_a(self):
bldata = bletl.parse(FP_TESTFILE)

x, y = bldata["DO"].get_timeseries("A01")

# The DO was below 70 for only ~2 h
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 is None
return

def test_find_no_peak_with_long_delay_b(self):
bldata = bletl.parse(FP_TESTFILE)

x, y = bldata["DO"].get_timeseries("A01")

# The series continues for only ~9.5 h after the peak
c_peak = bletl.find_do_peak(
x, y, delay_a=0.5, threshold_a=70, delay_b=12, threshold_b=80, initial_delay=1
)

assert c_peak is None
return

def test_find_no_peak_with_long_initial_delay(self):
bldata = bletl.parse(FP_TESTFILE)

x, y = bldata["DO"].get_timeseries("A01")

# The peak is within the first ~12 h
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 is None
return

0 comments on commit d52e600

Please sign in to comment.