Skip to content

Commit 3322dfb

Browse files
authored
Merge pull request #193 from MIT-LCP/fmt_24b_138
Adds 24-bit ability #138
2 parents 29f1001 + a2948b3 commit 3322dfb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

wfdb/io/_signal.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,21 @@ def _rd_dat_file(file_name, dir_name, pb_dir, fmt, start_byte, n_samp):
12231223
if pb_dir is None:
12241224
with open(os.path.join(dir_name, file_name), 'rb') as fp:
12251225
fp.seek(start_byte)
1226-
sig_data = np.fromfile(fp, dtype=np.dtype(DATA_LOAD_TYPES[fmt]),
1227-
count=element_count)
1226+
# Numpy doesn't really like 24-bit data but we can make it work
1227+
if DATA_LOAD_TYPES[fmt] == '<i3':
1228+
rawdatamap = np.memmap(fp,
1229+
dtype=np.dtype('u1'),
1230+
mode='r')
1231+
usablebytes = rawdatamap.shape[0]-rawdatamap.shape[0]%12
1232+
frames = int(usablebytes/12)
1233+
rawbytes = rawdatamap[:usablebytes]
1234+
sig_data = np.lib.stride_tricks.as_strided(rawbytes.view(np.int32),
1235+
strides=(12,3,),
1236+
shape=(frames,4))
1237+
else:
1238+
sig_data = np.fromfile(fp,
1239+
dtype=np.dtype(DATA_LOAD_TYPES[fmt]),
1240+
count=element_count)
12281241
# Stream dat file from physiobank
12291242
else:
12301243
sig_data = download._stream_dat(file_name, pb_dir, byte_count,

0 commit comments

Comments
 (0)