@@ -2710,8 +2710,9 @@ def rdedfann(record_name, pn_dir=None, delete_file=True, info_only=True,
2710
2710
fs = fs )
2711
2711
2712
2712
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 ):
2715
2716
"""
2716
2717
This function reads a pair of annotation files (specified by `ann_file1`
2717
2718
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,
2736
2737
out_file_name : string
2737
2738
The name of the output file name (with extension included). The
2738
2739
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.
2739
2753
start_ann : float, int, string, optional
2740
2754
The location (sample, time, etc.) to start the annotation filtering.
2741
2755
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,
2749
2763
be interpreted as sample number. If string, it will be interpreted
2750
2764
as time formatted in HH:MM:SS format (the same as that in `wfdbtime`).
2751
2765
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).
2759
2766
record_only : bool, optional
2760
2767
Whether to only return the annotation information (True) or not
2761
2768
(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,
2779
2786
raise Exception ('Annotation sample rates do not match up: samples '
2780
2787
'can be aligned but final sample rate can not be '
2781
2788
'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 )
2782
2798
2783
2799
if start_ann == 'e' :
2784
2800
raise Exception ('Start time can not be set to the end of the record' )
0 commit comments