Support a SortingAnalyzer with no unit in the core extensions - #4729
Open
adityasingh2400 wants to merge 1 commit into
Open
Support a SortingAnalyzer with no unit in the core extensions#4729adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
random_spikes_selection called np.concatenate on an empty list, and the sparse waveform and template paths called max() on an empty array, so a sorting with no unit crashed on the first extension. Empty results are now returned instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3679
A
SortingAnalyzerbuilt from a sorting with no unit crashes on the first extension withValueError: need at least one array to concatenate, which is the traceback reported in the issue. This comes up in real pipelines when a curation step removes every unit, for example when one shank of a multishank recording yields nothing. @alejoe91 confirmed in the issue that an analyzer with no unit is still a valid analyzer and should be handled.There are three places where the zero-unit case falls over. In
random_spikes_selection, the per-unit loop never runs sonp.concatenategets an empty list. Inextract_waveforms_to_single_bufferand inestimate_templates_with_accumulator, the sparse branch computesint(max(np.sum(sparsity_mask, axis=1)))on a mask that has no row, so builtinmaxraises on the empty iterable.estimate_templates_with_accumulatoradditionally assertsspikes.size > 0up front.The fix returns empty results at each of those points.
random_spikes_selectionreturns an empty int64 array, the two channel-count computations usenp.max(..., initial=0), andestimate_templates_with_accumulatorreturns zero-filled templates when there is no spike rather than allocating a zero-sized shared memory buffer. That last change also covers the case where units exist but all of them have zero spikes, which previously tripped the same assert. With these,random_spikes,noise_levels,waveformsandtemplatesall run on an empty analyzer in both dense and sparse mode, and the analyzer round-trips through the memory, binary_folder and zarr backends.Tested with
test_analyzer_with_no_unit(parametrized over sparse and dense) andtest_analyzer_with_only_empty_unitsintest_sortinganalyzer.py, plustest_random_spikes_selection_no_unitintest_sorting_tools.pycovering all four selection methods. Six of the seven new cases fail on main and all pass with the fix. The fulltest_sortinganalyzer.py,test_sorting_tools.py,test_waveform_tools.pyandtest_analyzer_extension_core.pysuites pass together, 60 passed.