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
ndarrayand 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 prefermne.preprocessing.remove_fmri_gradient_artifact(), which operates directly on aRawobject.- Parameters:
- eeg_data
ndarray, shape (n_channels, n_times) The raw EEG data to perform gradient correction on.
- tr_events
ndarray 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 bymne.find_events()(the first column is used). TRs must be evenly spaced in time, withintr_tolsamples (see below).- window
int|tupleofint 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_tol
int 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.
- eeg_data
- Attributes:
correctedThe gradient-corrected data (computed on first access).
n_channelsThe number of channels.
n_trThe number of TRs (imaging volumes).
tr_spacingThe (median) number of samples between consecutive TRs.
windowThe 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 the gradient-corrected data at a given TR.
Get the detrended data at a given TR.
Get the gradient artifact template at a given TR.
References
- correct()[source]#
Generate the gradient-corrected data.
- Returns:
- corrected
ndarray, shape (n_channels, n_times) The gradient-corrected data.
- corrected
- property corrected#
The gradient-corrected data (computed on first access).
- get_tr(n)[source]#
Get the uncorrected data at a given TR.
- Parameters:
- n
int The TR to get the uncorrected data at (0-indexed).
- n
- Returns:
- data
ndarray, shape (n_channels,tr_spacing) The uncorrected data at the given TR.
- data
- get_tr_corrected(n)[source]#
Get the gradient-corrected data at a given TR.
- Parameters:
- n
int The TR to get the corrected data at (0-indexed).
- n
- Returns:
- data
ndarray, shape (n_channels,tr_spacing) The gradient-corrected data at the given TR.
- data
- get_tr_detrended(n)[source]#
Get the detrended data at a given TR.
- Parameters:
- n
int The TR to get the detrended data at (0-indexed).
- n
- Returns:
- data
ndarray, shape (n_channels,tr_spacing) The detrended data at the given TR.
- data
- get_tr_template(n)[source]#
Get the gradient artifact template at a given TR.
- Parameters:
- n
int The TR to get the template at (0-indexed).
- n
- Returns:
- template
ndarray, shape (n_channels,tr_spacing) The artifact template at the given TR.
- template
- 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.