Skip to content

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

Closed
@nanli-emory

Description

@nanli-emory

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions