Skip to content

Commit e44e87c

Browse files
committed
update readme for new rdsamp input value and move convert_dtype function
1 parent 366f894 commit e44e87c

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Input Arguments:
159159
- ``m2s`` (default=True): Flag used only for multi-segment records. Specifies whether to convert the returned wfdb.MultiRecord object into a wfdb.Record object (True) or not (False).
160160
- ``smoothframes`` (default=True): Flag used when reading records with signals having multiple samples per frame. Specifies whether to smooth the samples in signals with more than one sample per frame and return an mxn uniform numpy array as the d_signals or p_signals field (True), or to return a list of 1d numpy arrays containing every expanded sample as the e_d_signals or e_p_signals field (False).
161161
- ``ignoreskew`` (default=False): Flag used when reading records with at least one skewed signal. Specifies whether to apply the skew to align the signals in the output variable (False), or to ignore the skew field and load in all values contained in the dat files unaligned (True).
162+
- ``returnres`` (default=64): The numpy array dtype of the returned signals. Options are: 64, 32, 16, and 8, where the value represents the numpy int or float dtype. Note that the value cannot be 8 when physical is True since there is no float8 format.
162163

163164
Output Arguments:
164165

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Versions should comply with PEP440. For a discussion on single-sourcing
2121
# the version across setup.py and the project code, see
2222
# https://packaging.python.org/en/latest/single_source_version.html
23-
version='1.2.0',
23+
version='1.2.1',
2424

2525
description='The WFDB Python Toolbox',
2626
long_description=long_description,

wfdb/readwrite/_signals.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,37 @@ def calculate_adcparams(self):
377377

378378
return (gains, baselines)
379379

380+
381+
def convert_dtype(self, physical, returnres, smoothframes):
382+
if physical is True:
383+
returndtype = 'float'+str(returnres)
384+
if smoothframes is True:
385+
currentdtype = self.p_signals.dtype
386+
if currentdtype != returndtype:
387+
self.p_signals = self.p_signals.astype(returndtype, copy=False)
388+
else:
389+
for ch in range(self.nsig):
390+
if self.e_p_signals[ch].dtype != returndtype:
391+
self.e_p_signals[ch] = self.e_p_signals[ch].astype(returndtype, copy=False)
392+
else:
393+
returndtype = 'int'+str(returnres)
394+
if smoothframes is True:
395+
currentdtype = self.d_signals.dtype
396+
if currentdtype != returndtype:
397+
# Do not allow changing integer dtype to lower value due to over/underflow
398+
if int(str(currentdtype)[3:])>int(str(returndtype)[3:]):
399+
raise Exception('Cannot convert digital samples to lower dtype. Risk of overflow/underflow.')
400+
self.d_signals = self.d_signals.astype(returndtype, copy=False)
401+
else:
402+
for ch in range(self.nsig):
403+
currentdtype = self.e_d_signals[ch].dtype
404+
if currentdtype != returndtype:
405+
# Do not allow changing integer dtype to lower value due to over/underflow
406+
if int(str(currentdtype)[3:])>int(str(returndtype)[3:]):
407+
raise Exception('Cannot convert digital samples to lower dtype. Risk of overflow/underflow.')
408+
self.e_d_signals[ch] = self.e_d_signals[ch].astype(returndtype, copy=False)
409+
return
410+
380411
def calc_checksum(self, expanded=False):
381412
"""
382413
Calculate the checksum(s) of the d_signals (expanded=False)

wfdb/readwrite/records.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,10 @@ def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True
773773
Specifies whether to apply the skew to align the signals in the output variable (False), or
774774
to ignore the skew field and load in all values contained in the dat files unaligned (True).
775775
- returnres (default=64): The numpy array dtype of the returned signals. Options are: 64, 32,
776-
16, or 8, where the value represents the numpy int or float dtype. Note that the value
777-
cannot be 8 when physical=True since there is no float8 format.
776+
16, and 8, where the value represents the numpy int or float dtype. Note that the value
777+
cannot be 8 when physical is True since there is no float8 format.
778+
779+
Output argument:
778780
- record: The wfdb Record or MultiRecord object representing the contents of the record read.
779781
780782
Note: If a signal range or channel selection is specified when calling this function, the
@@ -895,33 +897,7 @@ def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True
895897

896898
# Perform dtype conversion if necessary
897899
if type(record) == Record and record.nsig>0:
898-
if physical is True:
899-
returndtype = 'float'+str(returnres)
900-
if smoothframes is True:
901-
currentdtype = record.p_signals.dtype
902-
if currentdtype != returndtype:
903-
record.p_signals = record.p_signals.astype(returndtype, copy=False)
904-
else:
905-
for ch in range(record.nsig):
906-
if record.e_p_signals[ch].dtype != returndtype:
907-
record.e_p_signals[ch] = record.e_p_signals[ch].astype(returndtype, copy=False)
908-
else:
909-
returndtype = 'int'+str(returnres)
910-
if smoothframes is True:
911-
currentdtype = record.d_signals.dtype
912-
if currentdtype != returndtype:
913-
# Do not allow changing integer dtype to lower value due to over/underflow
914-
if int(str(currentdtype)[3:])>int(str(returndtype)[3:]):
915-
raise Exception('Cannot convert digital samples to lower dtype. Overflow/Underflow likely.')
916-
record.d_signals = record.d_signals.astype(returndtype, copy=False)
917-
else:
918-
for ch in range(record.nsig):
919-
currentdtype = record.e_d_signals[ch].dtype
920-
if currentdtype != returndtype:
921-
# Do not allow changing integer dtype to lower value due to over/underflow
922-
if int(str(currentdtype)[3:])>int(str(returndtype)[3:]):
923-
raise Exception('Cannot convert digital samples to lower dtype. Overflow/Underflow likely.')
924-
record.e_d_signals[ch] = record.e_d_signals[ch].astype(returndtype, copy=False)
900+
record.convert_dtype(physical, returnres, smoothframes)
925901

926902
return record
927903

0 commit comments

Comments
 (0)