Skip to content

Alter how quality metrics check extension dependencies #4080

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

chrishalcrow
Copy link
Member

@chrishalcrow chrishalcrow commented Jul 24, 2025

This PR changes how quality metrics are handled when an extension they depend on is missing.

The new behaviour is

  • if you explicitly ask for a metric to be computed (si.compute_snr or analyzer.compute('quality_metrics', metric_names=['snr']) and don't have the extension computed, this will error.
  • if you don't ask for any special metrics (analyzer.compute('quality_metrics')), this will compute all metrics it can. It will also gather all the metrics you can't compute, and why, and return a single warning.

The warning is e.g.

Some metrics you are trying to compute depend on other extensions:
    snr requires ['noise_levels', 'templates']
    amplitude_cutoff requires ['spike_amplitudes|waveforms', 'templates']
    amplitude_median requires ['spike_amplitudes|waveforms', 'templates']
    amplitude_cv requires ['spike_amplitudes|amplitude_scalings', 'templates']
    sd_ratio requires ['templates', 'spike_amplitudes']
    noise_cutoff requires ['spike_amplitudes']
To include these metrics, compute the required extensions using `sorting_analyzer.compute('extension_name')

Technically, we do this by doing a dependency check when we're figuring out which metrics to compute (done in _set_params of the ComputeQualityMetrics class). Then we don't include any metrics we don't have the extensions for.

If you call e.g. compute_snrs, it calls _has_required_extensions which does a check of the dependencies for a single metric, and raises the error message.

A nice consequence: now, the quality metrics extension has no dependencies, and will compute some spike-train related metrics if you give it an extension-less analyzer.

Made quite a big edit to the quality metrics modules docs page. Been meaning to do this for a while: https://spikeinterface--4080.org.readthedocs.build/en/4080/modules/qualitymetrics.html

We had discussed introducing a UnitMetric class or something. I think this is simpler for now!

@alejoe91 alejoe91 added the qualitymetrics Related to qualitymetrics module label Jul 28, 2025
@alejoe91 alejoe91 added this to the 0.103.0 milestone Jul 28, 2025
@alejoe91
Copy link
Member

That's good for me! For the spike_amplitudes/amplitude_scalings maybe we can do required_extensions=["spike_amplitudes|amplitude_scalings"] like we have in the core sorting analyzer here?

@alejoe91 alejoe91 removed this from the 0.103.0 milestone Jul 28, 2025
@chrishalcrow chrishalcrow changed the title Remove noise_levels and templates from quality metric deps Alter how quality metrics check extension dependencies Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qualitymetrics Related to qualitymetrics module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants