I try to recreate the functionality of the mne_bids_pipeline _06a2_find_ica_artifacts step.
Here is my function:
def detect_eog_components(
ica: mne.preprocessing.ICA,
raw: mne.io.BaseRaw,
epochs: mne.Epochs,
verbose: bool = True
) -> mne.preprocessing.ICA:
"""
Detect and exclude EOG components from ICA using simulated EOG channels.
This function creates EOG epochs, finds bad EOG components using ICA,
and excludes them from the ICA solution.
Args:
ica: The ICA object to use for component detection.
raw: The unfiltered raw MNE data object.
epochs: The epochs object used for ICA fitting.
verbose: Whether to output additional information during processing.
Returns:
The modified ICA object with EOG components excluded.
"""
logger.info("\t\tUsing simulated EOG channel to autoselect independent components")
eog_channels = ["Fp1", "Fp2"]
# Create EOG epochs
eog_epochs = mne.preprocessing.create_eog_epochs(raw, ch_name=eog_channels, baseline=(None, -0.2), verbose=verbose)
if len(eog_epochs):
if epochs.reject is not None:
eog_epochs.drop_bad(reject=epochs.reject)
# Find bad EOG components
eog_indices, eog_scores = ica.find_bads_eog(
eog_epochs,
ch_name=eog_channels,
threshold=3.0,
verbose=verbose
)
# Exclude detected EOG components
ica.exclude = eog_indices
return ica
Somehow I get a different number of eog epochs detected then with the mne_bids_pipeline. @richard Is the assumption correct that in _06a2_find_ica_artifacts create_eog_epochs uses the unfiltered raw data?