elephant.spike_train_generation.spike_extraction

elephant.spike_train_generation.spike_extraction(signal: AnalogSignal, threshold: Quantity = array(0.) * mV, sign: Literal['above', 'below'] = 'above', time_stamps: SpikeTrain = None, interval: tuple = (array(-2.) * ms, array(4.) * ms), always_as_list: bool = False) SpikeTrain | SpikeTrainList[source]

Return the peak times for all events that cross threshold and the waveforms. Usually used for extracting spikes from a membrane potential to calculate waveform properties.

Parameters:
signalneo.core.AnalogSignal

An analog input signal one or more channels.

thresholdpq.Quantity, optional

Contains a value that must be reached for an event to be detected. Default: 0.0 * pq.mV

sign{‘above’, ‘below’}, optional

Determines whether to count threshold crossings that cross above or below the threshold. Default: ‘above’

time_stampsneo.core.SpikeTrain , optional

Provides the time stamps around which the waveform is extracted. If it is None, the function peak_detection is used to calculate the time_stamps from signal. Default: None

intervaltuple of pq.Quantity

Specifies the time interval around the time_stamps where the waveform is extracted. The default time interval [-2ms, 4ms] are based on experience, and many spike sorting tools choose values in this range as the spikes are typically about 1-2 ms in length. This choice of default values includes a small interval before the spike peak and a slightly larger interval after the spike peak to capture the dynamics following the spike. Adjusting this interval will modify the waveforms stored in the neo neo.core.SpikeTrain, but it will not affect the spike times. Default: (-2 * pq.ms, 4 * pq.ms)

always_as_list: bool, optional

If True, neo.core.spiketrainslist.SpikeTrainList is returned. Default: False

Returns:
result_stneo.core.SpikeTrain, neo.core.spiketrainslist.SpikeTrainList.

Contains the time_stamps of each of the spikes and the waveforms in result_st.waveforms.

Notes

If time_stamps is set to None, peaks are extracted using NumPy’s peak finder. Therefore, the spike times will not be affected by the interval parameter. However, the dimensions of the array containing the waveforms, which is stored in the Neo neo.core.SpikeTrain object in result_st.waveforms, will differ depending on the interval parameter. The extracted waveforms are stored as an NxM matrix for the N spikes, each row containing a waveform. For example, if the sampling frequency is 10KHz, and 123 spikes were detected, then result_st.waveforms should be size 123x200 for an interval of [-10ms, 10ms].