Skip to content

Commit ca29df6

Browse files
authored
Merge pull request MIT-LCP#226 from MIT-LCP/edit_dtype_225
Adds datatype parameter in rdrecord/rdsamp MIT-LCP#224 MIT-LCP#225
2 parents c5584e7 + 32bcedf commit ca29df6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

wfdb/io/_signal.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,10 @@ def smooth_frames(self, sigtype='physical'):
856856

857857
#------------------- Reading Signals -------------------#
858858

859+
859860
def _rd_segment(file_name, dir_name, pn_dir, fmt, n_sig, sig_len, byte_offset,
860861
samps_per_frame, skew, sampfrom, sampto, channels,
861-
smooth_frames, ignore_skew):
862+
smooth_frames, ignore_skew, return_res=64):
862863
"""
863864
Read the digital samples from a single segment record's associated
864865
dat file(s).
@@ -896,6 +897,11 @@ def _rd_segment(file_name, dir_name, pn_dir, fmt, n_sig, sig_len, byte_offset,
896897
Specifies whether to apply the skew to align the signals in the
897898
output variable (False), or to ignore the skew field and load in
898899
all values contained in the dat files unaligned (True).
900+
return_res : int, optional
901+
The numpy array dtype of the returned signals. Options are: 64,
902+
32, 16, and 8, where the value represents the numpy int or float
903+
dtype. Note that the value cannot be 8 when physical is True
904+
since there is no float8 format.
899905
900906
Returns
901907
-------
@@ -930,6 +936,10 @@ def _rd_segment(file_name, dir_name, pn_dir, fmt, n_sig, sig_len, byte_offset,
930936
if ignore_skew:
931937
skew = [0]*n_sig
932938

939+
# Change format if requested
940+
if return_res != 64:
941+
fmt = len(fmt) * [str(return_res)]
942+
933943
# Get the set of dat files, and the
934944
# channels that belong to each file.
935945
file_name, datchannel = describe_list_indices(file_name)

wfdb/io/record.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,8 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
15171517
record.samps_per_frame,
15181518
record.skew, sampfrom, sampto,
15191519
channels, smooth_frames,
1520-
ignore_skew)
1520+
ignore_skew,
1521+
return_res=return_res)
15211522

15221523
# Arrange/edit the object fields to reflect user channel
15231524
# and/or signal range input
@@ -1538,7 +1539,8 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
15381539
record.samps_per_frame,
15391540
record.skew, sampfrom,
15401541
sampto, channels,
1541-
smooth_frames, ignore_skew)
1542+
smooth_frames, ignore_skew,
1543+
return_res=return_res)
15421544

15431545
# Arrange/edit the object fields to reflect user channel
15441546
# and/or signal range input
@@ -1588,7 +1590,8 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
15881590
record.segments[seg_num] = rdrecord(
15891591
os.path.join(dir_name, record.seg_name[seg_num]),
15901592
sampfrom=seg_ranges[i][0], sampto=seg_ranges[i][1],
1591-
channels=seg_channels[i], physical=physical, pn_dir=pn_dir)
1593+
channels=seg_channels[i], physical=physical, pn_dir=pn_dir,
1594+
return_res=return_res)
15921595

15931596
# Arrange the fields of the layout specification segment, and
15941597
# the overall object, to reflect user input.
@@ -1609,7 +1612,7 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
16091612

16101613

16111614
def rdsamp(record_name, sampfrom=0, sampto=None, channels=None, pn_dir=None,
1612-
channel_names=None, warn_empty=False):
1615+
channel_names=None, warn_empty=False, return_res=64):
16131616
"""
16141617
Read a WFDB record, and return the physical signals and a few important
16151618
descriptor fields.
@@ -1641,6 +1644,11 @@ def rdsamp(record_name, sampfrom=0, sampto=None, channels=None, pn_dir=None,
16411644
Whether to display a warning if the specified channel indices
16421645
or names are not contained in the record, and no signal is
16431646
returned.
1647+
return_res : int, optional
1648+
The numpy array dtype of the returned signals. Options are: 64,
1649+
32, 16, and 8, where the value represents the numpy int or float
1650+
dtype. Note that the value cannot be 8 when physical is True
1651+
since there is no float8 format.
16441652
16451653
Returns
16461654
-------
@@ -1682,8 +1690,8 @@ def rdsamp(record_name, sampfrom=0, sampto=None, channels=None, pn_dir=None,
16821690

16831691
record = rdrecord(record_name=record_name, sampfrom=sampfrom,
16841692
sampto=sampto, channels=channels, physical=True,
1685-
pn_dir=pn_dir, m2s=True, channel_names=channel_names,
1686-
warn_empty=warn_empty)
1693+
pn_dir=pn_dir, m2s=True, return_res=return_res,
1694+
channel_names=channel_names, warn_empty=warn_empty)
16871695

16881696
signals = record.p_signal
16891697
fields = {}

0 commit comments

Comments
 (0)