@@ -39,14 +39,22 @@ def _in_range(point, start, end):
3939
4040
4141def _sorting (starts , ends ): # li is the start values
42+ starts = starts .tolist ()
43+ ends = ends .tolist ()
4244 sort = [i for i in sorted (enumerate (starts ), key = lambda s : s [1 ])]
4345 sorted_starts = np .array ([s [1 ] for s in sort ])
4446 sorted_ends = np .array ([ends [s [0 ]] for s in sort ])
4547 return sorted_starts , sorted_ends
4648
4749
4850def union (ref , multi_tags ):
49- # now the simple case of 2 tags
51+ """
52+ Function to return the (non-overlapping) union of area tagged by multiple Tags
53+ or MultiTags of a specified DataArray.
54+ :param ref: the referenced array
55+ :param multi_tags: Tags or MultiTags that point to the tagged data
56+ :return: a list of DataViews
57+ """
5058 _check_valid (multi_tags , ref )
5159 if not isinstance (ref , nix .DataArray ):
5260 ref = multi_tags [0 ].references [ref ]
@@ -56,7 +64,7 @@ def union(ref, multi_tags):
5664 end_list = []
5765 for i , st in enumerate (starts ): # check if any duplicate
5866 covered = False
59- for ti , tmp_st , tmp_ed in enumerate (zip (start_list , end_list )):
67+ for ti , ( tmp_st , tmp_ed ) in enumerate (zip (start_list , end_list )):
6068 if _in_range (st , tmp_st , tmp_ed ) or _in_range (ends [i ], tmp_st , tmp_ed ):
6169 covered = True
6270 if not _in_range (ends [i ], tmp_st , tmp_ed ): # ends[i] > tmp_ed
@@ -75,6 +83,12 @@ def union(ref, multi_tags):
7583
7684
7785def intersection (ref , multi_tags ):
86+ """
87+ Function to return the overlapping area in a specified DataArray tagged by multiple Tags/MultiTags.
88+ :param ref: the referenced array
89+ :param multi_tags: Tags or MultiTags that point to the tagged data
90+ :return: a DataView
91+ """
7892 _check_valid (multi_tags , ref )
7993 if not isinstance (ref , nix .DataArray ):
8094 ref = multi_tags [0 ].references [ref ]
0 commit comments