Skip to content

Commit b83fad5

Browse files
author
Benjamin Moody
committed
_digi_bounds: use a dictionary instead of "if" statements.
The _digi_bounds function previously did not handle formats 310, 311, 61, 160, or 8 (which are not supported by wrsamp). Add these formats to SAMPLE_VALUE_RANGE for consistency even though they're currently not used. This will also raise an exception for unknown formats, rather than silently returning None.
1 parent 9c677b5 commit b83fad5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

wfdb/io/_signal.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@
6262
"311": "<u1",
6363
}
6464

65+
# Minimum and maximum digital sample values for each of the WFDB dat
66+
# formats.
67+
SAMPLE_VALUE_RANGE = {
68+
"80": (-(2**7), 2**7 - 1),
69+
"310": (-(2**9), 2**9 - 1),
70+
"311": (-(2**9), 2**9 - 1),
71+
"212": (-(2**11), 2**11 - 1),
72+
"16": (-(2**15), 2**15 - 1),
73+
"61": (-(2**15), 2**15 - 1),
74+
"160": (-(2**15), 2**15 - 1),
75+
"24": (-(2**23), 2**23 - 1),
76+
"32": (-(2**31), 2**31 - 1),
77+
"8": (-(2**31), 2**31 - 1),
78+
}
79+
6580

6681
class SignalMixin(object):
6782
"""
@@ -1839,17 +1854,7 @@ def _digi_bounds(fmt):
18391854
"""
18401855
if isinstance(fmt, list):
18411856
return [_digi_bounds(f) for f in fmt]
1842-
1843-
if fmt == "80":
1844-
return (-128, 127)
1845-
elif fmt == "212":
1846-
return (-2048, 2047)
1847-
elif fmt == "16":
1848-
return (-32768, 32767)
1849-
elif fmt == "24":
1850-
return (-8388608, 8388607)
1851-
elif fmt == "32":
1852-
return (-2147483648, 2147483647)
1857+
return SAMPLE_VALUE_RANGE[fmt]
18531858

18541859

18551860
def _digi_nan(fmt):

0 commit comments

Comments
 (0)