mne.preprocessing.GradientRemover#

class mne.preprocessing.GradientRemover(eeg_data, tr_events, window=(4, 4), tr_tol=0)[source]#

Remove the fMRI gradient artifact from EEG data using average templates.

Implements the average artifact subtraction (AAS) method of [1]: for each imaging volume (TR) epoch the data are detrended, an artifact template is formed by averaging neighboring TR epochs, and the template is subtracted from the epoch.

This class operates on a plain ndarray and exposes the intermediate templates and per-TR access, which makes it suitable both for offline correction and as a building block for real-time correction. Most users should prefer mne.preprocessing.remove_fmri_gradient_artifact(), which operates directly on a Raw object.

Parameters:
eeg_datandarray, shape (n_channels, n_times)

The raw EEG data to perform gradient correction on.

tr_eventsndarray

The sample numbers at which TRs (imaging volumes) begin. May be a 1D array of sample numbers, shape (n_trs,), or an (n_trs, 3) events array as returned by mne.find_events() (the first column is used). TRs must be evenly spaced in time, within tr_tol samples (see below).

windowint | tuple of int

The number of neighboring TRs to average into each template. Either an even integer giving the total number of TRs (split evenly before and after), or a (n_before, n_after) tuple. For example, (4, 0) averages the 4 preceding TRs only. Default (4, 4).

tr_tolint

The maximum allowed deviation (in samples) of any individual TR spacing from the median TR spacing. Real-world trigger timestamps (e.g. as reconstructed from wall-clock event times) are often off by a sample or two even when the true TR spacing is fixed; this tolerance allows such jitter without rejecting the data. Each TR epoch is anchored at its own detected onset sample, so small deviations do not accumulate across TRs. Default 0.

Attributes:
corrected

The gradient-corrected data (computed on first access).

n_channels

The number of channels.

n_tr

The number of TRs (imaging volumes).

tr_spacing

The (median) number of samples between consecutive TRs.

window

The template window as a (n_before, n_after) tuple.

Methods

correct()

Generate the gradient-corrected data.

get_tr(n)

Get the uncorrected data at a given TR.

get_tr_corrected(n)

Get the gradient-corrected data at a given TR.

get_tr_detrended(n)

Get the detrended data at a given TR.

get_tr_template(n)

Get the gradient artifact template at a given TR.

References

correct()[source]#

Generate the gradient-corrected data.

Returns:
correctedndarray, shape (n_channels, n_times)

The gradient-corrected data.

property corrected#

The gradient-corrected data (computed on first access).

get_tr(n)[source]#

Get the uncorrected data at a given TR.

Parameters:
nint

The TR to get the uncorrected data at (0-indexed).

Returns:
datandarray, shape (n_channels, tr_spacing)

The uncorrected data at the given TR.

get_tr_corrected(n)[source]#

Get the gradient-corrected data at a given TR.

Parameters:
nint

The TR to get the corrected data at (0-indexed).

Returns:
datandarray, shape (n_channels, tr_spacing)

The gradient-corrected data at the given TR.

get_tr_detrended(n)[source]#

Get the detrended data at a given TR.

Parameters:
nint

The TR to get the detrended data at (0-indexed).

Returns:
datandarray, shape (n_channels, tr_spacing)

The detrended data at the given TR.

get_tr_template(n)[source]#

Get the gradient artifact template at a given TR.

Parameters:
nint

The TR to get the template at (0-indexed).

Returns:
templatendarray, shape (n_channels, tr_spacing)

The artifact template at the given TR.

property n_channels#

The number of channels.

property n_tr#

The number of TRs (imaging volumes).

property tr_spacing#

The (median) number of samples between consecutive TRs.

property window#

The template window as a (n_before, n_after) tuple.