# Help for understanding the find\_ica\_artifacts part of mne\_bids\_pipeline

**URL:** <https://mne.discourse.group/t/help-for-understanding-the-find-ica-artifacts-part-of-mne-bids-pipeline/10379>\
**Category:** Support & Discussions\
**Tags:** mne-bids-pipeline\
**Created:** [October 11, 2024, 4:50pm UTC](https://mne.discourse.group/t/help-for-understanding-the-find-ica-artifacts-part-of-mne-bids-pipeline/10379 "2024-10-11T16:50:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![librethinker](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@librethinker](https://mne.discourse.group/u/librethinker)\
**Post date:** [October 11, 2024, 4:50pm UTC](https://mne.discourse.group/t/help-for-understanding-the-find-ica-artifacts-part-of-mne-bids-pipeline/10379/1 "2024-10-11T16:50:24Z")

</div>

I try to recreate the functionality of the mne\_bids\_pipeline [\_06a2\_find\_ica\_artifacts](https://github.com/mne-tools/mne-bids-pipeline/blob/main/mne_bids_pipeline/steps/preprocessing/_06a2_find_ica_artifacts.py) step.

Here is my function:

```python
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?

---

<div class="post-metadata">

**Author:** ![librethinker](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@librethinker](https://mne.discourse.group/u/librethinker)\
**Post date:** [October 17, 2024, 10:28am UTC](https://mne.discourse.group/t/help-for-understanding-the-find-ica-artifacts-part-of-mne-bids-pipeline/10379/2 "2024-10-17T10:28:45Z")

</div>

@richard Sorry for pinging you again but I am still not able to reproduce what the mne-bids-pipeline does in this step despite looking at the source code multiple times.  
I really hope for your insights!

Thanks,  
Richard
