Skip to content

How to use wfdb.wrann with custom_labels and label_store to write the custom labels? #399

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

Closed
nanli-emory opened this issue Jun 27, 2022 · 0 comments · Fixed by #404
Closed

Comments

@nanli-emory
Copy link

nanli-emory commented Jun 27, 2022

I was trying to write an annotation as wfdb format annotation.

import wfdb
import numpy as np
import pandas as pd
ann_idx = np.array([0, 1000, 2000, 3000, 4000, 5000, 6000, 7000])
ann_label_store = np.array([ 4, 4, 1, 2, 2, 3, 2, 3])
ann_chan = np.array([3, 1, 2, 3, 4, 5, 6, 7])
ann_custom_labels = {'label_store': [1, 2, 3, 4], 'symbol': ['v', 'l', 'r', 'z'], 'description': ['pvc', 'lbbb', 'rbbb', 'pac']}
ann_custom_labels = pd.DataFrame(data=ann_custom_labels)
wfdb.wrann('A0001', 'atr', ann_idx, chan=ann_chan, label_store=ann_label_store,custom_labels=ann_custom_labels)

However, there is a error.

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    wfdb.wrann('A0001', 'atr', ann_idx, chan=ann_chan, label_store=ann_label_store,custom_labels=ann_custom_labels)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wfdb/io/annotation.py", line 1525, in wrann
    annotation.wrann(write_fs=True, write_dir=write_dir)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wfdb/io/annotation.py", line 292, in wrann
    self.wr_ann_file(write_fs=write_fs, write_dir=write_dir)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wfdb/io/annotation.py", line 798, in wr_ann_file
    core_bytes = self.calc_core_bytes()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wfdb/io/annotation.py", line 937, in calc_core_bytes
    data_bytes.append(field2bytes('samptype', [sampdiff[i], self.symbol[i]]))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wfdb/io/annotation.py", line 1369, in field2bytes
    typecode = ann_label_table.loc[ann_label_table['symbol']==value[1], 'label_store'].values[0]
IndexError: index 0 is out of bounds for axis 0 with size 0

I think probably I used the incorrect way to write the custom labels.
Could you guide me on how to correctly use wfdb.wrann with custom_labels and label_store to write the annotation?
Thanks.

@nanli-emory nanli-emory changed the title How to use wfdb.wrann with custom_labels and label_store? How to use wfdb.wrann with custom_labels and label_store to write the custom labels? Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant