Drift metrics (drift_ptp, drift_std, drift_mad)

Calculation

Geometric positions and times of spikes within the cluster are estimated. Over the duration of the recording, the drift observed in positions of spikes is calculated in intervals, with respect to the overall median positions over the entire recording. These are referred to as “drift signals”.

  • The drift_ptp is the peak-to-peak of the drift signal for each unit.

  • The drift_std is the standard deviation of the drift signal for each unit.

  • The drift_mad is the median absolute deviation of the drift signal for each unit.

The SpikeInterface implementation differes from the original Allen because it uses spike location estimates (using compute_spike_locations() - either center of mass or monopolar triangulation), instead of the center of mass of the first PC projection. In addition the Allen Institute implementation assumes linear and equally spaced arrangement of channels.

Finally, the original “cumulative_drift” and “max_drift” metrics have been refactored/modified for the following reasons:

  • “max_drift” is calculated with the peak-to-peak, so it’s been renamed “drift_ptp”

  • “cumulative_drift” sums the absolute value of the drift signal for each interval. This makes it very sensitive to
    the number of bins (and hence the recording duration)! The “drift_std” and “drift_mad”, instead, are measures of
    the dispersion of the drift signal and are insensitive to the recording duration.

Expectation and use

Drift metrics represents how much, in um, a unit has moved over the recording. Larger values indicate more “drifty” units, possibly of lower quality.

Example code

import spikeinterface.qualitymetrics as sqm

# Combine sorting and recording into sorting_analyzer
# It is required to run sorting_analyzer.compute(input="spike_locations") first
# (if missing, values will be NaN)
drift_ptps, drift_stds, drift_mads = sqm.compute_drift_metrics(sorting_analyzer=sorting_analyzer peak_sign="neg")
# drift_ptps, drift_stds, and drift_mads are each a dict containing the unit IDs as keys,
# and their metrics as values.

Reference

spikeinterface.qualitymetrics.misc_metrics.compute_drift_metrics(sorting_analyzer, interval_s=60, min_spikes_per_interval=100, direction='y', min_fraction_valid_intervals=0.5, min_num_bins=2, return_positions=False, unit_ids=None)

Compute drifts metrics using estimated spike locations. Over the duration of the recording, the drift signal for each unit is calculated as the median position in an interval with respect to the overall median positions over the entire duration (reference position).

The following metrics are computed for each unit (in um):

  • drift_ptp: peak-to-peak of the drift signal

  • drift_std: standard deviation of the drift signal

  • drift_mad: median absolute deviation of the drift signal

Requires “spike_locations” extension. If this is not present, metrics are set to NaN.

Parameters
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

interval_sint, default: 60

Interval length is seconds for computing spike depth

min_spikes_per_intervalint, default: 100

Minimum number of spikes for computing depth in an interval

direction“x” | “y” | “z”, default: “y”

The direction along which drift metrics are estimated

min_fraction_valid_intervalsfloat, default: 0.5

The fraction of valid (not NaN) position estimates to estimate drifts. E.g., if 0.5 at least 50% of estimated positions in the intervals need to be valid, otherwise drift metrics are set to None

min_num_binsint, default: 2

Minimum number of bins required to return a valid metric value. In case there are less bins, the metric values are set to NaN.

return_positionsbool, default: False

If True, median positions are returned (for debugging)

unit_idslist or None, default: None

List of unit ids to compute the drift metrics. If None, all units are used

Returns
drift_ptpdict

The drift signal peak-to-peak in um

drift_stddict

The drift signal standard deviation in um

drift_maddict

The drift signal median absolute deviation in um

median_positionsnp.array (optional)

The median positions of each unit over time (only returned if return_positions=True)

Notes

For multi-segment object, segments are concatenated before the computation. This means that if there are large displacements in between segments, the resulting metric values will be very high.

Literature

First introduced in [Siegle] and modified by the SpikeInterface Team.