wfdb-python icon indicating copy to clipboard operation
wfdb-python copied to clipboard

Error in wfdb_to_wav

Open dmerinodel opened this issue 3 years ago • 2 comments

Hi everyone,

this is my first time writing an issue as well as using wfdb so, excuse me in advance for the mistakes I'll surely make :)

I'm trying to obtain some .wav from the data stored in VOICED database with the following piece of code:

import wfdb.io.convert.wav
import os

path = 'my_path'
wfdb.io.convert.wav.wfdb_to_wav('voice001', pn_dir='voiced',
                                output_filename=os.path.join(path, 'aaab.wav'))

Thus, I obtain the following error:

Traceback (most recent call last): File "path_of_my_script", line 18, in wfdb.io.convert.wav.wfdb_to_wav('voice001', pn_dir='voiced', File "C:[...]\AppData\Local\Programs\Python\Python310\lib\site-packages\wfdb\io\convert\wav.py", line 121, in wfdb_to_wav np.left_shift(np.subtract(record.adc(), offset), shift) File "C:[...]\AppData\Local\Programs\Python\Python310\lib\site-packages\wfdb\io_signal.py", line 578, in adc nanlocs = np.isnan(self.p_signal) TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

At first I thought that I was messing it up and went to the documentation page. I ended up realizing that if I try to run the example piece of code that appears for wfdb_to_wav:

wfdb_to_wav('100', pn_dir='pwave')

I obtain the same error as my code's. I did some research and some people has the same 'TypeError: ufunc 'isnan' not supported...' in other context, they managed to fix it using pandas instead of numpy, but it doesn't work for me. Any idea of why is this happening?

dmerinodel avatar Jul 21 '22 07:07 dmerinodel

This is a bug in wfdb_to_wav; it calls rdrecord with smooth_frames=False when what it wants is smooth_frames=True. Thanks for pointing this out! We ought to include a test case for wfdb_to_wav in the test suite.

Looks like this bug has been there since wfdb_to_wav (then called mit2wav) was first written, though prior to v4.0.0 the bug would only have occurred with multi-frequency input records.

bemoody avatar Jul 22 '22 14:07 bemoody

I tried with smooth_frames=True and my code runs, but the .wav that generates doesn't make any sound. I guess it's not that easy :) thanks!

dmerinodel avatar Jul 25 '22 07:07 dmerinodel