pyprep.Reference#
- class pyprep.Reference(raw, params, ransac=True, channel_wise=False, max_chunk_size=None, random_state=None, reject_by_annotation=None, matlab_strict=False)[source]#
Bases:
objectEstimate the ‘true’ reference with all the bad channels interpolated.
This class implements the functionality of the performReference function as part of the PREP (preprocessing pipeline) for EEG data described in [1].
- Parameters:
- raw
mne.io.Raw The raw data.
- params
dict Parameters of PREP which include at least the following keys: -
ref_chs-reref_chs- ransacbool
Whether or not to use RANSAC for noisy channel detection in addition to the other methods in
NoisyChannels. RANSAC can detect bad channels that other methods are unable to catch, but also slows down noisy channel detection considerably. Defaults toTrue.- channel_wisebool
Whether RANSAC should predict signals for chunks of channels over the entire signal length (“channel-wise RANSAC”, see max_chunk_size parameter). If
False, RANSAC will instead predict signals for all channels at once but over a number of smaller time windows instead of over the entire signal length (“window-wise RANSAC”). Channel-wise RANSAC generally has higher RAM demands than window-wise RANSAC (especially if max_chunk_size isNone), but can be faster on systems with lots of RAM to spare. Has no effect if not using RANSAC. Defaults toFalse.- max_chunk_size{
int,None} |None The maximum number of channels to predict at once during channel-wise RANSAC. If
None, RANSAC will use the largest chunk size that will fit into the available RAM, which may slow down other programs on the host system. If using window-wise RANSAC (the default) or not using RANSAC at all, this parameter has no effect. Defaults toNone.- random_state{
int,None,np.random.RandomState} |None The random seed at which to initialize the class. This can be
None, an integer, or aRandomStateobject. IfNone, a random seed will be obtained from the operating system. Defaults toNone.- reject_by_annotation{
None, ‘omit’} |None How to handle BAD-annotated time segments (annotations starting with “BAD” or “bad”) during channel quality assessment. If
'omit', annotated segments are excluded from analysis (clean segments are concatenated). IfNone(default), annotations are ignored and the full recording is used. This is useful when recordings contain breaks or movement artifacts that shouldn’t influence channel rejection decisions.- matlab_strictbool
Whether or not PyPREP should strictly follow MATLAB PREP’s internal math, ignoring any improvements made in PyPREP over the original code (see Deliberate Differences from MATLAB PREP for more details). Defaults to
False.
- raw
References
[1]Bigdely-Shamlo, N., Mullen, T., Kothe, C., Su, K. M., Robbins, K. A. (2015). The PREP pipeline: standardized preprocessing for large-scale raw analysis. Frontiers in Neuroinformatics, 9, 16.
- interpolate_bads()[source]#
Interpolate any remaining bad channels following robust referencing.
This method can only be called if
perform_reference()has already been run with theinterpolate_badsparameter set toFalse. It cannot be run more than once per instance ofReference.
- perform_reference(max_iterations=4, interpolate_bads=True)[source]#
Estimate the true signal mean and interpolate bad channels.
This function implements the functionality of the performReference function as part of the PREP pipeline on mne raw object.
- Parameters:
Notes
This function calls
robust_referencefirst.
- static remove_reference(signal, reference, index=None)[source]#
Remove the reference signal from the original EEG signal.
This function implements the functionality of the removeReference function as part of the PREP pipeline on mne raw object.
- Parameters:
- signal
np.ndarray, shape(channels,times) The original EEG signal.
- reference
np.ndarray, shape(times,) The reference signal.
- index{
list,None} |None A list of channel indices from which the reference signal should be subtracted. Defaults to all channels in signal.
- signal
- Returns:
np.ndarray, shape(channels,times)The referenced EEG signal.
- robust_reference(max_iterations=4)[source]#
Detect bad channels and estimate the robust reference signal.
This function implements the functionality of the robustReference function as part of the PREP pipeline on mne raw object.
- Parameters:
- Returns:
- noisy_channels:
dict A dictionary of names of noisy channels detected from all methods after referencing.
- reference_signal:
np.ndarray, shape(n, ) Estimation of the ‘true’ signal mean
- noisy_channels: