-
Notifications
You must be signed in to change notification settings - Fork 36
Detailed overview of quality metrics
Quality metrics to weed out noise units:
- Number of waveform peaks
- Number of waveform troughs
- Waveform peak-to-trough duration
- Waveform spatial decay
- Waveform baseline 'flatness'
Quality metrics to classify non-somatic units:
Quality metrics to weed out multi-units:
- Number of spikes
- Percentage of spikes below detection threshold
- Fraction of refractory period violations
- Drift estimate
- Presence ratio
- Mean raw waveform amplitude
- Signal-to-noise ratio
- Distance metrics: isolation distance, L-ratio and silhouette score
Detailed overview of bombcell's summary global output plots
Spikes that come from real neurons (as opposed to being artifacts) have stereotypical waveform shapes that typically include a set number of peaks (1-2) and troughs (1), waveforms with set durations, and a waveform with spatial decay across channels. We use the following waveform-based metrics to weed-out artefactual units.
Units with a template waveform containing more than detected peaks (qMetric.nPeaks
) than param.maxNPeaks
are classified as noise.
Units with a template waveform containing more detected troughs (qMetric.nTroughs
) than param.maxNTroughs
are classified as noise.
Units with peak-to-trough template waveform durations (qMetric.waveformDuration_peakTrough
) of less than param.minWvDuration
us or more than param.maxWvDuration
are classified as noise.

We compute each units spatial decay by taking the waveform's absolute maximum value for each unit, on the peak channel and channels up to 75-100 um away from the peak channel. We use MATLAB's function polyfit
to fit a first-order polynomial to these points and extract the slope of this fit.
Units with a spatial decay slope (qMetric.spatialDecaySlope
) of less than param.minSpatialDecaySlope
(a.u.)/um
Empirically, we noticed that artefactual units often had a 'non-flat' baseline (see below). To quantify this, we compute how large the biggest value in the window param.waveformBaselineWindowStart:param.waveformBaselineWindowStop
is relative to the waveforms largest value.
Units with a maximum waveform baseline value (qMetric.waveformBaselineFlatness
) exceeding a fraction of the waveforms maximum absolute value by param.maxWvBaselineFraction
are classified as noise.
Somatic waveforms are defined as waveforms where the largest trough precedes the largest peak, and the trough is larger than the peak (Deligkaris, Bullmann & Frey, 2016). If param.somatic
is equal to 1, the waveforms that meet these criteria are classified into a separate non-somatic category.
After classifying noise units, the remaining units are classified as good single units if the criteria below are met. They are classifying as multi-units otherwise.
Below a certain amount of spikes, ephys properties like ACGs will not be reliable. A good minimum to use is 300 empirically, because Kilosort2 does not attempt to split any clusters that have less than 300 spikes in the post-processing phase.
If a unit has less than param.minSpikes
spikes, it is classified as multi-unit activity.
The percent of spikes missing (false negatives) is estimated by fitting a gaussian the distribution of amplitudes, with a cutoff parameter. This assumes the spike amplitudes follow a gaussian distribution, which is not strictly true for bursty cells, like for instance Medium Spiny Neurons in the striatum.
Optionally, if param.computeTimeChunks
is true, the recording is split in time chunks of size param.deltaTimeChunk
, and the percentage of spikes missing (and the fraction of refractpry period violations -see below) is estimated separately on these time chunks. Then, only the time chunks with a percent of spikes missing and fraction of refractory period violations (see below) below the threshold are kept, and the rest of the quality metrics are computed on these epochs. These time points are stored in qMetric.useTheseTimesStart
and qMetric.useTheseTimesStop
. This can be of use in cases where there is a lot of drift during the recording. All subsequent metrics are computed only on these time chunks.
Two additional metrics are calculated, but not currently used:
-
qMetric.ksTest_pValue
gives the output p-value of a Kolmogorov–Smirnov test -
qMetric.percentageSpikesMissing_symmetric
estimates the percentage of spikes missing a distribution of spike amplitudes symmetric on both sides of its mode.
If the estimated percentage of spikes missing (qMetric.percentageSpikesMissing_gaussian
) is above the param.maxPercSpikesMissing
, the unit is classified as multi-unit activity.
Below: example of unit with many spikes below the detection threshold in the first two time chunks of the recording.

The fraction of refractory period violations (false positives) is estimated using r = 2*(tauR - tauC) * N^2 * (1-Fp) * Fp / T , solving for Fp, with tauR the refractory period, tauC the censored period, T the total experiment duration, r the number of refractory period violations, Fp the fraction of contamination. method from Hill et al., J. Neuro, 2011. tauC is defined in param.tauC
and tauR is defined in param.tauR_valuesMin
, in seconds.
Optionally, if param.computeTimeChunks
is true, the recording is split in time chunks of size param.deltaTimeChunk
, and the fraction of refractory period violations (and the percentage of spikes missing - see above) estimated separately on these time chunks. Then, only the time chunks with a fraction of refractory period violation and percentage of spikes missing (see above) below the threshold are kept, and the rest of the quality metrics are computed on these epochs. These time points are stored in qMetric.useTheseTimesStart
and qMetric.useTheseTimesStop
. This can be of use in cases where there is a lot of drift during the recording. All subsequent metrics are computed only on these time chunks.
Additionally, if param.tauR_valuesMax
is larger than param.tauR_valuesMin
, the fraction of refractory violations is calculated for several possible tauR values, ranging from param.tauR_valuesMin
to param.tauR_valuesMax
in steps of param.tauR_valuesStep
. This matrix (units by tauR value) of fraction of refractory period values is saved seperatly from the other quality metrics, in a templates._bc_fractionRefractoryPeriodViolationsPerTauR.parquet
file. The tauR value used to calculate the fraction of refractory periods to classify a unit is defined as the tauR value which gives the smallest estimate.
If the estimated percent of refractory period violations (qMetric.fractionRPVs_estimatedTauR
) is above param.maxRPVviolations
, the unit is classified as multi-unit activity.
Below: examples of a unit with a small fraction of refractory period violations (left) and one with a large fraction (right).

If param.computeDrift
is equal to 1, we estimate the amount of drift based on a metrics described in Seigle et al., 2021:
To compute the maximum drift for one unit, the peak channel was calculated from the top principal components of every spike. Next, the peak channel values are binned in 51-s intervals, and the median value is calculated across all spikes in each bin (assuming at least 10 spikes per bin). The maximum drift is defined as the difference between the maximum peak channel and the minimum peak channel across all bins. The average maximum drift across all units is used to identify sessions with a high amount of probe motion relative to the brain.
Each units cumulative drift is also calculated, and stored in qMetric.cumDriftEstimate
. This metric is not currently in use.
Units with a maximum drift (qMetric.maxDriftEstimate
) larger than param.maxDrift
are classified as multi-unit activity.
Bombcell can uses anotherhelpful tool to assess drift, and can also define time chunks of low drift: optionally, if param.computeTimeChunks
is true, the recording is split in time chunks of size param.deltaTimeChunk
, and the fraction of refractory period violations and percentage of spikes missing is estimated separately on these time chunks. Then, only the time chunks with a fraction of refractory period violation and percentage of spikes missing below the threshold are kept, and the rest of the quality metrics are computed on these epochs. These time points are stored in qMetric.useTheseTimesStart
and qMetric.useTheseTimesStop
. This can be of use in cases where there is a lot of drift during the recording. All subsequent metrics are computed only on these time chunks.
The presence ratio is defined as number of time chunks of size param.presenceRatioBinSize
which contain at least one spike over the total number of time chunks in the recording.
Units with a presence ratio qMetric.presenceRatio
smaller than `` are classified as multi-unit activity.
Units with low amplitude are noisy, further away units, that are more likely to be multi-unit activity. If param.extractRaw
is equal to 1, bombcell extracts param.nRawSpikesToExtract
spikes of width param.spikeWidth
(in samples) from the raw binary file located at param.rawFile
. Bombcell then uses information in the recording's .meta or .oebin meta file located at param.ephysMetaFile
to get amplitude values in uV.
If a unit's raw mean waveform maximum amplitude is below param.minAmplitude
, it is classified as multi-unit activity.
Below: examples of a unit with high amplitude (blue) and one with low amplitude (red).

If param.extractRaw
is equal to 1, bombcell extracts param.nRawSpikesToExtract
spikes of width param.spikeWidth
(in samples) from the raw binary file located at param.rawFile
. A signal-to-noise ratio is calculated by taking each units maximum waveform value (on its peak channel) and dividing that by the variance across its raw extracted waveform baselines. The waveform baseline is defined by param.waveformBaselineNoiseWindow
(in samples).
Units with a signal-to-noise ratio (qMetric.signalToNoiseRatio
) below param.minSNR
are classified as multi-unit activity.
If param.computeDistanceMetrics
is equal to 1, bombcell computes a few distance metrics. This is the most time-consuming part of the script. See Harris et al., Neuron, 2001 for more information on isolation distance, (see Schmitzer-Torbert and Redish, 2004) for more information on l-ratio and (see Rousseeuw, 1987 for more information on silhouette-score.
Note that these metrics take a long time to compute, and they are not very robust to recordings with a lot of drift (as is the case for most acute Neuropixels recordings). For this reason, these distance metrics are disabled by default. Empirically, we have found that good proxies for how well a unit is isolated from others is the unit's mean raw waveform amplitude and signal-to-noise ratio. Neurons that are larger/closer to the probe tend to be well isolated.
If a unit has distance metrics below param.minIsoD
for the isolation distance, above param.lratioMax
for l-ratio, or above param.ssMax
for the silhouette score it is classified as multi-unit activity.
Below: examples of a unit with high isolation distance (left) and one with low isolation distance (right).

If param.plotGlobal
is set to true, after computing quality metrics, bombcell will output 3 summary plots for each dataset :
-
a Euler diagram of the number of units classified as noise/multi-unit with each quality metric. Numbers in the circles indicate the number of units classifying as noise/multi-unit by that quality metric/intersection of quality metrics.
-
for each a quality metric, a histogram of the distribution of values for all units. The red lines indicate classification thresholds.
-
template waveforms for each unit classified as good, multi-unit and noise, overlaid on top of each other. This is a quick way of checking there is no odd, noisy unit that has mistakenly been classified as either good or multi-unit.
💣 Any issues? To get support, create a github issue, create a pull request or write a message on the the Neuropixels slack workgroup.