autoreject.AutoReject#

class autoreject.AutoReject(n_interpolate=None, consensus=None, thresh_func=None, cv=10, picks=None, thresh_method='bayesian_optimization', n_jobs=1, random_state=None, verbose=True)[source]#

Bases: object

Efficiently find n_interpolate and consensus.

Note

AutoReject by design supports multiple channels. If no picks are passed, separate solutions will be computed for each channel type and internally combined. This then readily supports cleaning unseen epochs from the different channel types used during fit.

Parameters:
n_interpolatearray | None

The values to try for the number of channels for which to interpolate. This is \(\\rho\). If None, defaults to np.array([1, 4, 32])

consensusarray | None

The values to try for percentage of channels that must agree as a fraction of the total number of channels. This sets \(\\kappa/Q\). If None, defaults to np.linspace(0, 1.0, 11)

cvint | sklearn.model_selection object

Defaults to cv=10.

picksstr | list | slice | None

Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g., ['meg', 'eeg']) will pick channels of those types, channel name strings (e.g., ['MEG0111', 'MEG2623'] will pick the given channels. Can also be the string values 'all' to pick all channels, or 'data' to pick data channels. None (default) will pick data channels {‘meg’, ‘eeg’}, which will lead fitting and combining autoreject solutions across these channel types. Note that channels in info['bads'] will be included if their names or indices are explicitly provided.

thresh_methodstr

‘bayesian_optimization’ or ‘random_search’

n_jobsint

The number of jobs.

random_stateint | np.random.RandomState | None

The seed of the pseudo random number generator to use. Defaults to None.

verbosebool

The verbosity of progress messages. If False, suppress all output messages.

Attributes:
local_reject_list

The instances of _AutoReject for each channel type.

threshes_dict

The sensor-level thresholds with channel names as keys and the peak-to-peak thresholds as the values.

loss_dict of array, shape (len(n_interpolate), len(consensus))

The cross validation error for different parameter values.

consensus_dict

The estimated consensus per channel type.

n_interpolate_dict

The estimated n_interpolate per channel type.

picks_array_like, shape (n_data_channels,)

The data channels considered by autoreject. By default only data channels, not already marked as bads are considered.

fit(epochs)[source]#

Fit the epochs on the AutoReject object.

Parameters:
epochsinstance of mne.Epochs

The epochs object to be fit.

Returns:
selfinstance of AutoReject

The instance.

fit_transform(epochs, return_log=False)[source]#

Estimate the rejection params and finds bad epochs.

Parameters:
epochsinstance of mne.Epochs

The epochs object which must be cleaned.

return_logbool

If true the rejection log is also returned.

Returns:
epochs_cleaninstance of mne.Epochs

The cleaned epochs.

reject_loginstance of autoreject.RejectLog

The rejection log. Returned only of return_log is True.

get_reject_log(epochs, picks=None)[source]#

Get rejection logs of epochs.

Note

If multiple channel types are present, reject_log[‘bad_epochs_idx’] reflects the union of bad trials across channel types.

Parameters:
epochsinstance of mne.Epochs

The epoched data for which the reject log is computed.

picksstr | list | slice | None

Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g., ['meg', 'eeg']) will pick channels of those types, channel name strings (e.g., ['MEG0111', 'MEG2623'] will pick the given channels. Can also be the string values 'all' to pick all channels, or 'data' to pick data channels. None (default) will use the .picks attribute. Note that channels in info['bads'] will be included if their names or indices are explicitly provided.

Returns:
reject_loginstance of autoreject.RejectLog

The reject log.

save(fname, overwrite=False)[source]#

Save autoreject object with the HDF5 format.

Parameters:
fnamestr

The filename to save to. The filename must end in ‘.h5’ or ‘.hdf5’.

overwritebool

If True, overwrite file if it already exists. Defaults to False.

transform(epochs, return_log=False, reject_log=None)[source]#

Remove bad epochs, repairs sensors and returns clean epochs.

Parameters:
epochsinstance of mne.Epochs

The epochs object which must be cleaned.

return_logbool

If true the rejection log is also returned.

reject_loginstance of autoreject.RejectLog | None

The reject log to use. If None, the default reject log is used.

Returns:
epochs_cleaninstance of mne.Epochs

The cleaned epochs

reject_loginstance of autoreject.RejectLog

The rejection log. Returned only if return_log is True.

Examples using autoreject.AutoReject#

Preprocessing workflow with autoreject and ICA

Preprocessing workflow with autoreject and ICA

Visualize bad sensors per trial

Visualize bad sensors per trial