Skip to content

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

Description

@MishalJasmine

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.

Activity

  1. self-assigned this
    on Apr 30, 2020
  2. Lucas-Mc commented on Apr 30, 2020

    @Lucas-Mc
    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!

  3. MishalJasmine commented on May 4, 2020

    @MishalJasmine
    Author

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

  4. MishalJasmine commented on May 8, 2020

    @MishalJasmine
    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.

  5. Lucas-Mc commented on May 8, 2020

    @Lucas-Mc
    Contributor

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

  6. MishalJasmine commented on May 8, 2020

    @MishalJasmine
    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.

  7. Lucas-Mc commented on May 8, 2020

    @Lucas-Mc
    Contributor

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

  8. MishalJasmine commented on May 9, 2020

    @MishalJasmine
    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

  9. added a commit that references this issue on May 11, 2020
  10. Lucas-Mc commented on May 11, 2020

    @Lucas-Mc
    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!

  11. Lucas-Mc commented on May 11, 2020

    @Lucas-Mc
    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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions