.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_mne_integration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_mne_integration.py: AMICA via MNE-Python ==================== This example shows how to fit AMICA through the :func:`amica.fit_ica` wrapper. The wrapper returns a standard :class:`mne.preprocessing.ICA` object, so the usual MNE methods work as expected: - ``plot_components`` - ``plot_sources`` - ``get_sources`` - ``apply`` The example uses the MNE sample dataset. To run it on your own data, replace ``load_raw()`` with your own loading code. .. GENERATED FROM PYTHON SOURCE LINES 21-23 Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 23-30 .. code-block:: Python from __future__ import annotations import mne from amica import fit_ica .. GENERATED FROM PYTHON SOURCE LINES 31-42 Load data --------- Here we use the MNE sample dataset. You can replace this function with your own data loader, for example: .. code-block:: python raw = mne.io.read_raw_fif("your_data_raw.fif", preload=True) raw = mne.io.read_raw_eeglab("your_data.set", preload=True) raw = mne.io.read_raw_brainvision("your_data.vhdr", preload=True) .. GENERATED FROM PYTHON SOURCE LINES 42-65 .. code-block:: Python def load_raw() -> mne.io.BaseRaw: """Load and minimally preprocess a Raw recording.""" sample = mne.datasets.sample.data_path() raw = mne.io.read_raw_fif( sample / "MEG" / "sample" / "sample_audvis_raw.fif", preload=True, ) raw.pick("eeg") raw.filter(1.0, 40.0) return raw raw = load_raw() print( f"Raw data: {len(raw.ch_names)} EEG channels, " f"{raw.n_times} samples @ {raw.info['sfreq']:.0f} Hz" ) .. GENERATED FROM PYTHON SOURCE LINES 66-70 Fit AMICA --------- ``fit_ica`` fits AMICA and returns a standard MNE ``ICA`` object. .. GENERATED FROM PYTHON SOURCE LINES 70-80 .. code-block:: Python ica = fit_ica( raw, n_components=15, max_iter=500, random_state=42, ) print(f"Fitted ICA with {ica.n_components_} components") .. GENERATED FROM PYTHON SOURCE LINES 81-85 Inspect sources --------------- Once fitted, the result behaves like any other MNE ICA object. .. GENERATED FROM PYTHON SOURCE LINES 85-90 .. code-block:: Python sources = ica.get_sources(raw) print(f"Sources shape: {sources.get_data().shape}") .. GENERATED FROM PYTHON SOURCE LINES 91-103 Next steps ---------- In an interactive session, you can use standard MNE visualization and cleaning methods: .. code-block:: python ica.plot_components() ica.plot_sources(raw) ica.exclude = [0, 1] ica.apply(raw) .. _sphx_glr_download_auto_examples_01_mne_integration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_mne_integration.ipynb <01_mne_integration.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_mne_integration.py <01_mne_integration.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_mne_integration.zip <01_mne_integration.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_