sccn / eeglab

EEGLAB is an open source signal processing environment for electrophysiological signals running on Matlab and developed at the SCCN/UCSD
https://eeglab.ucsd.edu/
Other
593 stars 241 forks source link

Update std_topo.m #780

Closed neuromechanist closed 3 months ago

neuromechanist commented 3 months ago

Update the iterator for the ICA inverse weight matrix. This will close #779.

arnodelorme commented 3 months ago

I do not understands "Line 104 should be a boolean instead: This guarantees to work whether compsToCompute is continuous or not."

Can you provide an example where it fails?

neuromechanist commented 3 months ago

Nevermind. This solution also does not fix the problem.

The main problem is that std_precomp(STUDY, ALLEEG, 'components','scalp','on') is not compatible with removing components based on ICLABEL using pop_subcomp. The reason is that the pop_subcomp reduces EEG.icawinv to only select components, while std_precomp (and more specifically std_topo) seems to need the full EEG.icawinv and work based on the component list from STUDY.datasetinfo.comps.

Study level functions, such as std_editset also can only select components based on being inbrain or RV. So, I am unsure how we can exclude based on ICLABEL for component-level analysis across a study.

One quick fix that I am going to do for now on my HBN pipeline is to update STUDY.datasetinfo.comps to the updated range from pop_subcomp. Then, things will hopefully work, although we will lose the actual number of the ICA sources.

arnodelorme commented 3 months ago

Oh, yes, you can easily only consider ICLabel components.

EEG = pop_icflag(EEG, [0 0;0 0; 0.9 1; 0 0; 0 0; 0 0; 0 0]);
EEG = pop_selectcomps(EEG, EEG.reject.gcompreject == 0); % or == 1

The components not considered are removed. To keep the components, maybe

ALLEEG = pop_icflag(ALLEEG, [0 0;0 0; 0.9 1; 0 0; 0 0; 0 0; 0 0]);
STUDY = pop_precomp(STUDY, ALLEEG, find(EEG.reject.gcompreject == 0), 'scalp', 'on');
neuromechanist commented 3 months ago

I think this solution, while they might be working, is not ideal for an analysis that is based on importing a BIDS dataset into a STUDY.

The component list is available under STUDY.datasetinfo.comps. That list can be modified with RV and inbrain using std_editset. The advantage of having this list is that, later on, for clustering, we can use the same list. So, it might be best to modify that list with ICflags to make sure that only those components are being retained.

I should add that I am currently using ICLABEL to retain data, not to reject (which might be the intended use). For large datasets, I think having a deciding factor like ICLABEL is crucial for a relatively fast and reliable turnaround of analyses.

neuromechanist commented 3 months ago

ok, I ended up with a simple for loop to update the component subfiled under datasetinfo:

EEG_subjs = unique(string({EEG(:).subject}));
nobrain_subjs = [];
for s = EEG_subjs
    idx = find(string({EEG(:).subject})==s);
    for i = idx
        STUDY.datasetinfo(i).comps = find(EEG(i).reject.gcompreject == 0)';
    end    
end

Now, precomp seems to work as expected.

arnodelorme commented 3 months ago

OK, there is no more changes then. I have closed the pull request? Feel free to reopen.