Skip to content

Waveform analysis

ephysiopy.common.waveformcalcs.WaveformCalcsGeneric(waveforms: np.ndarray, spike_times: np.ndarray, cluster: int, **kwargs)

Bases: object

Deals with the processing and analysis of spike data. There should be one instance of this class per cluster in the recording session. NB this differs from previous versions of this class where there was one instance per recording session and clusters were selected by passing in the cluster id to the methods.

NB Axona waveforms are nSpikes x nChannels x nSamples - this boils down to nSpikes x 4 x 50 NB KiloSort waveforms are nSpikes x nSamples x nChannels - these are ordered by 'best' channel first and then the rest of the channels. This boils down to nSpikes x 61 x 12 SO THIS NEEDS TO BE CHANGED to nSpikes x nChannels x nSamples

Parameters:

Name Type Description Default
spike_times ndarray

The times of spikes in the trial in seconds.

required
cluster int

The cluster ID.

required
waveforms ndarray

An nSpikes x nChannels x nSamples array.

required
**kwargs dict

Additional keyword arguments.

{}

Attributes:

Name Type Description
spike_times MaskedArray

The times of spikes in the trial in seconds.

_waves MaskedArray or None

The waveforms of the spikes.

cluster int

The cluster ID.

n_spikes int

the total number of spikes for the current cluster

duration (float, int)

total duration of the trial in seconds

event_ts ndarray or None

The times that events occurred in seconds.

event_window ndarray

The window, in seconds, either side of the stimulus, to examine.

stim_width float or None

The width, in ms, of the stimulus.

secs_per_bin float

The size of bins in PSTH.

sample_rate int

The sample rate of the recording.

pos_sample_rate int

The sample rate of the position data.

pre_spike_samples int

The number of samples before the spike.

post_spike_samples int

The number of samples after the spike.

KSMeta KSMetaTuple

The metadata from KiloSort.

Methods:

Name Description
apply_filter

Applies a mask to the spike times.

estimate_AHP

Estimate the decay time for the AHP of the waveform of the

get_best_channel

Returns the channel with the highest mean amplitude of the waveforms.

mean_waveform

Returns the mean waveform and standard error of the mean (SEM) for a

plot_waveforms

Plots the waveforms of the cluster.

update_KSMeta

Takes in a TemplateModel instance from a phy session and

waveforms

Returns the waveforms of the cluster.

n_channels: int | None property

Returns the number of channels in the waveforms.

Returns:

Type Description
int | None

The number of channels in the waveforms, or None if no waveforms are available.

n_samples: int | None property

Returns the number of samples in the waveforms.

Returns:

Type Description
int | None

The number of samples in the waveforms, or None if no waveforms are available.

n_spikes property

Returns the number of spikes in the cluster

Returns:

Type Description
int

The number of spikes in the cluster

apply_filter(*trial_filter: TrialFilter) -> None

Applies a mask to the spike times.

Parameters:

Name Type Description Default
trial_filter TrialFilter

The filter

()

estimate_AHP() -> float | None

Estimate the decay time for the AHP of the waveform of the best channel for the current cluster.

Returns:

Type Description
float | None

The estimated AHP decay time in microseconds, or None if no waveforms are available.

get_best_channel() -> int | None

Returns the channel with the highest mean amplitude of the waveforms.

Returns:

Type Description
int | None

The index of the channel with the highest mean amplitude, or None if no waveforms are available.

mean_waveform(channel_id: Sequence = None)

Returns the mean waveform and standard error of the mean (SEM) for a given spike train on a particular channel.

Parameters:

Name Type Description Default
channel_id Sequence

The channel IDs to return the mean waveform for. If None, returns mean waveforms for all channels.

None

Returns:

Type Description
tuple

A tuple containing: - mn_wvs (np.ndarray): The mean waveforms, usually 4x50 for tetrode recordings. - std_wvs (np.ndarray): The standard deviations of the waveforms, usually 4x50 for tetrode recordings.

plot_waveforms(n_waveforms: int = 2000, n_channels: int = 4)

Plots the waveforms of the cluster.

Parameters:

Name Type Description Default
n_waveforms int

The number of waveforms to plot.

2000
n_channels int

The number of channels to plot.

4

Returns:

Type Description
None

update_KSMeta(value: dict) -> None

Takes in a TemplateModel instance from a phy session and parses out the relevant metrics for the cluster and places into the namedtuple KSMeta.

Parameters:

Name Type Description Default
value dict

A dictionary containing the relevant metrics for the cluster.

required

waveforms(channel_id: Sequence | None = None) -> np.ndarray | None

Returns the waveforms of the cluster.

Parameters:

Name Type Description Default
channel_id Sequence

The channel IDs to return the waveforms for. If None, returns waveforms for all channels.

None

Returns:

Type Description
ndarray | None

The waveforms of the cluster, or None if no waveforms are available.

ephysiopy.common.waveformcalcs.peak_to_trough_time(ap: np.ndarray, fs: int, search_window_ms: float = 2.0) -> dict

Calculate the peak-to-trough time of a single action potential waveform, accounting for possibly inverted waveforms.

Parameters:

Name Type Description Default
ap ndarray

1-D array containing one action potential waveform (voltage, µV or mV).

required
fs int

Sampling frequency in Hz (e.g. 50_000 or 30_000).

required
search_window_ms float

How many milliseconds after the peak to search for the trough. Default is 2.0 ms (covers typical neuronal APs).

2.0

Returns:

Type Description
dict with keys:

peak_idx – sample index of the peak (or trough if inverted) trough_idx – sample index of the trough (or peak if inverted) peak_to_trough_samples – difference in samples peak_to_trough_ms – difference in milliseconds peak_value – voltage at the peak (or trough if inverted) trough_value – voltage at the trough (or peak if inverted) inverted – True if waveform is inverted

ephysiopy.common.waveformcalcs.get_param(waveforms, param='Amp', t=200, fet=1, **kws) -> np.ndarray

Returns the requested parameter from a spike train as a numpy array.

Parameters:

Name Type Description Default
waveforms ndarray

Array shape can be nSpikes x nSamples OR nSpikes x nElectrodes x nSamples.

required
param str

Valid values are: - 'Amp': peak-to-trough amplitude - 'P': height of peak - 'T': depth of trough - 'Vt': height at time t - 'tP': time of peak (in seconds) - 'tT': time of trough (in seconds) - 'PCA': first n fet principal components (defaults to 1)

'Amp'
t int

The time used for Vt

200
fet int

The number of principal components (use with param 'PCA').

1
**kws dict

Additional keyword arguments.

{}

Returns:

Type Description
ndarray

The requested parameter as a numpy array.