Repository navigation
Commit 51fd0fc
authored
Correct near-start peak guesses regardless of input order (#680)
`correct_peaks()` can return a negative index for a valid near-start
guess when that guess follows a later one in the input array. The
boundary-adjustment loop stops at the first guess outside the near-start
window, leaving subsequent early guesses unadjusted.
For a length-30 signal with maxima at samples 0 and 20:
```python
sig = np.zeros(30)
sig[[0, 20]] = 5
processing.correct_peaks(sig, np.array([20, 2]), 5, 9, "up")
# before: array([20, -3]); after: array([20, 0])
```
Skip individual later guesses instead of ending the boundary-adjustment
loop. Preserve input order and duplicates. This extends the near-start
correction from #613 to unsorted inputs without changing sorted-input
behavior.
Tests cover all four direction options, duplicate guesses, sorted
controls, unchanged input, and a written/read digital WFDB record passed
to the public API. The 17 added cases produce 13 failures and 4 passing
controls on the unchanged code.
Validation on current main 05db3a2 plus this patch:
- `tests/test_processing.py`: 151 passed on Python 3.12.16.
- Ruff 0.17.3 check and format passed for the changed Python files.
- Strict Sphinx HTML build with `-W --keep-going` passed.
Earlier same-file validation: 113 peak tests passed on Python 3.10.12;
4,000 seeded permutation checks and 4,000 sorted baseline/fixed
equivalence checks passed. The full repository suite and remote CI have
not been verified. These tests check index correction, not clinical
detection accuracy.
AI assistance was used to develop and test this change. Independent
review has not been completed.3 files changed
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
475 | 519 | | |
476 | 520 | | |
477 | 521 | | |
| |||
0 commit comments