ssvepy.Ssvep

class ssvepy.Ssvep(epochs, stimulation_frequency, noisebandwidth=1.0, compute_harmonics=range(2, 5), compute_subharmonics=range(2, 5), compute_intermodulation=range(2, 5), psd=None, freqs=None, fmin=0.1, fmax=50, tmin=None, tmax=None, compute_tfr=False, tfr_method=’rls’, tfr_time_window=0.9)[source]

Turns epoched EEG/MEG data into epoched evoked frequency data.

This is the main class in ssvepy.

Parameters:
  • epochs (mne.Epochs) – An instance of Epoch data.
  • stimulation_frequency (int, float, or list) – The frequencies at which the stimulation oscillated.
  • noisebandwidth (float) – The width of the noise band used to calculate the signal-to-noise ratio.
  • compute_harmonics (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • compute_subharmonics (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • compute_intermodulation (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • psd (numpy.ndarray) – If you have already computed the power spectrum with some other method, pass it as a parameter.
  • freqs (numpy.ndarray) – If you provide a power spectrum, this has to be the frequencies over which it was evaluated.
  • fmax (fmin,) – Bounds of frequency band to be evaluated
  • tmax (tmin,) – The time points between which power will be evaluated
  • compute_tfr (bool) – If you want to evaluate the time-frequency decomposition (this applies to the stimulation and non-linear combination frequencies only.)
  • tfr_method (str) – Currently, only one method is implemented (‘rls’)
  • tfr_time_window (float) – The window width for the TFR method.

Attributes

stimulation

obj – a data structure with the following attributes: stimulation.frequencies, stimulation.power, stimulation.snr

harmonics, subharmonics, intermodulations

obj – non-linear combination of your input stimulus frequencies, all with the attributes: _.frequencies, _.power, _.snr, _.order

psd

numpy.ndarray – the power spectrum

freqs

numpy.ndarray – the frequencies at which the psd was evaluated

snr

numpy.ndarray – the signal-to-noise ratio for each frequency in freqs


Methods

These are the methods that are added by ssvepy. All methods, including the inherited ones, are at the end of the page.

plot_psd([collapse_epochs, collapse_electrodes]) Plot the power-spectrum that has been calculated for this data.
plot_snr([collapse_epochs, collapse_electrodes]) Plot the signal-to-noise-ratio-spectrum that has been calculated for this data.
plot_tfr([frequency, collapse_epochs, …]) Plot the time-course of one of the evoked frequencies.
predict_epochs(labels[, trainepochs, …]) This method is for predicting the labels of trials based on the SSVEP power in a trial.
predict_timepoints(labels[, trainingtrials, …]) This method is for predicting the labels of trials based on the SSVEP power in a trial.
save(filename) Save the data to file.
topoplot_psd([collapse_epochs, flims]) Plot the signal-to-noise-ratio-spectrum across the scalp.
topoplot_snr([collapse_epochs, flims]) Plot the signal-to-noise-ratio-spectrum across the scalp.

Methods Details

class ssvepy.Ssvep(epochs, stimulation_frequency, noisebandwidth=1.0, compute_harmonics=range(2, 5), compute_subharmonics=range(2, 5), compute_intermodulation=range(2, 5), psd=None, freqs=None, fmin=0.1, fmax=50, tmin=None, tmax=None, compute_tfr=False, tfr_method=’rls’, tfr_time_window=0.9)[source]

Turns epoched EEG/MEG data into epoched evoked frequency data.

This is the main class in ssvepy.

Parameters:
  • epochs (mne.Epochs) – An instance of Epoch data.
  • stimulation_frequency (int, float, or list) – The frequencies at which the stimulation oscillated.
  • noisebandwidth (float) – The width of the noise band used to calculate the signal-to-noise ratio.
  • compute_harmonics (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • compute_subharmonics (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • compute_intermodulation (list | numpy.ndarray) – Integers of which order of harmonics to compute. Can be None.
  • psd (numpy.ndarray) – If you have already computed the power spectrum with some other method, pass it as a parameter.
  • freqs (numpy.ndarray) – If you provide a power spectrum, this has to be the frequencies over which it was evaluated.
  • fmax (fmin,) – Bounds of frequency band to be evaluated
  • tmax (tmin,) – The time points between which power will be evaluated
  • compute_tfr (bool) – If you want to evaluate the time-frequency decomposition (this applies to the stimulation and non-linear combination frequencies only.)
  • tfr_method (str) – Currently, only one method is implemented (‘rls’)
  • tfr_time_window (float) – The window width for the TFR method.

Attributes

stimulation

obj – a data structure with the following attributes: stimulation.frequencies, stimulation.power, stimulation.snr

harmonics, subharmonics, intermodulations

obj – non-linear combination of your input stimulus frequencies, all with the attributes: _.frequencies, _.power, _.snr, _.order

psd

numpy.ndarray – the power spectrum

freqs

numpy.ndarray – the frequencies at which the psd was evaluated

snr

numpy.ndarray – the signal-to-noise ratio for each frequency in freqs

plot_psd(collapse_epochs=True, collapse_electrodes=False, **kwargs)[source]

Plot the power-spectrum that has been calculated for this data.

Parameters:
  • collapse_epochs (bool) – Whether you want to plot the average of all epochs (default), or each power-spectrum individually.
  • collapse_electrodes (bool) – Whether you want to plot each electrode individually (default), or only the average of all electrodes.
plot_snr(collapse_epochs=True, collapse_electrodes=False, **kwargs)[source]

Plot the signal-to-noise-ratio-spectrum that has been calculated for this data.

Parameters:
  • collapse_epochs – bool Whether you want to plot the average of all epochs (default), or each power-spectrum individually.
  • collapse_electrodes – bool Whether you want to plot each electrode individually (default), or only the average of all electrodes.
plot_tfr(frequency=’stimulation’, collapse_epochs=True, collapse_electrodes=False, figsize=(7, 5))[source]

Plot the time-course of one of the evoked frequencies.

Parameters:
  • frequency (str) – Which evoked frequency to plot. Either ‘stimulation’, ‘harmonic’, ‘subharmonic’ or ‘intermodulation’
  • collapse_epochs (bool) – Whether to average over the epochs or not.
  • collapse_electrodes (bool) – Whether to average over electrodes or not.
  • figsize (tup) – Matplotlib figure size.
predict_epochs(labels, trainepochs=None, method=LogisticRegressionCV(Cs=10, class_weight=None, cv=None, dual=False, fit_intercept=True, intercept_scaling=1.0, max_iter=100, multi_class=’ovr’, n_jobs=1, penalty=’l2’, random_state=None, refit=True, scoring=None, solver=’lbfgs’, tol=0.0001, verbose=0))[source]

This method is for predicting the labels of trials based on the SSVEP power in a trial.

Parameters:
  • labels (numpy.ndarray) – Labels for each trial; needs to be the same length as there are epochs.
  • trainepochs (list) – A list of trial indices that will be used to train - e.g. range(6) - or an ndarray of booleans of the same size as label. The trials in this index will be used as training trials, and the returned accuracy is based on the trials not used for training.
  • method (sklearn.class) – A training class that conforms to the standard sklearn model (ie has the methods fit(), predict() etc.)
predict_timepoints(labels, trainingtrials=None, datatransform=None, method=LogisticRegressionCV(Cs=10, class_weight=None, cv=None, dual=False, fit_intercept=True, intercept_scaling=1.0, max_iter=100, multi_class=’ovr’, n_jobs=1, penalty=’l2’, random_state=None, refit=True, scoring=None, solver=’lbfgs’, tol=0.0001, verbose=0))[source]

This method is for predicting the labels of trials based on the SSVEP power in a trial.

Parameters:
  • labels (numpy.ndarray) – Labels for each timepoint; the dimensions should match (trial x timepoint)
  • trainepochs (list) – A list of trial indices that will be used to train - e.g. range(6) - or an ndarray of booleans of the same size as label. The trials in this index will be used as training trials, and the returned accuracy is based on the trials not used for training.
  • datatransform (str) – What transform to do to the TFR data - at the moment, ‘z-score’ works.
  • method (sklearn.class) – A training class that conforms to the standard sklearn model (ie has the methods fit(), predict() etc.)
save(filename)[source]

Save the data to file.

Parameters:filename (str) – The name of the file, either bare, or with the file extension .hdf5
topoplot_psd(collapse_epochs=True, flims=’stimulation’, **kwargs)[source]

Plot the signal-to-noise-ratio-spectrum across the scalp.

Parameters:
  • collapse_epochs – bool Whether you want to plot the average of all epochs (default), or each power-spectrum individually.
  • flims – list | str Which frequency bands you want to plot. By default, the stimulation frequencies will be plotted. Can be limits (eg. [6, 8]) or a string referring to an evoked frequency (eg. ‘stimulation’, ‘harmonic’)
topoplot_snr(collapse_epochs=True, flims=’stimulation’, **kwargs)[source]

Plot the signal-to-noise-ratio-spectrum across the scalp.

Parameters:
  • collapse_epochs – bool Whether you want to plot the average of all epochs (default), or each power-spectrum individually.
  • flims – list | str Which frequency bands you want to plot. By default, the stimulation frequencies will be plotted. Can be limits (eg. [6, 8]) or a string referring to an evoked frequency (eg. ‘stimulation’, ‘harmonic’)