Skip to content

Commit 1c6639e

Browse files
committed
little tidy up
1 parent 162994f commit 1c6639e

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

src/spikeinterface/postprocessing/correlograms.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

src/spikeinterface/postprocessing/tests/test_extension_merges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_correlograms_merge():
2222
[["4", "1", "8"], ["2", "7", "0"], ["3", "9"], ["5", "6"]],
2323
]
2424

25-
new_unit_ids = [["2"], ["4"], ["4", "2"], ["1", "2", "3", "100"]]
25+
new_unit_ids = [["2"], ["4"], ["4", "2"], ["1", "2", "9", "100"]]
2626

2727
for new_id_strategy in ["append", "take_first", "user"]:
2828
for merge_unit_groups, new_unit_id in zip(trial_merges, new_unit_ids):

0 commit comments

Comments
 (0)