You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix MNE epochs conversion EEG shape and ICA fields #178
🤖 eeg_mne2eeg_epochs stores data in MNE order instead of EEGPrep/EEGLAB channel-major order and maps MNE ICA component maps into EEGLAB ICA fields. This can pass shape-only tests while producing unusable ICA fields.
Relevant code:
src/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:31 - MNE data order retained
src/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:33 - get_components used as ICA weights
eeg_mne2eeg_epochs assigns ICA fields incorrectly: it calls ica.get_components() (which returns the n_channels x n_components mixing matrix), names it ica_weights, then writes icasphere = mixing, icaweights = I, icawinv = pinv(mixing). The EEGLAB algebra icawinv = pinv(icaweights @ icasphere) is violated and field shapes are wrong. Separately, data = epochs.get_data() keeps MNE order (n_epochs, n_channels, n_times) instead of EEGLAB (nbchan, pnts, trials).
Relevant code
src/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:31 — MNE-ordered data kept verbatim
src/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:33-38 — get_components() mislabeled then swapped into icasphere/icaweights
src/eegprep/functions/adminfunc/eeg_checkset.py:243-267 — canonical EEGLAB ICA algebra used by EEGPrep
tests/test_eeg_mne2eeg_epochs.py:119-123 — asserts the currently broken shapes
Proposed Fix
In eeg_mne2eeg_epochs: transpose data to (nbchan, pnts, trials) and set icawinv = ica.get_components(), icaweights = pinv(icawinv), icasphere = eye(nbchan). This satisfies pinv(icaweights @ icasphere) ≈ icawinv so EEGPrep can reconstruct icaact via the EEGLAB algebra. Tests are updated to assert channel-major shape and the reconstruction identity, replacing the current shape-only ICA checks.
Activity
claude commentedon Jun 10, 2026
🤖 Plan:
eeg_mne2eeg_epochs.py+ testseeg_checkset.py(icawinv = pinv(icaweights @ icasphere))agent/20260610-fix-178eeg_mne2eeg_epochs: transpose data to(nbchan, pnts, trials); seticawinv = ica.get_components(),icaweights = pinv(icawinv),icasphere = I(nbchan)./pre-commit.py --fix+uv run pytest tests/test_eeg_mne2eeg_epochs.py(10 passed, 1 skipped — empty-epochs MNE limitation)PR: #185
Research
eeg_mne2eeg_epochsassigns ICA fields incorrectly: it callsica.get_components()(which returns the n_channels x n_components mixing matrix), names itica_weights, then writesicasphere = mixing,icaweights = I,icawinv = pinv(mixing). The EEGLAB algebraicawinv = pinv(icaweights @ icasphere)is violated and field shapes are wrong. Separately,data = epochs.get_data()keeps MNE order(n_epochs, n_channels, n_times)instead of EEGLAB(nbchan, pnts, trials).Relevant code
src/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:31— MNE-ordered data kept verbatimsrc/eegprep/functions/miscfunc/eeg_mne2eeg_epochs.py:33-38—get_components()mislabeled then swapped into icasphere/icaweightssrc/eegprep/functions/adminfunc/eeg_checkset.py:243-267— canonical EEGLAB ICA algebra used by EEGPreptests/test_eeg_mne2eeg_epochs.py:119-123— asserts the currently broken shapesProposed Fix
In
eeg_mne2eeg_epochs: transposedatato(nbchan, pnts, trials)and seticawinv = ica.get_components(),icaweights = pinv(icawinv),icasphere = eye(nbchan). This satisfiespinv(icaweights @ icasphere) ≈ icawinvso EEGPrep can reconstructicaactvia the EEGLAB algebra. Tests are updated to assert channel-major shape and the reconstruction identity, replacing the current shape-only ICA checks.