Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and benchmark auto-merging functions #2934

Closed
wants to merge 241 commits into from
Closed
Show file tree
Hide file tree
Changes from 143 commits
Commits
Show all changes
241 commits
Select commit Hold shift + click to select a range
0087705
WIP
yger May 29, 2024
57f40d8
Starting to reformat merging methods
yger May 30, 2024
ec92c01
WIP
yger May 30, 2024
8e39954
WIP
yger May 30, 2024
f0d8378
WIP
yger May 30, 2024
f453437
WIP
yger May 30, 2024
d5a541d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
08c5583
WIP
yger May 30, 2024
779b619
WIP
yger May 30, 2024
a811f66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
51517ab
WIP
yger May 30, 2024
2fa8ace
WIP
yger May 30, 2024
fce51e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
1693e07
WIP
yger May 30, 2024
9377d2c
WIP
yger May 30, 2024
f67b05b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
0c2b502
WIP
yger May 30, 2024
9cef54e
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 30, 2024
6cdddb7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
8b05581
Merge branch 'main' of github.com:yger/spikeinterface into meta_mergi…
yger May 31, 2024
3f9f556
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
5130db6
WIP
yger May 31, 2024
50135da
More plots
yger May 31, 2024
75963a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
8f7e2a0
WIP
yger May 31, 2024
d8e7537
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
7e766b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
fa48c56
WIP
yger May 31, 2024
5d950a2
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
bfbea8c
Getting rid of lussac imports
yger May 31, 2024
9ecd241
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
4fe600b
Spaces and tabs
yger May 31, 2024
3ccb5f9
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
96be6c8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
48329eb
Removing lussac imports
yger May 31, 2024
dd52f77
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
20e6ba9
WIP
yger May 31, 2024
60fc057
WIP
yger May 31, 2024
630273c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
3252e26
Fixing display
yger May 31, 2024
bb2c9a6
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger May 31, 2024
043f2a0
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Jun 2, 2024
c0d0333
Merge branch 'main' into meta_merging_sc2
yger Jun 4, 2024
fea71b4
Fix tests
alejoe91 Jun 4, 2024
4bd5fb0
Fix test imports
alejoe91 Jun 4, 2024
982c065
Fix more test imports
alejoe91 Jun 4, 2024
c51e79d
Renaming the drift suggestion for meta merging
yger Jun 4, 2024
31d8180
WIP
yger Jun 4, 2024
bc0898e
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 4, 2024
719a688
WIP
yger Jun 4, 2024
da862d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
9a69b14
Harmonize
yger Jun 4, 2024
2eee74e
CircusMerging is now able to do handle drift
yger Jun 4, 2024
e153c15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
cd08b35
WIP
yger Jun 4, 2024
bea35ee
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 4, 2024
4408a66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
d6a9c8d
WIP
yger Jun 5, 2024
df937cf
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 5, 2024
57749ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
82d021c
Harmonize lussac and circus meta merging
yger Jun 5, 2024
b956e26
Fixing conflicts
yger Jun 5, 2024
3f9f84c
Exploring params
yger Jun 5, 2024
ba459c6
Params
yger Jun 5, 2024
1a1a54b
WIP
yger Jun 5, 2024
283aae9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
0bde7bb
Docs
yger Jun 5, 2024
a71bd10
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 5, 2024
86e73e1
Docs
yger Jun 5, 2024
88c1bc8
Reuse the templates already available
yger Jun 5, 2024
9195a75
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
4ab001d
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 5, 2024
b7f54d7
Harmonize params
yger Jun 5, 2024
9d8a699
Adding possibility to only split cells given SNR
yger Jun 5, 2024
00f0a9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
7bc1c29
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 6, 2024
947a35d
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 6, 2024
30a7d36
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2024
3c0bb86
Handling precomputed similarities for curation
yger Jun 8, 2024
7468a64
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 8, 2024
5ff19a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2024
b0dab64
Prepare for the use of template_similarity instead
yger Jun 9, 2024
7f3d365
WIP to integrate Alessio's widget
yger Jun 10, 2024
76cb82d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
5f4fd0e
WIP
yger Jun 10, 2024
5087781
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 10, 2024
4643334
WIP
yger Jun 10, 2024
5d0277e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
fb6d1ba
WIP
yger Jun 10, 2024
a48ac2e
Lussac merging can use new metrics
yger Jun 12, 2024
f560406
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
8aca009
WIP
yger Jun 12, 2024
2c07c6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
65b01be
Merging curation functions
yger Jun 13, 2024
f0499e6
WIP
yger Jun 13, 2024
f7bd29b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
d777fae
WIP
yger Jun 13, 2024
56c3666
WIP
yger Jun 13, 2024
2d8df38
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
852521c
WIP
yger Jun 13, 2024
c806d02
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 13, 2024
c9cbd9e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
476fc31
Useless imports
yger Jun 13, 2024
9b30b5e
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 13, 2024
b2f2e8a
Delete Untitled.ipynb
yger Jun 13, 2024
e7f6655
Docs
yger Jun 13, 2024
cc066f1
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 13, 2024
640446a
Cleaning auto merge
yger Jun 13, 2024
7f6ed93
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
f201f71
WIP
yger Jun 13, 2024
c287f25
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 13, 2024
6098de8
Refactoring auto merges
yger Jun 13, 2024
1a29125
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
80f914d
Tests
yger Jun 14, 2024
036a729
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 14, 2024
2d3fbf1
Merge branch 'main' into meta_merging_sc2
yger Jun 14, 2024
b9b0dbb
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 14, 2024
4658758
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 14, 2024
0056eaf
Adding the extra method from Aurelien as a step in auto_merge for cla…
yger Jun 14, 2024
75a8804
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
8afab01
Factorize params
yger Jun 14, 2024
efc621c
Default params
yger Jun 14, 2024
35b71ec
Default params
yger Jun 14, 2024
2ad54dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
43fe534
Merge branch 'main' into meta_merging_sc2
yger Jun 17, 2024
4358040
WIP
yger Jun 17, 2024
0a1a400
WIP
yger Jun 17, 2024
4856aeb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 17, 2024
03d9ac6
Merge branch 'main' into meta_merging_sc2
yger Jun 18, 2024
f8b8e6c
WIP
yger Jun 19, 2024
b5b95de
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 19, 2024
e64542f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
07590ce
Merging
yger Jun 19, 2024
56bbe19
Merge branch 'main' into meta_merging_sc2
alejoe91 Jun 21, 2024
5c6edf8
WIP
yger Jun 24, 2024
e0165b3
WIP
yger Jun 24, 2024
2427c22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
31ddfec
Typo
yger Jun 24, 2024
0c7458e
WIP
yger Jun 24, 2024
2df7ad3
Refactoring
yger Jun 24, 2024
4c2bbcd
Merge branch 'main' into meta_merging_sc2
yger Jun 24, 2024
30f3617
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
4db85c7
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 26, 2024
10fce9d
Larger params
yger Jun 27, 2024
816f2fd
WIP
yger Jun 27, 2024
e437670
Bug
yger Jun 27, 2024
835ac4f
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Jun 28, 2024
750eba0
Adding Knn merging
yger Jun 28, 2024
3058a2f
WIP
yger Jun 28, 2024
c73e860
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
e5b02a5
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 28, 2024
55460a9
WIP
yger Jun 28, 2024
599755c
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Jun 29, 2024
63da29e
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jun 29, 2024
c3e2115
knn
yger Jun 29, 2024
f609b23
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2024
37ba955
WIP
yger Jul 1, 2024
a67b4d3
WIP
yger Jul 1, 2024
2ac4898
Merge branch 'main' into meta_merging_sc2
alejoe91 Jul 1, 2024
1f323f9
Sync with main
yger Jul 1, 2024
016d7cc
Fixes
yger Jul 2, 2024
71c4876
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 2, 2024
0607450
Adding a curation step for too small SNR
yger Jul 3, 2024
1a18a05
Fixes
yger Jul 3, 2024
478c173
Fix conflicts
alejoe91 Jul 4, 2024
25f740a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
9e9c3fd
Merge branch 'main' into meta_merging_sc2
alejoe91 Jul 4, 2024
a0bb321
cleanup, tests, automerge recordingless + multi-segment
alejoe91 Jul 4, 2024
37c7fb7
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
alejoe91 Jul 4, 2024
ae51c3a
fix tests
alejoe91 Jul 4, 2024
e1c3c31
fix lussac meta-merging component
alejoe91 Jul 4, 2024
bb127c9
Bring back the default mode for auto_merge
yger Jul 4, 2024
fc36bdc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
6c85de4
Bring back default old behaviour
yger Jul 4, 2024
722ff6a
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 4, 2024
d6d673a
Docs
yger Jul 5, 2024
d6bd776
Merge branch 'main' into meta_merging_sc2
yger Jul 7, 2024
01e5cc1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2024
84dea85
rebasing
yger Jul 8, 2024
d697b8c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2024
4d34a61
Merge branch 'main' into meta_merging_sc2
yger Jul 9, 2024
bd61e1b
polishing
yger Jul 9, 2024
6a6073f
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 9, 2024
a52dc64
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 9, 2024
50f6798
Adapt to new names
yger Jul 9, 2024
8449ee9
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 9, 2024
026bab4
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jul 9, 2024
ef9c25c
Cleaning
yger Jul 11, 2024
4150d31
Updating to main
yger Jul 15, 2024
b86f3a1
WIP
yger Jul 16, 2024
f906059
Sync with main
yger Jul 16, 2024
2678d54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
4dccd51
Sync with main
yger Jul 16, 2024
2700fb0
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 16, 2024
b6310de
Merge branch 'patch_release' into meta_merging_sc2
yger Jul 16, 2024
de21fe8
WIP
yger Jul 16, 2024
53f05e5
Merge branch 'patch_release' into meta_merging_sc2
yger Jul 16, 2024
f3c2d7b
WIP
yger Jul 17, 2024
4df391e
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jul 17, 2024
87158b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
98edbdb
Fixing tests
yger Jul 17, 2024
85623ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
164fa58
Adding iterative merges
yger Jul 17, 2024
61cde8c
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 17, 2024
c6e1e00
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
d3bb0a2
Refactoring
yger Jul 17, 2024
c9b57d9
Refactoring
yger Jul 17, 2024
c891245
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
64d2780
WIP
yger Jul 17, 2024
878fe99
Bringing back the components
yger Jul 17, 2024
09eeef3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
2b0c6bc
WIP
yger Jul 17, 2024
44b3e05
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
67526f5
Propagating job kwargs
yger Jul 17, 2024
09c5903
Merge branch 'fix_sa' of github.com:samuelgarcia/spikeinterface into …
yger Jul 17, 2024
7ebabe1
Debugging and trying old analyzers
yger Jul 17, 2024
0134d0d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
5c327fe
WIP
yger Jul 18, 2024
5d88ec2
Merge branch 'fix_sa' of github.com:samuelgarcia/spikeinterface into …
yger Jul 18, 2024
b88909d
Allowing extra_outputs
yger Jul 18, 2024
15934aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 18, 2024
e15c676
Bugs
yger Jul 18, 2024
d4fb25c
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 18, 2024
c3f11aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 18, 2024
787d3a1
Docs
yger Jul 18, 2024
711d0ff
Merge branch 'meta_merging_sc2' of github.com:yger/spikeinterface int…
yger Jul 18, 2024
3a72d1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 18, 2024
ba9d955
Ease the view of final merges
yger Jul 18, 2024
b97f60a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 18, 2024
b0a6212
Merge branch 'main' of https://github.com/SpikeInterface/spikeinterfa…
yger Jul 18, 2024
faebd26
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Jul 18, 2024
e1ef2a0
Avoid erasing already computed extensions
yger Jul 19, 2024
10a1c78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 19, 2024
970dd95
Force copy of the analyzer
yger Jul 19, 2024
61fc29b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 19, 2024
d6a7aee
Merge branch 'main' of https://github.com/SpikeInterface/spikeinterfa…
yger Jul 19, 2024
c9d673d
Fixes
yger Jul 23, 2024
5e99875
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Aug 26, 2024
f18124a
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Aug 27, 2024
fb27a6b
WIP
yger Sep 24, 2024
6ec9940
Merge branch 'SpikeInterface:main' into meta_merging_sc2
yger Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/spikeinterface/core/sorting_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,102 @@ def random_spikes_selection(
raise ValueError(f"random_spikes_selection(): method must be 'all' or 'uniform'")

return random_spikes_indices


def get_ids_after_merging(sorting, units_to_merge, new_unit_ids=None):
yger marked this conversation as resolved.
Show resolved Hide resolved
merged_unit_ids = set(sorting.unit_ids)
for count in range(len(units_to_merge)):
assert len(units_to_merge[count]) > 1, "A merge should have at least two units"
for unit_id in units_to_merge[count]:
assert unit_id in sorting.unit_ids, "Merged ids should be in the sorting"
if new_unit_ids is None:
for unit_id in units_to_merge[count][1:]:
merged_unit_ids.discard(unit_id)
else:
for unit_id in units_to_merge[count]:
merged_unit_ids.discard(unit_id)
merged_unit_ids = merged_unit_ids.union([new_unit_ids[count]])
return np.array(list(merged_unit_ids))


def apply_merges_to_sorting(sorting, units_to_merge, new_unit_ids=None, censor_ms=None):
"""
Function to apply a resolved representation of the merges to a sorting object. If censor_ms is not None,
duplicated spikes violating the censor_ms refractory period are removed

Parameters
----------
sorting: The Sorting object to apply merges
units_to_merge : list/tuple of lists/tuples
A list of lists for every merge group. Each element needs to have at least two elements (two units to merge),
but it can also have more (merge multiple units at once).
new_unit_ids : None or list
A new unit_ids for merged units. If given, it needs to have the same length as `units_to_merge`. If None,
merged units will have the first unit_id of every lists of merges
censor_ms: None or float
When applying the merges, should be discard consecutive spikes violating a given refractory per

Returns
-------
sorting : The new Sorting object
The newly create sorting with the merged units
kept_indices : A boolean mask, if censor_ms is not None, telling which spike from the original spike vector
has been kept, given the refractory period violations (None if censor_ms is None)
"""
spikes = sorting.to_spike_vector().copy()

if censor_ms is None:
to_keep = None
else:
to_keep = np.ones(len(spikes), dtype=bool)

if new_unit_ids is not None:
assert len(new_unit_ids) == len(units_to_merge), "new_unit_ids should have the same len as units_to_merge"
else:
new_unit_ids = [i[0] for i in units_to_merge]

all_unit_ids = get_ids_after_merging(sorting, units_to_merge, new_unit_ids)

segment_slices = {}
for segment_index in range(sorting.get_num_segments()):
s0, s1 = np.searchsorted(spikes["segment_index"], [segment_index, segment_index + 1], side="left")
segment_slices[segment_index] = (s0, s1)

if censor_ms is not None:
rpv = int(sorting.sampling_frequency * censor_ms / 1000)

max_index = len(sorting.unit_ids)

for unit_id, to_be_merged in zip(new_unit_ids, units_to_merge):
mask = np.in1d(spikes["unit_index"], sorting.ids_to_indices(to_be_merged))
if unit_id in sorting.unit_ids:
spikes["unit_index"][mask] = sorting.id_to_index(unit_id)
else:
spikes["unit_index"][mask] = max_index
max_index += 1

if censor_ms is not None:
for segment_index in range(sorting.get_num_segments()):
s0, s1 = segment_slices[segment_index]
(indices,) = s0 + np.nonzero(mask[s0:s1])
to_keep[indices[1:]] = np.diff(spikes[indices]["sample_index"]) > rpv

from spikeinterface.core import NumpySorting

times_list = []
labels_list = []
for segment_index in range(sorting.get_num_segments()):
s0, s1 = segment_slices[segment_index]
if censor_ms is not None:
times_list += [spikes["sample_index"][s0:s1][to_keep[s0:s1]]]
labels = spikes["unit_index"][s0:s1][to_keep[s0:s1]]
labels_list += [labels]
else:
times_list += [spikes["sample_index"][s0:s1]]
labels = spikes["unit_index"][s0:s1]
labels_list += [labels]

sorting = NumpySorting.from_times_labels(times_list, labels_list, sorting.sampling_frequency)
sorting = sorting.rename_units(all_unit_ids)

return sorting, to_keep
Loading
Loading