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

Error when calling rdedfann(): read_edf() got an unexpected keyword argument 'delete_file'

Open prohor33 opened this issue 3 years ago • 4 comments

Hi! I just encounter strange error. It seems for me like function rdedfann doesn't work at all. I confused, because it seems it doesn't represent any specific use case, just ordinary edf file. So, seems strange to me. I just installed new 4.0.0 version and got this bug.

wfdb: 4.0.0

When calling on edf file:

from wfdb.io.convert.edf import rdedfann
rdedfann(f"data/{folder}/{filename}")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [6], in <cell line: 2>()
      1 from wfdb.io.convert.edf import rdedfann
----> 2 rdedfann(f"data/{folder}/{filename}")

File ~/.venv/fecg/lib/python3.8/site-packages/wfdb/io/convert/edf.py:1096, in rdedfann(record_name, pn_dir, delete_file, info_only, record_only, verbose)
   1087     raise Exception(
   1088         "Both `info_only` and `record_only` are set. Only one "
   1089         "can be set at a time."
   1090     )
   1092 # According to the EDF+ docs:
   1093 #   "The coding is EDF compatible in the sense that old EDF software would
   1094 #    simply treat this 'EDF Annotations' signal as if it were a (strange-
   1095 #    looking) ordinary signal"
-> 1096 rec = read_edf(
   1097     record_name,
   1098     pn_dir=pn_dir,
   1099     delete_file=delete_file,
   1100     record_only=True,
   1101     rdedfann_flag=True,
   1102 )
   1104 # Convert from array of integers to ASCII strings
   1105 annotation_string = ""

TypeError: read_edf() got an unexpected keyword argument 'delete_file'

prohor33 avatar Jul 14 '22 22:07 prohor33

I have the same error, reviewing the code base reveals that the read_edf is called from the rdedfann with delete_file argument that is not defined in read_edf

def read_edf(
    record_name,
    pn_dir=None,
    header_only=False,
    verbose=False,
    rdedfann_flag=False,
):

and what is called in the rdedfann function

def rdedfann(
    record_name,
    pn_dir=None,
    delete_file=True,
    info_only=True,
    record_only=False,
    verbose=False,
):

is

    rec = read_edf(
        record_name,
        pn_dir=pn_dir,
        delete_file=delete_file, => wrong
        record_only=True,
        rdedfann_flag=True,
    )

How to make it run (hacky):

in your virtual env console type pip show wfdb to find where wfdb is installed > something like `~/workspace/project/venv/lib/python3.10/site-packages

cd to this location ~/workspace/project/venv/lib/python3.10/site-packages/wfdb/io/convert

open the file in an editor and replace the line 1096-1102 with

    rec = read_edf(
        record_name,
        pn_dir=pn_dir,
        header_only=False,
        rdedfann_flag=True,
    )

unfortunately, i get another error (after some investigation should not be related to this)

  1108 else:
   1109     adjusted_hex = hex(
   1110         struct.unpack("<H", struct.pack(">H", chunk + 1))[0]
   1111     )
-> 1112     annotation_string += bytes.fromhex(adjusted_hex[2:]).decode("ascii")
   1113     # Remove all of the whitespace
   1114     for rep in ["\x00", "\x14", "\x15"]:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xae in position 0: ordinal not in range(128)

mrkistler avatar Jul 18 '22 16:07 mrkistler

You can Comment it out like this, it will run!!! image

lai-nick avatar Mar 01 '24 06:03 lai-nick

i believe it has been fixed/removed in version 4.1.2

def read_edf(
    record_name,
    pn_dir=None,
    header_only=False,
    verbose=False,
    rdedfann_flag=False,
    encoding="iso8859-1",
):

evismoit avatar Mar 01 '24 12:03 evismoit