Skip to content

Add numba check to sd_ratio#3890

Merged
alejoe91 merged 1 commit into
SpikeInterface:mainfrom
chrishalcrow:add-numba-check-to-sd-ratio
May 5, 2025
Merged

Add numba check to sd_ratio#3890
alejoe91 merged 1 commit into
SpikeInterface:mainfrom
chrishalcrow:add-numba-check-to-sd-ratio

Conversation

@chrishalcrow
Copy link
Copy Markdown
Member

@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 DEPRECATER: use "metrics" instead Related to qualitymetrics module label Apr 28, 2025
Copy link
Copy Markdown
Member

@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.

@alejoe91 alejoe91 added this to the 0.102.3 milestone May 2, 2025
Comment thread src/spikeinterface/qualitymetrics/misc_metrics.py
@alejoe91 alejoe91 merged commit d142fe4 into SpikeInterface:main May 5, 2025
15 checks passed
@chrishalcrow chrishalcrow deleted the add-numba-check-to-sd-ratio branch July 30, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qualitymetrics DEPRECATER: use "metrics" instead Related to qualitymetrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants