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

Proposal to implement a sorting_analyzer.merge_units() syntax #3043

Merged
merged 369 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
369 commits
Select commit Hold shift + click to select a range
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
8cab632
WIP
yger Jun 18, 2024
9c2a813
WIP
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
9a6c115
WIP
yger Jun 19, 2024
e64542f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
501df84
WIP
yger Jun 19, 2024
f05b96c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
7e6274c
More extensions'
yger Jun 19, 2024
3406aed
Conflicts
yger Jun 19, 2024
7c889e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
f1e9f95
More extensions
yger Jun 19, 2024
12c59fc
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 19, 2024
8afe050
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
3b6984a
Merge branch 'main' into merging_units
yger Jun 19, 2024
888075b
Template similarity
yger Jun 19, 2024
0e0a30d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
27d56c8
Merge branch 'main' into merging_units
yger Jun 19, 2024
9f48741
More merging
yger Jun 19, 2024
dfb8489
Merge branch 'main' of https://github.com/SpikeInterface/spikeinterfa…
yger Jun 19, 2024
6241f5c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
c7de50e
Simplifications and speedup
yger Jun 19, 2024
9b6515c
Merge branch 'main' into merging_units
yger Jun 19, 2024
6bcb194
Passing tests
yger Jun 19, 2024
20ec554
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 19, 2024
07590ce
Merging
yger Jun 19, 2024
f0ed774
Extension to handle new_unit_ids post merges that can be arbitraty
yger Jun 20, 2024
93784ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 20, 2024
20d5ea2
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 20, 2024
abea8fd
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 20, 2024
e06d4f1
Fixes'
yger Jun 21, 2024
debb576
Support for merges is now the union
yger Jun 21, 2024
cfce511
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
c46c24a
Patching and sorting extensions
yger Jun 21, 2024
6bf1037
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 21, 2024
b0a2268
Update src/spikeinterface/core/sortinganalyzer.py
yger Jun 21, 2024
e2289a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
70d8ac5
Weighted sums
yger Jun 21, 2024
bd2998e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
7761127
WIP
yger Jun 21, 2024
d30bc2e
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 21, 2024
89e6479
Merge branch 'main' into merging_units
yger Jun 21, 2024
e319636
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
1e49c02
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 21, 2024
4bebc2c
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 21, 2024
92f783d
WIP
yger Jun 21, 2024
56bbe19
Merge branch 'main' into meta_merging_sc2
alejoe91 Jun 21, 2024
02779ee
Starting to go for quality metrics
yger Jun 21, 2024
a05a7c4
Merge branch 'main' into merging_units
yger Jun 21, 2024
d55c69c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
452fb1e
Metrics are recomputed only for merges
yger Jun 22, 2024
a556b5c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 22, 2024
7bd7b57
Merge branch 'main' into merging_units
yger Jun 22, 2024
53a179f
More work if we need to recompute masks when merging
yger Jun 23, 2024
d3b11a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2024
5dad6c0
Handling union of sparsity
yger Jun 23, 2024
898bf8a
Handling union of sparsity
yger Jun 23, 2024
0838ff3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2024
6be52fa
Censor period to be added
yger Jun 23, 2024
6b34abc
Bug
yger Jun 24, 2024
a7edcff
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 24, 2024
d485ef7
WIP
yger Jun 24, 2024
6e2997b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
cd35ac9
Redesign the API based on discussion
yger Jun 24, 2024
dfcc8a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
15afb26
WIP, but issues in random_spikes
yger Jun 24, 2024
091c780
WIP, but issues in random_spikes
yger Jun 24, 2024
1f6b8c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
167b91f
Almost there, fixing random_spikes
yger Jun 24, 2024
19861ab
Docs
yger Jun 24, 2024
d6b355f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
e910021
Merge branch 'main' into merging_units
yger Jun 24, 2024
66a1b93
Docs
yger Jun 24, 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
b018a37
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
cc9e438
Check for the soft mode
yger Jun 25, 2024
f4740fb
Patches, now working
yger Jun 25, 2024
2193534
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 25, 2024
14641c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
f93042a
Merge branch 'main' into merging_units
yger Jun 25, 2024
7953ed4
Factorizing the function to get new ids during merging
yger Jun 25, 2024
d520b28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
7b88ff6
Dealing with waveforms
yger Jun 26, 2024
4338fe3
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
3bf14bc
Merge branch 'main' into merging_units
yger Jun 26, 2024
f26a7e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
49cf782
In place modifification of the spike vector
yger Jun 26, 2024
60fa650
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
5b8f2c1
Sync with main
yger Jun 26, 2024
3fb1fa1
Compatibility with new template_similarity
yger Jun 26, 2024
1a5268f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
4f30bb5
Moving function to avoid numba
yger Jun 26, 2024
167aa5c
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
184b2f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
279c5de
Forgot one import
yger Jun 26, 2024
5bd44bf
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
4db85c7
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jun 26, 2024
53436b8
Merge branch 'main' into merging_units
yger Jun 26, 2024
f265bd1
Faster recompute for hard mode
yger Jun 26, 2024
283fd7f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
3d73d80
Fixing tests
yger Jun 26, 2024
531897e
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
df44a0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
84812d5
Bug with new template similarity
yger Jun 26, 2024
73e8eaa
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 26, 2024
b9c2638
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
34a1bc2
Fixing bug
yger Jun 27, 2024
513c804
Corner cases and bug if analyzer is not sparse
yger Jun 27, 2024
f7bec43
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 27, 2024
1b46e99
Merge branch 'main' into merging_units
yger Jun 27, 2024
f30aa40
Side effects in SC2
yger Jun 27, 2024
f455878
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 27, 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
52ae65e
Harmonization between waveforms and PCA
yger Jun 28, 2024
6cc2f4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
b7aa531
Setting to 0 former values because of copy
yger Jun 28, 2024
5e69a57
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jun 28, 2024
d582da4
Naming
yger Jun 28, 2024
c37dae3
Merge branch 'SpikeInterface:main' into merging_units
yger Jun 29, 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
14d2002
Issue with kept indices
yger Jul 1, 2024
a3cc09b
Catching cases with no units to merge
yger Jul 1, 2024
6fe1483
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 1, 2024
8772547
Merge branch 'main' into merging_units
yger Jul 1, 2024
3211df7
Extensions are for all spikes
yger Jul 1, 2024
fdebd55
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jul 1, 2024
300f9ee
Merge branch 'main' into merging_units
yger Jul 2, 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
939da1c
fix get_some_waveforms channel ids
alejoe91 Jul 2, 2024
5a3210b
fix bug in plot_unit_waveforms
alejoe91 Jul 2, 2024
2389c6f
Merge branch 'main' into merging_units
yger Jul 3, 2024
0607450
Adding a curation step for too small SNR
yger Jul 3, 2024
933dfe9
wip: add template metrics and tests
alejoe91 Jul 3, 2024
222b5a1
wip: add template metrics and tests
alejoe91 Jul 3, 2024
4397020
extend merge data for ccg to multi-segment
alejoe91 Jul 3, 2024
3fab31c
fix dense pca merge units
alejoe91 Jul 3, 2024
ac3a805
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
alejoe91 Jul 3, 2024
df0bfb9
Recompute ccgs upon merging
alejoe91 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
dfa6566
Merge branch 'main' into merging_units
yger 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
aea39be
Fix pca/waveforms/template_metrics merge data and update params in lo…
alejoe91 Jul 5, 2024
a189529
Fix spike indices of waveforms and pca merge units
alejoe91 Jul 5, 2024
f67e0c4
correlogram comment
alejoe91 Jul 5, 2024
e124ee1
check and add extensive tests for get_some_waveforms/get_some_project…
alejoe91 Jul 5, 2024
ff80e8a
Adding tests
yger Jul 5, 2024
4acfa41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 5, 2024
4a0599b
Switch to keep_mask
yger Jul 5, 2024
8b35bfc
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jul 5, 2024
b25e632
partial conflicts
alejoe91 Jul 5, 2024
52f75e1
fix conflicts
alejoe91 Jul 5, 2024
be8a13b
revert metamerging changes
alejoe91 Jul 5, 2024
f91a039
Merge with #3154
alejoe91 Jul 6, 2024
6c46085
Update src/spikeinterface/core/sorting_tools.py
alejoe91 Jul 6, 2024
82e8dbf
Fixing tests
yger Jul 7, 2024
19ad820
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2024
caf15df
Large speedup for waveforms/pca
yger Jul 7, 2024
817302f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2024
e4b2a4a
Fixing bugs
yger Jul 7, 2024
1878fa4
Fixing bugs
yger Jul 7, 2024
8a25138
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2024
a3ead81
Some more optimizations, to reduce memory after merges
yger Jul 8, 2024
c783d75
Some change by Sam and Alessio to refactor the merge on analyzer
samuelgarcia Jul 8, 2024
db356e7
wip
samuelgarcia Jul 8, 2024
d3a07ef
Simpler waveforms and pca alignement after sparsity
samuelgarcia Jul 8, 2024
9b6eb38
oups
samuelgarcia Jul 8, 2024
feb0ff8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2024
f313a60
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger Jul 9, 2024
5e29e24
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jul 9, 2024
b4e2cc6
add test multi extension
samuelgarcia Jul 9, 2024
357ead3
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
samuelgarcia Jul 9, 2024
a040e6a
First fixes
yger Jul 9, 2024
f959002
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
yger Jul 9, 2024
c07de20
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 9, 2024
8abd708
Done
yger Jul 9, 2024
b143e37
Bringing back indices
yger Jul 9, 2024
09d8583
Fixing test
yger Jul 9, 2024
48e9e34
Fixing tests
yger Jul 9, 2024
06979b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 9, 2024
e324434
Fixing tests
yger Jul 9, 2024
798811f
Merge branch 'main' into merging_units
yger Jul 9, 2024
5216d97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 9, 2024
13d0be9
Goc back to previous situation for get_some_projection()
samuelgarcia Jul 10, 2024
b87d28e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 11, 2024
7ec8a46
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 Jul 11, 2024
2f2fe7e
Extend merge postprocessing tests and fix pca and template_metrics
alejoe91 Jul 11, 2024
6d79358
Recompute unit_location after merging
samuelgarcia Jul 12, 2024
ff377b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2024
4fb9438
rewrite merging unit in template similarity
samuelgarcia Jul 12, 2024
6ff2185
wip
samuelgarcia Jul 12, 2024
c128d39
Fix a few unit_ids not None problem in quality metrics
samuelgarcia Jul 12, 2024
ea1ae05
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
samuelgarcia Jul 12, 2024
95c45f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2024
872a506
unit_ids in compute_synchrony_metrics
samuelgarcia Jul 12, 2024
f2d71ba
Merge branch 'merging_units' of github.com:yger/spikeinterface into m…
samuelgarcia Jul 12, 2024
3939a97
oups
samuelgarcia Jul 12, 2024
cce9690
More fixes
samuelgarcia Jul 12, 2024
a04d58b
Select large templates to merge
alejoe91 Jul 12, 2024
34cea11
wip curation docs
alejoe91 Jul 15, 2024
6dab89e
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 Jul 15, 2024
f0079c2
wip docs
alejoe91 Jul 15, 2024
8da1f33
Extend curation doc
alejoe91 Jul 15, 2024
d94155f
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 Jul 15, 2024
10ebd21
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 Jul 15, 2024
575f67d
Add curation ref
alejoe91 Jul 15, 2024
171f861
Better ref
alejoe91 Jul 15, 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
Binary file added doc/images/spikeinterface_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions doc/modules/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,20 @@ backends without writing to disk. So, you can compute an extension *in-memory* w
you have decided on your desired parameters you can either use :code:`compute` with :code:`save=True` or use :code:`save_as`
to write everything out to disk.


