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

Subelements of the symbol field must be strings of length 1 to 3 error

Open MishalJasmine opened this issue 4 years ago • 9 comments

I am using wrann to write the symbols and the indices into the reference annotation file. I am getting this error Subelements of the symbol field must be strings of length 1 to 3 for the symbols list. I checked the type of the list elements using
for i in range(0,len(labels)):
print(isinstance(labels[i], str_types)) and the result is True for all the elements of the list. If I use a dummy symbol list I am able to write to the annotation file. Could you tell me what is it that I am doing wrong.

MishalJasmine avatar Apr 30 '20 04:04 MishalJasmine

Hey @MishalJasmine, thanks for posting your issues here! You are using custom labels? If so, this snippet here indicates that being an instance of str_types isn't the only condition that needs to be satisfied to raise this error. The length of each sublist must also be in the range of 1-3.

https://github.com/MIT-LCP/wfdb-python/blob/0d4b5a689bc7a1719af1ead6e6dd5b1ecaf1a6b3/wfdb/io/annotation.py#L294-L295

Maybe these errors should be separated to provide more clarity? An example symbol (or labels in your case) list would be the following (coming from 1003.atr in sample_data):

[(15, 'c', 'calibration pulse'), (17, '#', 'pressure line flushed'), (20, 'x', 'signal source change'), (21, 'w', 'wedge recording (PCW)'), (23, '*', 'pop test'), (24, 'z', 'zero pressure')]

Does this help? If not, I need some more information about your labels variable in order to make more suggestions. Thanks!

Lucas-Mc avatar Apr 30 '20 15:04 Lucas-Mc

I think I understand.. let me check that out..

MishalJasmine avatar May 04 '20 05:05 MishalJasmine

I tried creating a annotation file locally. These labels are not custom labels. The labels that I have used are N, S, F , Q and V which are included in the PhysioNet. The error that I am getting now is

TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The type of symbols and labels is <class 'numpy.ndarray'>. I have included a spinet of the code.

    label_array = np.array(label)
    qrs_index = np.array(qrs)

    #Test Annotation file creation
    wfdb.wrann(recordlist[i],extension = 'atr' ,sample = qrs_index, symbol = label_array)

Can I get some help on this.

MishalJasmine avatar May 08 '20 03:05 MishalJasmine

Hey @MishalJasmine, I need to know what your label and qrs variables are to find out the error here.

Lucas-Mc avatar May 08 '20 14:05 Lucas-Mc

label and qrs is the output of my model. It is basically a list of all the symbols and the indices of the QRS peaks that I need to add in my annotation file.

MishalJasmine avatar May 08 '20 14:05 MishalJasmine

What is the traceback for the error? I am trying to find the source of it now.

Lucas-Mc avatar May 08 '20 19:05 Lucas-Mc

Traceback (most recent call last): File "internalTesting.py", line 18, in main() File "internalTesting.py", line 14, in main localfunction(sys.argv[1].lower(), sys.argv[2]) File "/home/xxxx/GitHub/patch_python/local_test_scripts/internalTesting/qrsanalysis/databaseLocal.py", line 310, in localfunction wfdb.wrann(record_name= recordlist[i], extension='atr',sample = qrs_index, symbol = label_array) File "/home/xxxx/anaconda3/lib/python3.7/site-packages/wfdb/io/annotation.py", line 1160, in wrann annotation.wrann(write_fs=True, write_dir=write_dir) File "/home/xxxx/anaconda3/lib/python3.7/site-packages/wfdb/io/annotation.py", line 189, in wrann self.wr_ann_file(write_fs=write_fs, write_dir=write_dir) File "/home/xxxx/anaconda3/lib/python3.7/site-packages/wfdb/io/annotation.py", line 600, in wr_ann_file core_bytes = self.calc_core_bytes() File "/home/xxxx/anaconda3/lib/python3.7/site-packages/wfdb/io/annotation.py", line 705, in calc_core_bytes data_bytes.append(field2bytes('samptype', [sampdiff[i], self.symbol[i]])) File "/home/xxxx/anaconda3/lib/python3.7/site-packages/wfdb/io/annotation.py", line 1023, in field2bytes data_bytes = [sd & 255, ((sd & 768) >> 8) + 4*typecode] TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according

MishalJasmine avatar May 09 '20 03:05 MishalJasmine

Okay, I think this attached pull request should fix the issue you are having. There was an error in the way that two binary numbers were being added which was causing your error. Feel free to update me if this fix doesn't help out! Thanks for posting!

Lucas-Mc avatar May 11 '20 12:05 Lucas-Mc

Actually, this just seems to open another error.... I really need some kind of example of your labels that cause the error so I know whether or not I fixed it and maintains the current functionality as well.

Lucas-Mc avatar May 11 '20 13:05 Lucas-Mc