Skip to content

Fix MNE epochs conversion EEG shape and ICA fields #178

Closed

Description

@suraj-ranganath

🤖 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
  • tests/test_eeg_mne2eeg_epochs.py:119 - shape-only ICA assertions

Acceptance criteria:

  • Converted data is shaped nbchan x pnts x trials.
  • EEGLAB ICA fields satisfy the reconstruction algebra used by EEGPrep.
  • Tests fail on the current behavior and cover data shape plus ICA consistency.

Activity

  1. added
    bug
    on Jun 10, 2026
  2. claude commented on Jun 10, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read issue and inspect eeg_mne2eeg_epochs.py + tests
    • Confirm EEGLAB algebra in eeg_checkset.py (icawinv = pinv(icaweights @ icasphere))
    • Duplicate preflight: Strengthen MNE conversion tests for EEG and ICA invariants #183 covers test strengthening, Clean up MNE converter temp files and demo code #181 covers temp cleanup — scope this PR to shape + ICA field semantics only
    • Branch agent/20260610-fix-178
    • Update tests to assert channel-major data and EEGLAB ICA reconstruction algebra (must fail on current code) — verified failure pre-fix
    • Fix eeg_mne2eeg_epochs: transpose data to (nbchan, pnts, trials); set icawinv = 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)
    • Open PR [EEG] Fix mne2eeg_epochs data orientation and ICA fields #185, monitoring CI

    PR: #185

    Research

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions