Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MishalJasmine opened this issue Apr 30, 2020 · 9 comments · May be fixed by #214
Open

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

MishalJasmine opened this issue Apr 30, 2020 · 9 comments · May be fixed by #214
Assignees
Labels

Comments

@MishalJasmine
Copy link

MishalJasmine commented Apr 30, 2020

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.

@Lucas-Mc Lucas-Mc self-assigned this Apr 30, 2020
@Lucas-Mc
Copy link
Contributor

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.

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 (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!

@MishalJasmine
Copy link
Author

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

@MishalJasmine
Copy link
Author

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.

@Lucas-Mc
Copy link
Contributor

Lucas-Mc commented May 8, 2020

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

@MishalJasmine
Copy link
Author

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.

@Lucas-Mc
Copy link
Contributor

Lucas-Mc commented May 8, 2020

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

@MishalJasmine
Copy link
Author

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

Lucas-Mc added a commit that referenced this issue May 11, 2020
Fixes incorrect addition of two binary number causing a TypeError from adding two incompatible types. Fixes #201.
@Lucas-Mc
Copy link
Contributor

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 Lucas-Mc linked a pull request May 11, 2020 that will close this issue
@Lucas-Mc Lucas-Mc added bug and removed more info labels May 11, 2020
@Lucas-Mc Lucas-Mc reopened this May 11, 2020
@Lucas-Mc
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants