MIT-LCP / wfdb-python

Native Python WFDB package
MIT License
738 stars 300 forks source link

KeyError: '516' while running wfdb.rdrecord and wfdb.rdsamp #432

Closed svinnak2 closed 1 year ago

svinnak2 commented 1 year ago

Hello,

I'm running below code and getting KeyError: '516'. No more information to debug the error. Could you please provide me some inputs to solve the error.

Start of Code

segment_names = ['83404654_0005', '82924339_0007'] segment_dirs = ['mimic4wdb/0.1.0/waves/p100/p10020306/83404654', 'mimic4wdb/0.1.0/waves/p101/p10126957/82924339']

rel_segment_n = 1 rel_segment_name = segment_names[rel_segment_n] rel_segment_dir = segment_dirs[rel_segment_n] print(f"Specified segment '{rel_segment_name}' in directory: '{rel_segment_dir}'")

sampfrom = fs start_seconds sampto = fs (start_seconds + n_seconds_to_load)

segment_data = wfdb.rdrecord(record_name=rel_segment_name, sampfrom=sampfrom, sampto=sampto, pn_dir=rel_segment_dir)

print(f"{n_seconds_to_load} seconds of data extracted from segment {rel_segment_name}")

End of Code


KeyError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_13056/2226737551.py in 2 sampto = fs * (start_seconds + n_seconds_to_load) 3 ----> 4 segment_data = wfdb.rdrecord(record_name=rel_segment_name, 5 sampfrom=sampfrom, 6 sampto=sampto,

~\anaconda3\lib\site-packages\wfdb\io\record.py in rdrecord(record_name, sampfrom, sampto, channels, physical, pn_dir, m2s, smooth_frames, ignore_skew, return_res, force_channels, channel_names, warn_empty) 3528 return_res=return_res) 3529 else: -> 3530 record.d_signal = _signal._rd_segment(record.file_name, 3531 dir_name, pn_dir, 3532 record.fmt,

~\anaconda3\lib\site-packages\wfdb\io_signal.py in _rd_segment(file_name, dir_name, pn_dir, fmt, n_sig, sig_len, byte_offset, samps_per_frame, skew, sampfrom, sampto, channels, smooth_frames, ignore_skew, no_file, sig_data, return_res) 992 if smooth_frames or sum(samps_per_frame) == n_sig: 993 # Figure out the largest required dtype for the segment to minimize memory usage --> 994 max_dtype = _np_dtype(_fmt_res(fmt, max_res=True), discrete=True) 995 # Allocate signal array. Minimize dtype 996 signals = np.zeros([sampto-sampfrom, len(channels)], dtype=max_dtype)

~\anaconda3\lib\site-packages\wfdb\io_signal.py in _fmt_res(fmt, max_res) 1837 if max_res: 1838 # Allow None -> 1839 bit_res = np.max([_fmt_res(f) for f in fmt if f is not None]) 1840 else: 1841 bit_res = [_fmt_res(f) for f in fmt]

~\anaconda3\lib\site-packages\wfdb\io_signal.py in (.0) 1837 if max_res: 1838 # Allow None -> 1839 bit_res = np.max([_fmt_res(f) for f in fmt if f is not None]) 1840 else: 1841 bit_res = [_fmt_res(f) for f in fmt]

~\anaconda3\lib\site-packages\wfdb\io_signal.py in _fmt_res(fmt, max_res) 1842 return bit_res 1843 -> 1844 return BIT_RES[fmt] 1845 1846

KeyError: '516'

Thanks, Sai

bemoody commented 1 year ago

You're using an old version of wfdb. Please upgrade to the latest version (4.0.0).

svinnak2 commented 1 year ago

Thanks for your inputs to resolve it. Thanks so much @bemoody .