Skip to content

Commit 0bec4ab

Browse files
sofia3msjomy-kk
andauthored
Even kernel size (#66)
* Warn even kernel size instead of halting Wouldn't it be more friendly if BioSPPy solved for the user the issue of passing an even kernel size when median filtering? Because raising an error halts the program, which isn't necessary since it's not problematic. Here's a proposal to solve the issue and alert the user. * Update warnings --------- Co-authored-by: João Saraiva <[email protected]>
1 parent 6a92fcc commit 0bec4ab

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

biosppy/signals/tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from six.moves import range
1717
import six
1818

19+
# built-in
20+
import warnings
21+
1922
# 3rd party
2023
import sys
2124
import numpy as np
@@ -592,7 +595,8 @@ def smoother(signal=None, kernel="boxzen", size=10, mirror=True, **kwargs):
592595
elif kernel == "median":
593596
# median filter
594597
if size % 2 == 0:
595-
raise ValueError("When the kernel is 'median', size must be odd.")
598+
size -= 1
599+
warnings.warn("When the kernel is 'median', size must be odd, so the size was decremented by one.")
596600

597601
smoothed = ss.medfilt(signal, kernel_size=size)
598602

0 commit comments

Comments
 (0)