@@ -139,29 +139,22 @@ def _merge_extension_data(
139139 # construct the matrix we first make a dictionary of the form {old_index: new_index}
140140 old_to_new_unit_index_map = {}
141141 for old_unit in self .sorting_analyzer .unit_ids :
142+ old_unit_index = self .sorting_analyzer .sorting .id_to_index (old_unit )
142143 unit_involved_in_merge = False
143144 for merge_unit_group , new_unit_id in zip (merge_unit_groups , new_unit_ids ):
145+ new_unit_index = new_sorting_analyzer .sorting .id_to_index (new_unit_id )
144146 # check if the old_unit is involved in a merge
145147 if old_unit in merge_unit_group :
146- # check if it is mapped to itself?
148+ # check if it is mapped to itself
147149 if old_unit == new_unit_id :
148- old_to_new_unit_index_map [self .sorting_analyzer .sorting .id_to_index (old_unit )] = (
149- new_sorting_analyzer .sorting .id_to_index (new_unit_id )
150- )
150+ old_to_new_unit_index_map [old_unit_index ] = new_unit_index
151151 # or to a unit_id outwith the old ones
152152 elif new_unit_id not in self .sorting_analyzer .unit_ids :
153- if (
154- new_sorting_analyzer .sorting .id_to_index (new_unit_id )
155- not in old_to_new_unit_index_map .values ()
156- ):
157- old_to_new_unit_index_map [self .sorting_analyzer .sorting .id_to_index (old_unit )] = (
158- new_sorting_analyzer .sorting .id_to_index (new_unit_id )
159- )
153+ if new_unit_index not in old_to_new_unit_index_map .values ():
154+ old_to_new_unit_index_map [old_unit_index ] = new_unit_index
160155 unit_involved_in_merge = True
161156 if unit_involved_in_merge is False :
162- old_to_new_unit_index_map [self .sorting_analyzer .sorting .id_to_index (old_unit )] = (
163- new_sorting_analyzer .sorting .id_to_index (old_unit )
164- )
157+ old_to_new_unit_index_map [old_unit_index ] = new_sorting_analyzer .sorting .id_to_index (old_unit )
165158
166159 transformation_matrix = np .zeros (
167160 (len (new_sorting_analyzer .unit_ids ), len (self .sorting_analyzer .unit_ids )), dtype = "int"
@@ -179,14 +172,14 @@ def _merge_extension_data(
179172 merge_unit_group_indices = self .sorting_analyzer .sorting .ids_to_indices (merge_unit_group )
180173
181174 # Sum unit rows of the correlogram matrix: C_{k,l} = C_{i,l} + C_{j,l}
182- # and place this sum in the first unit index from the merge group
175+ # and place this sum in all indices from the merge group
183176 new_col = np .sum (correlograms [merge_unit_group_indices , :, :], axis = 0 )
184177 # correlograms[merge_unit_group_indices[0], :, :] = new_col
185178 correlograms [merge_unit_group_indices , :, :] = new_col
186179 # correlograms[merge_unit_group_indices[1:], :, :] = 0
187180
188181 # Sum unit columns of the correlogram matrix: C_{l,k} = C_{l,i} + C_{l,j}
189- # and put this sum in the first unit index from the merge group
182+ # and put this sum in all indices from the merge group
190183 new_row = np .sum (correlograms [:, merge_unit_group_indices , :], axis = 1 )
191184
192185 for merge_unit_group_index in merge_unit_group_indices :
0 commit comments