annejooyun
(Anne Joo Yun Marthinsen)
February 8, 2023, 7:21pm
1
os: Windows 11
python: 3.10.6
During ICA my data disappears
(and the code has worked fine in a previous project)
Then I run ICA (inside a class - therefore “self”)
self.ica = mne.preprocessing.ICA(n_components=8, max_iter=10000, random_state=97)
self.ica.fit(self.raw_arr)
self.ica.plot_sources(self.raw_arr, title=f'ICA components sub-{self.sub_nr}_ses-{self.ses_nr}_run-{self.run_nr}', show_scrollbars=False)
self.ica.plot_components(colorbar=True, ch_type = self.ch_type , reject='auto')
Which displays everything fine.
Its is not until I plot_overlay that the data disappears
self.ica.plot_overlay(self.raw_arr, exclude=components, picks='eeg', show = True)
Even when I try to exclude no components, the results after cleaning are always straight lines.
Does anybody know how to fix this?
EDIT:
Also, when I try to actually exclude the components, the reconstructed array is left without data as well.
self.ica.exclude = components
self.reconst_arr = self.raw_arr.copy()
self.ica.apply(self.reconst_arr)
cbrnr
(Clemens Brunner)
February 8, 2023, 8:34pm
2
What is the value of components
? It looks like you are excluding all components, which would explain why the data is just flat lines. BTW, if you really have only 8 channels ICA might not be the best method (to remove artifacts and/or separate sources), usually people recommend at least 32 channels.
annejooyun
(Anne Joo Yun Marthinsen)
February 8, 2023, 9:07pm
3
I’ve tried to remove with components = [0]
for ex.
No use no matter what I do. The function calls are later in the code as I have built a class for filtering.
Yes, I only have 8 channels, so I’ll look into other possible methods to artifact removal later on
cbrnr
(Clemens Brunner)
February 9, 2023, 6:20am
4
I cannot reproduce with example data:
import os
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_filt-0-40_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw.crop(tmax=200).pick_types(eeg=True).pick_channels(raw.ch_names[:8])
raw.load_data()
filt_raw = raw.copy().filter(1, None)
ica = ICA(random_state=97)
ica.fit(filt_raw)
ica.plot_overlay(filt_raw, exclude=[0])
However, if I exclude all components, then the black signals (after cleaning) are flat lines just like in your example:
ica.plot_overlay(filt_raw, exclude=list(range(8)))
I am pretty sure that this is what is happening, so please double-check the actual value of your exclude
argument as well as ica.exclude
.
If this is not the case, we’ll need to see a reproducible example with your data to further investigate.
1 Like
annejooyun
(Anne Joo Yun Marthinsen)
February 9, 2023, 8:44am
5
Okey, so I have made a class called Recording, which includes different functions for preprocessing and ICA.
Everything works fine until I try to run test.test_exclude(components=[0,1])
which in turn runs
def test_exclude(self, components):
self.ica.plot_overlay(self.raw_arr, exclude=components, picks='eeg', show = True)
I have tried running it with no components, all components and a subset. It always yields the same results.
Also, if I skip this step, and go straight to excluding and reconstructing
test.exclude_ICA(components=[0])
which runs
def exclude_ICA(self, components):
self.ica.exclude = components
self.reconst_arr = self.raw_arr.copy()
self.ica.apply(self.reconst_arr)
None which yields any data
I’m very stumped