Skip to content

Commit c374442

Browse files
committed
Adds chan mapping
1 parent f1c0355 commit c374442

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

wfdb/io/annotation.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,8 +2710,9 @@ def rdedfann(record_name, pn_dir=None, delete_file=True, info_only=True,
27102710
fs=fs)
27112711

27122712

2713-
def mrgann(ann_file1, ann_file2, out_file_name='merged_ann.atr', start_ann=0,
2714-
end_ann='e', merge_method='combine', record_only=True, verbose=False):
2713+
def mrgann(ann_file1, ann_file2, out_file_name='merged_ann.atr',
2714+
merge_method='combine', chan1=-1, chan2=-1, start_ann=0,
2715+
end_ann='e', record_only=True, verbose=False):
27152716
"""
27162717
This function reads a pair of annotation files (specified by `ann_file1`
27172718
and `ann_file2`) for the specified record and writes a third annotation
@@ -2736,6 +2737,19 @@ def mrgann(ann_file1, ann_file2, out_file_name='merged_ann.atr', start_ann=0,
27362737
out_file_name : string
27372738
The name of the output file name (with extension included). The
27382739
default is 'merged_ann.atr'.
2740+
merge_method : string, optional
2741+
The method used to merge the two annotation files. The default is
2742+
'combine' which simply combines the two files along every attribute;
2743+
duplicates will be preserved. The other options are 'replace1' which
2744+
replaces attributes of the first annotation file with attributes of
2745+
the second for the desired time range and 'replace2' which does the
2746+
same thing except switched (first file replaces second).
2747+
chan1 : int, optional
2748+
Sets the value of `chan` for the first annotation file. The default is
2749+
-1 which means to keep it the same.
2750+
chan2 : int, optional
2751+
Sets the value of `chan` for the second annotation file. The default
2752+
is -1 which means to keep it the same.
27392753
start_ann : float, int, string, optional
27402754
The location (sample, time, etc.) to start the annotation filtering.
27412755
If float, it will be interpreted as time in seconds. If int, it will
@@ -2749,13 +2763,6 @@ def mrgann(ann_file1, ann_file2, out_file_name='merged_ann.atr', start_ann=0,
27492763
be interpreted as sample number. If string, it will be interpreted
27502764
as time formatted in HH:MM:SS format (the same as that in `wfdbtime`).
27512765
The default is 'e' to represent the end of the annotation.
2752-
merge_method : string, optional
2753-
The method used to merge the two annotation files. The default is
2754-
'combine' which simply combines the two files along every attribute;
2755-
duplicates will be preserved. The other options are 'replace1' which
2756-
replaces attributes of the first annotation file with attributes of
2757-
the second for the desired time range and 'replace2' which does the
2758-
same thing except switched (first file replaces second).
27592766
record_only : bool, optional
27602767
Whether to only return the annotation information (True) or not
27612768
(False). If False, this function will generate a WFDB-formatted
@@ -2779,6 +2786,15 @@ def mrgann(ann_file1, ann_file2, out_file_name='merged_ann.atr', start_ann=0,
27792786
raise Exception('Annotation sample rates do not match up: samples '
27802787
'can be aligned but final sample rate can not be '
27812788
'determined')
2789+
# Apply the channel mapping if desired
2790+
if chan1 != -1:
2791+
if chan1 < -1:
2792+
raise Exception('Invalid value for `chan1`: must be >= 0')
2793+
ann1.chan = np.array([chan1] * ann1.ann_len)
2794+
if chan2 != -1:
2795+
if chan2 < -1:
2796+
raise Exception('Invalid value for `chan2`: must be >= 0')
2797+
ann2.chan = np.array([chan2] * ann2.ann_len)
27822798

27832799
if start_ann == 'e':
27842800
raise Exception('Start time can not be set to the end of the record')

0 commit comments

Comments
 (0)