Repository navigation
Subelements of the symbol field must be strings of length 1 to 3 error #201
Description
Activity
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_typesisn'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.wfdb-python/wfdb/io/annotation.py
Lines 294 to 295 in 0d4b5a6
if not isinstance(symbol[i], str_types) or len(symbol[i]) not in [1,2,3]: raise ValueError('The symbol values of the '+field+' field must be strings of length 1 to 3') Maybe these errors should be separated to provide more clarity? An example
symbol(orlabelsin your case) list would be the following (coming from1003.atrinsample_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
labelsvariable in order to make more suggestions. Thanks!I think I understand.. let me check that out..
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.
Hey @MishalJasmine, I need to know what your
labelandqrsvariables are to find out the error here.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.
What is the traceback for the error? I am trying to find the source of it now.
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 accordingOkay, 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!
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.
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 3for the symbols list. I checked the type of the list elements usingfor 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.