neurotools.spikes.ppc module

Pairwise-phase-consistency spike-LFP coupling statistics and related functions.

neurotools.spikes.ppc.phase_randomize(signal)[source]

Phase randomizes a signal by rotating frequency components by a random angle. Negative frequencies are rotated in the opposite direction. The nyquist frequency, if present, has it’s sign randomly flipped.

Parameters:

signal (1D array)

Return type:

phase-randomized sigal

neurotools.spikes.ppc.fftppc_biased(snippits, Fs=1000, taper=None)[source]

FFT-based pairwise phase consistency without corrections for finite-sample-size bias.

Parameters:
  • snippits – List of LFP signals extracted in the vicinity of each spike.

  • Fs (positive int; default 1000) – Sample rate

  • taper (np.attay) – Windowing function to apply before taking the FFT

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated

  • raw (np.array) – Raw (biased) value for the PPC at each frequency

  • phases (np.array) – Phase values associated with each ppc coefficient

neurotools.spikes.ppc.fftppc(snippits, Fs=1000, taper=None)[source]

FFT-based pairwise phase consistency with corrections for finite-sample-size bias.

Parameters:
  • snippits – List of LFP signals extracted in the vicinity of each spike.

  • Fs (positive int; default 1000) – Sample rate

  • taper (np.attay) – Windowing function to apply before taking the FFT

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated

  • raw (np.array) – Raw (biased) value for the PPC at each frequency

  • phases (np.array) – Phase values associated with each ppc coefficient

neurotools.spikes.ppc.fftppc_biased_multitaper(snippits, Fs=1000, k=4, transpose_warning=True)[source]

FFT-based pairwise phase consistency without corrections for finite-sample-size bias, using a multi-taper method with k tapers to reduce variance at the expense of bandwidth resolution.

Parameters:
  • snippits (Nspikes x Nwindow) – Array of spike-triggered samples of the signal trace

  • Fs (scalar) – Sampling frequency. Defaults to 1000 Hz

  • k (positive integer) – Number of tapers. Defaults to 4.

  • transpose_warning (boolean; default True) – Warn if any of the input arrays appear transposed.

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated

  • raw (np.array) – Raw (biased) value for the PPC at each frequency

  • phases (np.array) – Phase values associated with each ppc coefficient

neurotools.spikes.ppc.fftppc_multitaper(snippits, Fs=1000, k=4, transpose_warning=True)[source]

FFT-based pairwise phase consistency with corrections for finite-sample-size bias, using a multi-taper method with k tapers to reduce variance at the expense of bandwidth resolution.

Parameters:
  • snippits (Nspikes x Nwindow) – Array of spike-triggered samples of the signal trace

  • Fs (scalar) – Sampling frequency. Defaults to 1000 Hz

  • k (positive integer) – Number of tapers. Defaults to 4.

  • transpose_warning (boolean; default True) – Warn if any of the input arrays appear transposed.

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated

  • raw (np.array) – Raw (biased) value for the PPC at each frequency

  • phases (np.array) – Phase values associated with each ppc coefficient

neurotools.spikes.ppc.discard_spikes_closer_than_delta(signal, times, delta)[source]

When computing PPC, we need to throw out spikes that are too close together. This is a heuristic to make the spiking samples “more independent”. We also need to skip spikes that are so close to the edge of our data that we can’t get the LFP window surrounding the spike time. Because certain tests that compare across conditions require matching the number of spikes, to ensure that the variance of the PPC estimator is comparable between the conditions, we expose the code for selecting the subset of spikes for PPC here, so that it can be used to ensure that both conditions have a matching number of spikes

Parameters:
  • signal

  • times

  • delta

neurotools.spikes.ppc.pairwise_phase_consistancy(signal, times, window=50, Fs=1000, k=4, multitaper=True, biased=False, delta=100, taper=None)[source]
Parameters:
  • signal – 1D real valued signal

  • times – Times of events relative to signal

  • window (positive int; default 50) – Time around event to examine

  • Fs (positive int; default 1000) – sample rate for computing freqs

  • k (positive int; default 4) – number of tapers Also accepts lists of signals / times returns (freqs, ppc, phase), lfp_segments

  • multitaper (boolean; default True)

  • biased (booleanl default False)

  • delta (positive int; default 100)

  • taper (array; default None)

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated

  • raw (np.array) – Raw (biased) value for the PPC at each frequency

  • phases (np.array) – Phase values associated with each ppc coefficient

neurotools.spikes.ppc.estimate_bias_in_uncorrected_ppc(signal, times, window=50, Fs=1000, nrand=100)[source]
Parameters:
  • signal

  • times

  • window (positive int; deafult 50)

  • Fs (positive int; default 1000)

  • nrand (positive int; default 100)

Returns:

  • ff

  • bias

neurotools.spikes.ppc.phase_randomized_bias_correction(signal, times, window=50, Fs=1000, nrand=100)[source]

Estimates degrees of freedom using phase randomization. experimental.

Parameters:
  • signal

  • times

  • window (positive int; deafult 50)

  • Fs (positive int; default 1000)

  • nrand (positive int; default 100)

Returns:

  • ff

  • unbiased

neurotools.spikes.ppc.ppc_chance_level(nSamples, nrandom, p, nTapers=1)[source]

Caution: This underestimates chance level if spikes or the LFP signal are correlated in time.

Parameters:
  • nSamples

  • nrandom

  • p

  • nTapers (positive int; default 1)

Return type:

samples

neurotools.spikes.ppc.ppc_phase_randomize_chance_level_sample(signal, times, window=50, Fs=1000, k=4, multitaper=True, biased=False, delta=100, taper=None)[source]

Uses phase randomization to sample from the null hypothesis distribution. Returns the actual PPC samples rather than any summary statistics. You can do what you want with the distribution returned.

Parameters:
  • signal – 1D real valued signal

  • times – Times of events relative to signal

  • window (positive int; default 50) – Time around event to examine

  • window – Time around event to examine

  • Fs (positive int; default 1000) – sample rate for computing freqs

  • k (positive int; default 4) – number of tapers Also accepts lists of signals / times returns (freqs, ppc, phase), lfp_segments

  • multitaper (boolean; default True)

  • biased (booleanl default False)

  • delta (positive int; default 100)

  • taper (array; default None)

Returns:

  • freqs (npp.array) – Frequencies at which the PPC has been evaluated (phase-randomized samples)

  • raw (np.array) – Raw (biased) value for the PPC at each frequency (phase-randomized samples)

  • phases (np.array) – Phase values associated with each ppc coefficient (phase-randomized samples)