Repository navigation
Use the last RR interval in compute_hr - #601
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks, this looks good! I checked record 100 and only the samples after the last beat change, as you said. It also fixes an IndexError when the last beat is past the end of the signal.
Could you rebase on main? #599 just added a changelog entry in the same place.
Optional: a sentence in the docstring explaining which interval each sample's rate comes from (like your code comment) would help users.
ba6c494 to
836a01d
Compare
|
Thanks! I've rebased onto
Tests (89) and the docs build pass. |
The loop stopped one interval early and copied the previous rate past the last beat, so the last RR interval was never used and two beats gave only NaN.
836a01d to
b9e0542
Compare
|
#600 was merged while I was pushing, so I've rebased once more. It's mergeable again, and tests pass (99). |
tompollard
left a comment
There was a problem hiding this comment.
Thanks so much for all of these fixes! It's Halloween here today, so feels very appropriate to have @TheNetherWatcher digging up old bugs 🎃
|
It's weekend, and I'm mostly free the entire weekend, so I go up issue fixing, bug hunting and performance improving in the OSS space every weekend. |
compute_hrloops overrange(len(qrs_inds) - 2)and then copies the rate at the last beat forward (heart_rate[qrs_inds[-1]:] = heart_rate[qrs_inds[-1]]). So the interval between the last two beats is never used:compute_hr(14, [0, 2, 6, 12], fs=60)gives 900 bpm after sample 12 (from the 2-sample interval before it) instead of 600 bpm (from the last interval, 6 samples).compute_hr(10, [2, 6], fs=1)returns only NaN, although thelen(qrs_inds) < 2check implies two beats are enough.The loop now runs over every RR interval, and the last one fills up to the end of the signal. Everything before the last beat is unchanged. For record 100 with the reference annotations, the only differences are the 8 samples after the last beat.
Two tests are added in
TestComputeHr, and both fail onmain.ruff checkis clean andpytest -m "not network"passes.Related to #185, but that report was mostly caused by non-beat annotations (see the comments there), so this doesn't close it.