Skip to content

Add numba check to sd_ratio #3890

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrishalcrow
Copy link
Collaborator

@chrishalcrow chrishalcrow commented Apr 28, 2025

Hello,

If you don't have numba installed and try to compute sd_ratio, like so:

import spikeinterface.full as si

rec, sort = si.generate_ground_truth_recording()
sa = si.create_sorting_analyzer(recording=rec, sorting=sort)
sa.compute(["noise_levels", "random_spikes", "templates", "spike_amplitudes"])
si.compute_quality_metrics(sa, metric_names=["sd_ratio"])

you get a tricky error message:

File "/Users/christopherhalcrow/Work/fromgit/spikeinterface/src/spikeinterface/qualitymetrics/misc_metrics.py", line 1472, in compute_sd_ratio
    from spikeinterface.curation.curation_tools import _find_duplicated_spikes_keep_first_iterative
ImportError: cannot import name '_find_duplicated_spikes_keep_first_iterative' from 'spikeinterface.curation.curation_tools' (/Users/christopherhalcrow/Work/fromgit/spikeinterface/src/spikeinterface/curation/curation_tools.py)

This is because sd_ratio uses _find_duplicated_spikes_keep_first_iterative which needs numba.

This PR checks for numba in compute_sd_ratio and gives a warning if it's not installed (I'd be mad if my pipeline crashed because of one quality metric):

UserWarning: 'sd_ratio' metric computation requires numba. Install it with >>> pip install numba. SD ratio metric will be set to NaN

I also use the conveinence function find_duplicated_spikes instead of _find_duplicated_spikes_keep_first_iterative, which would give a better error message if someone tried to use it.

EDIT: Also fixed a couple of typos and remove some commented out code.

Another option: if there's no numba, use a different find_duplicated_spikes method. Unfortunately, the different methods are genuinely different algorithms and give different results. Hence this is not a good idea for reproducibility.

@chrishalcrow chrishalcrow added the qualitymetrics Related to qualitymetrics module label Apr 28, 2025
Copy link
Collaborator

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
qualitymetrics Related to qualitymetrics module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants