Quality Metrics module
Quality metrics allows one to quantitatively assess the goodness of a spike sorting output.
The qualitymetrics module includes functions to compute a large variety of available metrics.
All of the metrics currently implemented in spikeInterface are per unit (pairwise metrics do appear in the literature).
Each metric aims to identify some quality of the unit. Contamination metrics (also sometimes called ‘false positive’ or ‘type I’ metrics) aim to identify the amount of noise present in the unit. Examples include: ISI violations, sliding refractory period violations, SNR, NN-hit rate. Completeness metrics (or ‘false negative’/’type II’ metrics) aim to identify whether any of the spiking activity is missing from a unit. Examples include: presence ratio, amplitude cutoff, NN-miss rate. Drift metrics aim to identify changes in waveforms which occur when spike sorters fail to successfully track neurons in the case of electrode drift.
The quality metrics are saved as an extension of a SortingAnalyzer. Some metrics can only be computed if certain extensions have been computed first. For example the drift metrics can only be computed the spike locations extension has been computed. By default, as many metrics as possible are computed. Which ones are computed depends on which other extensions have been computed.
In detail, the default metrics are (click on each metric to find out more about them!):
Inter-spike-interval (ISI) violations (isi_violation, rp_violation)
Sliding refractory period violations (sliding_rp_violations)
If spike_locations are computed, add:
If spike_amplitudes and templates are computed, add:
If noise_levels and templates are computed, add:
If the recording, spike_amplitudes and templates are available, add:
If principal_components are computed, add:
Nearest Neighbor Metrics (nn_hit_rate, nn_miss_rate, nn_isolation, nn_noise_overlap) (note: excluding the
nn_noise_overlapmetric)
You can compute the default metrics using the following code snippet:
# load or create a sorting analyzer
sorting_analyzer = si.load_sorting_analyzer(folder='my_sorting_analyzer')
# compute the metrics
sorting_analyzer.compute("quality_metrics")
# get the metrics in the form of a pandas DataFrame
quality_metrics = sorting_analyzer.get_extension("quality_metrics").get_data()
# print the metrics that have been computed
print(quality_metrics.columns)
Some metrics are very slow to compute when the number of units it large. So by default, the following metrics are not computed:
The
nn_noise_overlapfrom Nearest Neighbor Metrics (nn_hit_rate, nn_miss_rate, nn_isolation, nn_noise_overlap)
Some metrics make use of principal component analysis (PCA) to reduce the dimensionality of computations. Various approaches to computing the principal components are possible, and choice should be carefully considered in relation to the recording equipment used.
If you only want to compute a subset of metrics, you can use convenience functions to compute each one,
from spikeinterface.quality_metrics import compute_isi_violations
isi_violations = compute_isi_violations(sorting_analyzer, isi_threshold_ms=3.0)
This function returns the result of the computation but does not save it into the sorting_analyzer.
To save the result in your analyzer, you can use the compute method:
sorting_analyzer.compute(
"quality_metrics",
metric_names = ["isi_violation", "snr"],
extension_params = {
"isi_violation": {"isi_threshold_ms": 3.0},
}
)
Note that if you request a specific metric using metric_names and you do not have the required extension computed, this will error.
For more information about quality metrics, check out this excellent documentation from the Allen Institute.