Finally, the :code:`SortingAnalyzer` object can be used directly to curate a spike sorting output by selecting/removing units
and merging unit groups.

.. code-block:: python

sorting_analyzer_select = sorting_analyzer.select_units(unit_ids=[0, 1, 2, 3])
sorting_analyzer_remove = sorting_analyzer.remove_units(remove_unit_ids=[0])
sorting_analyzer_merge = sorting_analyzer.merge_units([0, 1], [2, 3])

All computed extensions will be automatically propagated or merged when curating. Please refer to the
:ref:`modules/curation` documentation for more information.


Event
-----

Expand Down
298 changes: 230 additions & 68 deletions doc/modules/curation.rst

Large diffs are not rendered by default.

172 changes: 154 additions & 18 deletions src/spikeinterface/core/analyzer_extension_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* ComputeNoiseLevels which is very convenient to have
"""

import warnings

import numpy as np

from .sortinganalyzer import AnalyzerExtension, register_result_extension
Expand Down Expand Up @@ -76,6 +78,20 @@ def _select_extension_data(self, unit_ids):
new_data["random_spikes_indices"] = np.flatnonzero(selected_mask[keep_spike_mask])
return new_data

def _merge_extension_data(
self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, keep_mask=None, verbose=False, **job_kwargs
):
new_data = dict()
random_spikes_indices = self.data["random_spikes_indices"]
if keep_mask is None:
new_data["random_spikes_indices"] = random_spikes_indices.copy()
else:
spikes = self.sorting_analyzer.sorting.to_spike_vector()
selected_mask = np.zeros(spikes.size, dtype=bool)
selected_mask[random_spikes_indices] = True
new_data["random_spikes_indices"] = np.flatnonzero(selected_mask[keep_mask])
return new_data

def _get_data(self):
return self.data["random_spikes_indices"]

Expand Down Expand Up @@ -224,18 +240,66 @@ def _select_extension_data(self, unit_ids):

return new_data

def get_waveforms_one_unit(
self,
unit_id,
force_dense: bool = False,
def _merge_extension_data(
self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, keep_mask=None, verbose=False, **job_kwargs
):
new_data = dict()

waveforms = self.data["waveforms"]
some_spikes = self.sorting_analyzer.get_extension("random_spikes").get_random_spikes()
if keep_mask is not None:
spike_indices = self.sorting_analyzer.get_extension("random_spikes").get_data()
valid = keep_mask[spike_indices]
some_spikes = some_spikes[valid]
waveforms = waveforms[valid]
else:
waveforms = waveforms.copy()

old_sparsity = self.sorting_analyzer.sparsity
if old_sparsity is not None:
# we need a realignement inside each group because we take the channel intersection sparsity
for group_ids in merge_unit_groups:
group_indices = self.sorting_analyzer.sorting.ids_to_indices(group_ids)
group_sparsity_mask = old_sparsity.mask[group_indices, :]
group_selection = []
for unit_id in group_ids:
unit_index = self.sorting_analyzer.sorting.id_to_index(unit_id)
selection = np.flatnonzero(some_spikes["unit_index"] == unit_index)
group_selection.append(selection)
_inplace_sparse_realign_waveforms(waveforms, group_selection, group_sparsity_mask)

old_num_chans = int(np.max(np.sum(old_sparsity.mask, axis=1)))
new_num_chans = int(np.max(np.sum(new_sorting_analyzer.sparsity.mask, axis=1)))
if new_num_chans < old_num_chans:
waveforms = waveforms[:, :, :new_num_chans]

return dict(waveforms=waveforms)

def get_waveforms_one_unit(self, unit_id, force_dense: bool = False):
"""
Returns the waveforms of a unit id.

Parameters
----------
unit_id : int or str
The unit id to return waveforms for
force_dense : bool, default: False
If True, and SortingAnalyzer must be sparse then only waveforms on sparse channels are returned.

Returns
-------
waveforms: np.array
The waveforms (num_waveforms, num_samples, num_channels).
In case sparsity is used, only the waveforms on sparse channels are returned.
"""
sorting = self.sorting_analyzer.sorting
unit_index = sorting.id_to_index(unit_id)
# spikes = sorting.to_spike_vector()
# some_spikes = spikes[self.sorting_analyzer.random_spikes_indices]

waveforms = self.data["waveforms"]
some_spikes = self.sorting_analyzer.get_extension("random_spikes").get_random_spikes()

spike_mask = some_spikes["unit_index"] == unit_index
wfs = self.data["waveforms"][spike_mask, :, :]
wfs = waveforms[spike_mask, :, :]

if self.sorting_analyzer.sparsity is not None:
chan_inds = self.sorting_analyzer.sparsity.unit_id_to_channel_indices[unit_id]
Expand All @@ -252,6 +316,22 @@ def _get_data(self):
return self.data["waveforms"]


def _inplace_sparse_realign_waveforms(waveforms, group_selection, group_sparsity_mask):
# this is used by "waveforms" extension but also "pca"

# common mask is intersection
common_mask = np.all(group_sparsity_mask, axis=0)

for i in range(len(group_selection)):
chan_mask = group_sparsity_mask[i, :]
sel = group_selection[i]
wfs = waveforms[sel, :, :][:, :, : np.sum(chan_mask)]
keep_mask = common_mask[chan_mask]
wfs = wfs[:, :, keep_mask]
waveforms[:, :, : wfs.shape[2]][sel, :, :] = wfs
waveforms[:, :, wfs.shape[2] :][sel, :, :] = 0.0


compute_waveforms = ComputeWaveforms.function_factory()
register_result_extension(ComputeWaveforms)

Expand Down Expand Up @@ -298,16 +378,13 @@ def _set_params(self, ms_before: float = 1.0, ms_after: float = 2.0, operators=N

waveforms_extension = self.sorting_analyzer.get_extension("waveforms")
if waveforms_extension is not None:
nbefore = waveforms_extension.nbefore
nafter = waveforms_extension.nafter
else:
nbefore = int(ms_before * self.sorting_analyzer.sampling_frequency / 1000.0)
nafter = int(ms_after * self.sorting_analyzer.sampling_frequency / 1000.0)
ms_before = waveforms_extension.params["ms_before"]
ms_after = waveforms_extension.params["ms_after"]

params = dict(
operators=operators,
nbefore=nbefore,
nafter=nafter,
ms_before=ms_before,
ms_after=ms_after,
)
return params

Expand All @@ -316,6 +393,7 @@ def _run(self, verbose=False, **job_kwargs):

if self.sorting_analyzer.has_extension("waveforms"):
self._compute_and_append_from_waveforms(self.params["operators"])

else:
for operator in self.params["operators"]:
if operator not in ("average", "std"):
Expand Down Expand Up @@ -380,7 +458,6 @@ def _compute_and_append_from_waveforms(self, operators):
"random_spikes"
), "compute templates requires the random_spikes extension. You can run sorting_analyzer.get_random_spikes()"
some_spikes = self.sorting_analyzer.get_extension("random_spikes").get_random_spikes()

for unit_index, unit_id in enumerate(unit_ids):
spike_mask = some_spikes["unit_index"] == unit_index
wfs = waveforms[spike_mask, :, :]
Expand Down Expand Up @@ -410,11 +487,33 @@ def _compute_and_append_from_waveforms(self, operators):

@property
def nbefore(self):
return self.params["nbefore"]
if "ms_before" not in self.params:
# compatibility february 2024 > july 2024
self.params["ms_before"] = self.params["nbefore"] * 1000.0 / self.sorting_analyzer.sampling_frequency
warnings.warn(
"The 'nbefore' parameter is deprecated and it's been replaced by 'ms_before' in the params."
"You can save the sorting_analyzer to update the params.",
DeprecationWarning,
stacklevel=2,
)

nbefore = int(self.params["ms_before"] * self.sorting_analyzer.sampling_frequency / 1000.0)
return nbefore

@property
def nafter(self):
return self.params["nafter"]
if "ms_after" not in self.params:
# compatibility february 2024 > july 2024
warnings.warn(
"The 'nafter' parameter is deprecated and it's been replaced by 'ms_after' in the params."
"You can save the sorting_analyzer to update the params.",
DeprecationWarning,
stacklevel=2,
)
self.params["ms_after"] = self.params["nafter"] * 1000.0 / self.sorting_analyzer.sampling_frequency

nafter = int(self.params["ms_after"] * self.sorting_analyzer.sampling_frequency / 1000.0)
return nafter

def _select_extension_data(self, unit_ids):
keep_unit_indices = np.flatnonzero(np.isin(self.sorting_analyzer.unit_ids, unit_ids))
Expand All @@ -425,12 +524,43 @@ def _select_extension_data(self, unit_ids):

return new_data

def _merge_extension_data(
self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, keep_mask=None, verbose=False, **job_kwargs
):

all_new_units = new_sorting_analyzer.unit_ids
new_data = dict()
counts = self.sorting_analyzer.sorting.count_num_spikes_per_unit()
for key, arr in self.data.items():
new_data[key] = np.zeros((len(all_new_units), arr.shape[1], arr.shape[2]), dtype=arr.dtype)
for unit_index, unit_id in enumerate(all_new_units):
if unit_id not in new_unit_ids:
keep_unit_index = self.sorting_analyzer.sorting.id_to_index(unit_id)
new_data[key][unit_index] = arr[keep_unit_index, :, :]
else:
merge_group = merge_unit_groups[list(new_unit_ids).index(unit_id)]
keep_unit_indices = self.sorting_analyzer.sorting.ids_to_indices(merge_group)
# We do a weighted sum of the templates
weights = np.zeros(len(merge_group), dtype=np.float32)
for count, merge_unit_id in enumerate(merge_group):
weights[count] = counts[merge_unit_id]
weights /= weights.sum()
new_data[key][unit_index] = (arr[keep_unit_indices, :, :] * weights[:, np.newaxis, np.newaxis]).sum(
0
)
if new_sorting_analyzer.sparsity is not None:
chan_ids = new_sorting_analyzer.sparsity.unit_id_to_channel_indices[unit_id]
mask = ~np.isin(np.arange(arr.shape[2]), chan_ids)
new_data[key][unit_index][:, mask] = 0

return new_data

def _get_data(self, operator="average", percentile=None, outputs="numpy"):
if operator != "percentile":
key = operator
else:
assert percentile is not None, "You must provide percentile=..."
key = f"pencentile_{percentile}"
key = f"percentile_{percentile}"

templates_array = self.data[key]

Expand Down Expand Up @@ -582,6 +712,12 @@ def _select_extension_data(self, unit_ids):
# this do not depend on units
return self.data

def _merge_extension_data(
self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, keep_mask=None, verbose=False, **job_kwargs
):
# this do not depend on units
return self.data.copy()

def _run(self, verbose=False):
self.data["noise_levels"] = get_noise_levels(
self.sorting_analyzer.recording, return_scaled=self.sorting_analyzer.return_scaled, **self.params
Expand Down
2 changes: 2 additions & 0 deletions src/spikeinterface/core/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ def inject_some_split_units(sorting, split_ids: list, num_split=2, output_ids=Fa
-------
sorting_with_split : NumpySorting
A sorting with split units.
other_ids : dict
The dictionary with the split unit_ids. Returned only if output_ids is True.
"""
unit_ids = sorting.unit_ids
assert unit_ids.dtype.kind == "i"
Expand Down
Loading
Loading