-
Notifications
You must be signed in to change notification settings - Fork 314
Allow custom labels in field2bytes #404
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
Conversation
4fcf271
to
99a4737
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thank you.
Could you please add a test case?
Also, I'm curious to know: why do you want to write WFDB annotation files? Trying to get a gauge of what's useful and where to focus future efforts, thanks. |
We were trying to write the custom beat labels into WFDB annotation format. 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 an error as follows.
After we checked the code and found out the python code never use custom_labels to store the symbol/labels. So my colleague tries to fix the bug that allows storing custom labels in WFDB annotation format. The test code that we use: import wfdb
import numpy as np
import pandas as pd
ann_idx = np.array([1, 1000, 2000, 3000, 4000, 5000, 6000, 7000])
ann_chan = np.array([3, 1, 2, 3, 4, 5, 6, 7])
# write custom labels
ann_label_store = np.array([ 4, 4, 1, 2, 2, 3, 2, 3])
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, custom_labels=ann_custom_labels, label_store=ann_label_store)
# read
ann = wfdb.rdann('A0001', 'atr')
print(ann.sample)
print(ann.custom_labels)
print(ann.symbol)
print(ann.label_store)
print(ann.chan) After fixed the result:
|
Thank you. I've added a test case to the pytest suite in f01a151. Please let me know if this needs some code style changes, or anything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
Fixes #399
Take custom labels into account in encoding, should they exist by temporarily creating a larger version of ann_label_table including custom labels.