Spectral data postprocessing (psynal.spectra.postprocess)

Postprocessing functions for LFP/EEG/continuous data and spectral analysis

pool_freq_bands(data, bands, axis=None, freqs=None, func='mean')

Pool (eg average) spectral data within each of a given set of frequency bands

Parameters:
  • data (ndarray or xarray DataArray, shape=(...,n_freqs,...)) – Raw data to pool within frequency bands. Any arbitary shape.

  • bands (array-like, shape=(n_bands,2) or dict {str : array-like, shape=(2,)}) – Frequency bands to pool data within. Input either as a list of [low-cut, high-cut] values or as a dict, with keys being frequency band names and their associated values being the corresponding [low-cut, high-cut] pair. Band edges are inclusive.

  • axis (int) – Data axis corresponding to frequency. Only needed if data is not an xarray DataArray with dimension named ‘freq’/’frequency’.

  • freqs (array-like, shape=(n_freqs,)) – Frequency sampling in data. Only needed if data is not an xarray DataArray.

  • func (str or callable, default: 'mean' (mean across all frequencies in band)) – Function to use to pool values within each frequency band, given either as a string specifier (options: ‘mean’ or ‘sum’) or a custom function that takes as input an ndarray and returns an ndarray with its first axis reduced to length 1.

Returns:

data – Data with values pooled within each of given frequency bands

Return type:

ndarray or xarray DataArray, shape=(…,n_freqbands,…)

pool_time_epochs(data, epochs, axis=None, timepts=None, func='mean')

Pool (eg average) spectral data within each of a given set of time epochs

Parameters:
  • data (ndarray or xarray DataArray, shape=(...,n_timepts,...)) – Raw data to pool within time epochs. Any arbitary shape.

  • epochs (array-like, shape=(n_epochs,2) or dict {str : array-like, shape=(2,)}) – Time epochs to pool data within. Input either as a list of [start,end] times or as a dict, with keys being time epoch names and their associated values being the corresponding [start,end] pair. Epoch edges are inclusive.

  • axis (int) – Data axis corresponding to time. Only needed if data is not an xarray DataArray with dimension named ‘time’.

  • timepts (array-like, shape(n_timepts,)) – Time sampling in data. Only needed if data is not an xarray DataArray with dimension named ‘time’.

  • func (str or callable, default: 'mean' (mean across all frequencies in band)) – Function to use to pool values within each time epoch, given either as a string specifier (options: ‘mean’ or ‘sum’) or a custom function that takes as input an ndarray and returns an ndarray with its first axis reduced to length 1.

Returns:

data – Data with values pooled within each of given time epochs

Return type:

ndarray or xarray DataArray, shape=(…,n_time_epochs,…)

one_over_f_norm(data, axis=None, freqs=None, exponent=1.0)

Normalize to correct for ~ 1/frequency**alpha baseline distribution of power by multiplying by frequency, raised to a given exponent

Parameters:
  • data (ndarray or xarray DataArray, shape=(...,n_freqs,...)) – Raw data to pool within frequency bands. Any arbitary shape.

  • axis (int) – Data axis corresponding to frequency. Needed if data is not an xarray DataArray with dimension named ‘freq’/’frequency’.

  • freqs (array-like, shape=(n_freqs,)) – Frequency sampling in data. Needed if data is not an xarray DataArray.

  • exponent (float, default: 1 (correct for 1/f, w/o exponent)) – Exponent (‘alpha’) to raise freqs to for normalization.

Returns:

data – 1/f normalized data. Same shape as input.

Return type:

ndarray or xarray DataArray, shape=(…,n_freqs,…)