[Mne_analysis] Convert EEG MNE_RawArray to ndarray with time courses

Dan McCloy dan.mccloy at gmail.com
Wed Aug 28 20:54:53 EDT 2019
Search archives:

        External Email - Use Caution        

This works for me:

import os
import numpy as np
import matplotlib.pyplot as plt
import mne
from mne.preprocessing import ICA

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw.crop(tmax=60.).load_data().filter(l_freq=1., h_freq=None)
ica = ICA(n_components=30, random_state=97)
ica.fit(raw)

sources_raw = ica.get_sources(raw)
sources_array, times = sources_raw.get_data(return_times=True)

# PLOT THE NUMPY ARRAY OF SOURCES
fig, ax = plt.subplots()
# this will let us plot the sources without overlapping:
offsets = 15 * np.linspace(29, 0, len(sources_array))
ax.plot(times, sources_array.T + offsets, linewidth=0.5, color='k')

# COMPARE WITH THE MNE-PYTHON PLOT OF SOURCES
ica.plot_sources(raw)


On Wed, Aug 28, 2019 at 5:16 PM Brown Amumbwe <bamumbwe at gmail.com> wrote:

>         External Email - Use Caution
>
> Hi,
> Basically I have an MNE RawArray object and I would like to convert it to
> an ndarray.
>
> I am doing an ICA of an EEG signal with 22 channels. I need an ndarray
> with the corresponding time courses of the the Independent Components from
> the ICA.
>
> Code Snippet
> ica = mne.preprocessing.ICA(method="infomax", random_state=1)
> ica.fit(raw_tmp)
>
> data = ica.get_sources(inst=raw_tmp)
>
> data is a RawArray object
> Using
> cpt = data.get_data()
>
> gives an ndarray but without the time courses of the ICs
>
> Thank you for any help.
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190828/ab7cf142/attachment-0001.html 


More information about the Mne_analysis mailing list