Skip to content

Commit 4fcf271

Browse files
committed
Allow custom labels in field2bytes
1 parent 4c784fa commit 4fcf271

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

wfdb/io/annotation.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,14 +1170,14 @@ def calc_core_bytes(self):
11701170

11711171
# Process the samp (difference) and sym items
11721172
data_bytes.append(
1173-
field2bytes("samptype", [sampdiff[i], self.symbol[i]])
1173+
field2bytes("samptype", [sampdiff[i], self.symbol[i]], self.custom_labels)
11741174
)
11751175

11761176
# Process the extra optional fields
11771177
for field in extra_write_fields:
11781178
value = getattr(compact_annotation, field)[i]
11791179
if value is not None:
1180-
data_bytes.append(field2bytes(field, value))
1180+
data_bytes.append(field2bytes(field, value, self.custom_labels))
11811181

11821182
# Flatten and convert to correct format
11831183
data_bytes = np.array(
@@ -1600,7 +1600,7 @@ def compact_carry_field(full_field):
16001600
return compact_field
16011601

16021602

1603-
def field2bytes(field, value):
1603+
def field2bytes(field, value, custom_labels=None):
16041604
"""
16051605
Convert an annotation field into bytes to write.
16061606
@@ -1619,11 +1619,17 @@ def field2bytes(field, value):
16191619
"""
16201620
data_bytes = []
16211621

1622+
# allow use of custom labels
1623+
label_table = ann_label_table
1624+
if custom_labels is not None:
1625+
label_table = pd.concat([label_table, custom_labels], ignore_index=True)
1626+
print(label_table)
1627+
16221628
# samp and sym bytes come together
16231629
if field == "samptype":
16241630
# Numerical value encoding annotation symbol
1625-
typecode = ann_label_table.loc[
1626-
ann_label_table["symbol"] == value[1], "label_store"
1631+
typecode = label_table.loc[
1632+
label_table["symbol"] == value[1], "label_store"
16271633
].values[0]
16281634

16291635
# sample difference

0 commit comments

Comments
 (0)