Amplitude cutoff (amplitude_cutoff)

Calculation

First, all spike amplitudes for one unit are collapsed across time to create a histogram, then the histogram is smoothed using a 1D Gaussian filter. For some units, the amplitude histogram will not fall off gracefully to zero at the lower end, indicating that some spikes were likely missed by the sorter. To calculate the approximate fraction of missing spikes, we look at the height of the lowest amplitude bin, and count the number of spikes at the upper end of the distribution with amplitudes above a bin of similar height. The ratio of this count to the total number of spikes yields the amplitude cutoff.

Expectation and use

This metric can be considered an estimate of the fraction of false negatives (missed spikes) during the intervals over which a unit is successfully detected. Therefore, smaller amplitude cutoff values tend to indicate higher quality units. However, the actual fraction of missed spikes may be much higher if the unit is not tracked for a portion of the recording session. For this reason, amplitude cutoff should be combined with a metric such as presence ratio to more accurately estimate each unit’s overall completeness.

The calculation works best when the amplitude distribution is symmetric and has a single peak. Importantly, these assumptions likely do not hold if there is substantial drift. In this case, amplitude cutoff can be computed separately for different chunks of the recording, yielding a more accurate estimate of the fraction of spikes missing from each chunk.

IMPORTANT: When applying this metric, it is critical to know how the spike amplitudes were calculated. Template-based sorting algorithms such as Kilosort output the template scaling factors that are used to fit particular templates to each spike waveform. By multiplying the template amplitude by the scaling factor, one can approximate the original amplitude of each spike. However, this amplitude is not guaranteed to match the true amplitude. Amplitude cutoffs computed from the template scaling factors (amplitudes.npy in the Kilosort output) tend to be much higher than when using actual spike amplitudes extracted from the raw data. SpikeInterface uses amplitudes calculated from the raw data, but several large-scale electrophysiology surveys (such as those from the Allen Institute) use the template scaling factors. It’s important to know which method was used in order to compare amplitude cutoff values across studies.

Example code

import spikeinterface.qualitymetrics as sqm

# Combine sorting and recording into a sorting_analyzer
# It is also recommended to run sorting_analyzer.compute(input="spike_amplitudes")
# in order to use amplitudes from all spikes
fraction_missing = sqm.compute_amplitude_cutoffs(sorting_analyzer=sorting_analyzer, peak_sign="neg")
# fraction_missing is a dict containing the unit IDs as keys,
# and their estimated fraction of missing spikes as values.

Reference

spikeinterface.qualitymetrics.misc_metrics.compute_amplitude_cutoffs(sorting_analyzer, peak_sign='neg', num_histogram_bins=500, histogram_smoothing_value=3, amplitudes_bins_min_ratio=5, unit_ids=None)

Calculate approximate fraction of spikes missing from a distribution of amplitudes.

Parameters
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

peak_sign“neg” | “pos” | “both”, default: “neg”

The sign of the peaks.

num_histogram_binsint, default: 100

The number of bins to use to compute the amplitude histogram.

histogram_smoothing_valueint, default: 3

Controls the smoothing applied to the amplitude histogram.

amplitudes_bins_min_ratioint, default: 5

The minimum ratio between number of amplitudes for a unit and the number of bins. If the ratio is less than this threshold, the amplitude_cutoff for the unit is set to NaN.

unit_idslist or None

List of unit ids to compute the amplitude cutoffs. If None, all units are used.

Returns
all_fraction_missingdict of floats

Estimated fraction of missing spikes, based on the amplitude distribution, for each unit ID.

Notes

This approach assumes the amplitude histogram is symmetric (not valid in the presence of drift). If available, amplitudes are extracted from the “spike_amplitude” extension (recommended). If the “spike_amplitude” extension is not available, the amplitudes are extracted from the SortingAnalyzer, which usually has waveforms for a small subset of spikes (500 by default).

References

Inspired by metric described in [Hill]

This code was adapted from: https://github.com/AllenInstitute/ecephys_spike_sorting/tree/master/ecephys_spike_sorting/modules/quality_metrics

Literature

A version of this metric was first suggested by [Hill]. This paper suggested fitting a Gaussian distribution to the amplitude histogram to calculate the fraction of missing spikes, but this is not part of the SpikeInterface implementation. Instead, the upper end of the amplitude distribution is used to estimate the size of the lower end of the distribution.