@@ -108,17 +108,25 @@ def _merge_extension_data(
108108 # if censor_ms has no effect, can apply "soft" method. Check if any spikes have been removed
109109 for new_unit_id , merge_unit_group in zip (new_unit_ids , merge_unit_groups ):
110110
111- merged_spike_train_length = len (new_sorting_analyzer .sorting .get_unit_spike_train (new_unit_id ))
111+ num_segments = new_sorting_analyzer .get_num_segments ()
112+ for segment_index in range (num_segments ):
112113
113- old_spike_train_lengths = len (
114- np .concatenate (
115- [self .sorting_analyzer .sorting .get_unit_spike_train (unit_id ) for unit_id in merge_unit_group ]
114+ merged_spike_train_length = len (
115+ new_sorting_analyzer .sorting .get_unit_spike_train (new_unit_id , segment_index = segment_index )
116116 )
117- )
118117
119- if merged_spike_train_length != old_spike_train_lengths :
120- can_apply_soft_method = False
121- break
118+ old_spike_train_lengths = len (
119+ np .concatenate (
120+ [
121+ self .sorting_analyzer .sorting .get_unit_spike_train (unit_id , segment_index = segment_index )
122+ for unit_id in merge_unit_group
123+ ]
124+ )
125+ )
126+
127+ if merged_spike_train_length != old_spike_train_lengths :
128+ can_apply_soft_method = False
129+ break
122130
123131 if can_apply_soft_method is False :
124132 new_ccgs , new_bins = _compute_correlograms_on_sorting (new_sorting_analyzer .sorting , ** self .params )
@@ -134,11 +142,14 @@ def _merge_extension_data(
134142
135143 merge_unit_group_indices = self .sorting_analyzer .sorting .ids_to_indices (merge_unit_group )
136144
145+ # Sum unit rows of the correlogram matrix: C_{k,l} = C_{i,l} + C_{j,l}
146+ # and place this sum in the first unit index from the merge group
137147 new_col = np .sum (correlograms [merge_unit_group_indices , :, :], axis = 0 )
138-
139148 correlograms [merge_unit_group_indices [0 ], :, :] = new_col
140149 correlograms [merge_unit_group_indices [1 :], :, :] = 0
141150
151+ # Sum unit columns of the correlogram matrix: C_{l,k} = C_{l,i} + C_{l,j}
152+ # and put this sum in the first unit index from the merge group
142153 new_row = np .sum (correlograms [:, merge_unit_group_indices , :], axis = 1 )
143154 correlograms [:, merge_unit_group_indices [0 ], :] = new_row
144155 correlograms [:, merge_unit_group_indices [1 :], :] = 0
@@ -147,6 +158,8 @@ def _merge_extension_data(
147158 need_to_append = True
148159 delete_from = 0
149160
161+ # When new_id_strategy='append' is used, the new summed rows/columns to the
162+ # end of the correlogram matrix
150163 if need_to_append is True :
151164 old_num_units = np .shape (correlograms )[0 ]
152165 correlograms = np .pad (correlograms , ((0 , len (new_unit_ids )), (0 , len (new_unit_ids )), (0 , 0 )))
@@ -158,6 +171,7 @@ def _merge_extension_data(
158171 correlograms [:, [old_loc , new_loc ], :] = correlograms [:, [new_loc , old_loc ], :]
159172 correlograms [[old_loc , new_loc ], :, :] = correlograms [[new_loc , old_loc ], :, :]
160173
174+ # Delete the leftover units from the merge
161175 units_to_delete = np .concatenate ([merge_unit_group [delete_from :] for merge_unit_group in merge_unit_groups ])
162176 indices_to_delete = self .sorting_analyzer .sorting .ids_to_indices (units_to_delete )
163177
0 commit comments