Skip to content

Commit 1634a8a

Browse files
author
Benjamin Moody
committed
Remove obsolete and broken logic for handling 24-bit input.
Previously, the data type string for signal format 24 (DATA_LOAD_TYPES['24']) was set to '<i3', which is numpy shorthand for "little-endian, signed integers, three bytes per element", although numpy does not actually support such a format. This file format was previously accommodated by special cases in _rd_dat_file (for local files) and in _stream_dat (for remote files). Both of these implementations were broken, in that they would silently discard the least significant byte and return a 16-bit integer array. The implementation for local files was further broken in that it only worked if the input file was mmappable, if the range to be retrieved was the entire input file, and if the file consisted of an even number of samples. Format 24 is now accommodated by reading the data as unsigned 8-bit integers (DATA_LOAD_TYPES['24'] = '<u1') and reformatting the array afterwards (in _blocks_to_samples), as was previously done for formats 212, 310, and 311. This makes the previous logic in _rd_dat_file and _stream_dat unnecessary, so remove it.
1 parent 37d5a12 commit 1634a8a

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

wfdb/io/_signal.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,24 +1410,12 @@ def _rd_dat_file(file_name, dir_name, pn_dir, fmt, start_byte, n_samp):
14101410
if pn_dir is None:
14111411
with open(os.path.join(dir_name, file_name), 'rb') as fp:
14121412
fp.seek(start_byte)
1413-
# Numpy doesn't really like 24-bit data but we can make it work
1414-
if DATA_LOAD_TYPES[fmt] == '<i3':
1415-
raw_data_map = np.memmap(fp,
1416-
dtype=np.dtype('i2'),
1417-
mode='r')
1418-
temp_data = np.frombuffer(raw_data_map, 'b').reshape(-1,3)[:,1:].flatten().view('i2')
1419-
sig_data = np.fromstring(temp_data, dtype='i2')
1420-
else:
1421-
sig_data = np.fromfile(fp,
1422-
dtype=np.dtype(DATA_LOAD_TYPES[fmt]),
1423-
count=element_count)
1413+
sig_data = np.fromfile(fp,
1414+
dtype=np.dtype(DATA_LOAD_TYPES[fmt]),
1415+
count=element_count)
14241416
# Stream dat file from Physionet
14251417
else:
1426-
if DATA_LOAD_TYPES[fmt] == '<i3':
1427-
dtype_in = '<i3'
1428-
else:
1429-
dtype_in = np.dtype(DATA_LOAD_TYPES[fmt])
1430-
1418+
dtype_in = np.dtype(DATA_LOAD_TYPES[fmt])
14311419
sig_data = download._stream_dat(file_name, pn_dir, byte_count,
14321420
start_byte, dtype_in)
14331421

wfdb/io/download.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ def _stream_dat(file_name, pn_dir, byte_count, start_byte, dtype):
177177
response.raise_for_status()
178178

179179
# Convert to numpy array
180-
if type(dtype) == str:
181-
# Convert 24-bit to 16-bit then proceed
182-
temp_data = np.frombuffer(response.content, 'b').reshape(-1,3)[:,1:].flatten().view('i2')
183-
sig_data = np.fromstring(temp_data, dtype='i2')
184-
else:
185-
sig_data = np.fromstring(response.content, dtype=dtype)
180+
sig_data = np.fromstring(response.content, dtype=dtype)
186181

187182
return sig_data
188183

0 commit comments

Comments
 (0)