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

Assert that at least one unit is included when creating a sorting analyzer ? #3679

Open
b-grimaud opened this issue Feb 10, 2025 · 2 comments
Labels
core Changes to core module

Comments

@b-grimaud
Copy link
Contributor

b-grimaud commented Feb 10, 2025

I'm iterating over clustering parameters to try to find the best settings for my data.

To that end, I have a pipeline that goes : Clustering (HS2) -> Sorting Extractor -> Remove units with <10 spikes -> Sorting Analyzer -> Quality Metrics

Under some clustering conditions, this can result in sorting objects with no units left. This then results in a crash when computing the first extension, in this case random spikes :

Traceback (most recent call last):
  File "/home/user/Documents/ephy/test_clustering.py", line 80, in <module>
    analyzer.compute("random_spikes",
  File "/home/user/Documents/GitHub/spikeinterface/src/spikeinterface/core/sortinganalyzer.py", line 1324, in compute
    return self.compute_one_extension(extension_name=input, save=save, verbose=verbose, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/GitHub/spikeinterface/src/spikeinterface/core/sortinganalyzer.py", line 1405, in compute_one_extension
    extension_instance.run(save=save, verbose=verbose)
  File "/home/user/Documents/GitHub/spikeinterface/src/spikeinterface/core/sortinganalyzer.py", line 2170, in run
    self._run(**kwargs)
  File "/home/user/Documents/GitHub/spikeinterface/src/spikeinterface/core/analyzer_extension_core.py", line 58, in _run
    self.data["random_spikes_indices"] = random_spikes_selection(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/GitHub/spikeinterface/src/spikeinterface/core/sorting_tools.py", line 223, in random_spikes_selection
    random_spikes_indices = np.concatenate(random_spikes_indices)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: need at least one array to concatenate

While I understand this might be far from the typical use case, wouldn't it make sense to check for the presence of at least one unit in the create method of the sorting analyzer ?

I can draft a small PR if needed.

@zm711
Copy link
Collaborator

zm711 commented Feb 11, 2025

I think this makes sense, but I guess we could also just say this is the user's responsibility to check their sorting themselves before using it. I think this is a @alejoe91 and @samuelgarcia level decision.

@alejoe91 alejoe91 added the core Changes to core module label Feb 13, 2025
@alejoe91
Copy link
Member

@b-grimaud we discussed about this and we think that a sorting analyzer with no units is still a valid analyzer so we should deal with it.

@chrishalcrow will help making sure this is properly supported!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes to core module
Projects
None yet
Development

No branches or pull requests

3 participants