mne.cov.prepare_noise_cov

mne.cov.prepare_noise_cov(noise_cov, info, ch_names=None, rank=None, scalings=None, on_rank_mismatch='ignore', verbose=None)[source]

Prepare noise covariance matrix.

Parameters
noise_covinstance of Covariance

The noise covariance to process.

infomne.Info

The mne.Info object with information about the sensors and methods of measurement. (Used to get channel types and bad channels).

ch_nameslist | None

The channel names to be considered. Can be None to use info['ch_names'].

rankNone | ‘info’ | ‘full’ | dict

This controls the rank computation that can be read from the measurement info or estimated from the data. When a noise covariance is used for whitening, this should reflect the rank of that covariance, otherwise amplification of noise components can occur in whitening (e.g., often during source localization).

None

The rank will be estimated from the data after proper scaling of different channel types.

'info'

The rank is inferred from info. If data have been processed with Maxwell filtering, the Maxwell filtering header is used. Otherwise, the channel counts themselves are used. In both cases, the number of projectors is subtracted from the (effective) number of channels in the data. For example, if Maxwell filtering reduces the rank to 68, with two projectors the returned value will be 66.

'full'

The rank is assumed to be full, i.e. equal to the number of good channels. If a Covariance is passed, this can make sense if it has been (possibly improperly) regularized without taking into account the true data rank.

dict

Calculate the rank only for a subset of channel types, and explicitly specify the rank for the remaining channel types. This can be extremely useful if you already know the rank of (part of) your data, for instance in case you have calculated it earlier.

This parameter must be a dictionary whose keys correspond to channel types in the data (e.g. 'meg', 'mag', 'grad', 'eeg'), and whose values are integers representing the respective ranks. For example, {'mag': 90, 'eeg': 45} will assume a rank of 90 and 45 for magnetometer data and EEG data, respectively.

The ranks for all channel types present in the data, but not specified in the dictionary will be estimated empirically. That is, if you passed a dataset containing magnetometer, gradiometer, and EEG data together with the dictionary from the previous example, only the gradiometer rank would be determined, while the specified magnetometer and EEG ranks would be taken for granted.

The default is None.

New in version 0.18: Support for ‘info’ mode.

scalingsdict | None

Data will be rescaled before rank estimation to improve accuracy. If dict, it will override the following dict (default if None):

dict(mag=1e12, grad=1e11, eeg=1e5)
on_rank_mismatchstr

If an explicit MEG value is passed, what to do when it does not match an empirically computed rank (only used for covariances). Can be ‘raise’ to raise an error, ‘warn’ (default) to emit a warning, or ‘ignore’ to ignore.

New in version 0.23.

verbosebool | str | int | None

Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

Returns
covinstance of Covariance

A copy of the covariance with the good channels subselected and parameters updated.