Skip to content

[Fable 5 Findings] Phase 2 — EEG data integrity: stop mutating the caller & preserve ICA invariants #195

Closed

Description

@suraj-ranganath

🤖 Auto-generated from the thermo-nuclear whole-codebase code-quality review at commit 8ba958e (tip of PR #190). Part of the Fable 5 Findings epic #193.

Rationale

The most dangerous structural pattern in the codebase: functions that should be side-effect-free silently mutate the caller's live EEG dict or arrays, and two ICA back-ends break the icaweights·icasphere·data = icaact invariant. A researcher's in-memory dataset is corrupted by an operation they believe is read-only (a save, a plot, a feature extraction), and a second call compounds it.

How to approach

The durable fix is one consistent copy-on-entry discipline at the pop_*/eeg_*/plugin boundary (deepcopy inputs, or a clearly documented in-place contract), and keeping ICA posact/sphere handling from folding the sphere into the weights. These are the highest-priority correctness items after the test suite is honest.

Findings in this phase (15)

Every item below was confirmed by an independent adversarial verification pass against the working tree. Check items off as they land. Full per-finding detail (with verifier notes and full evidence) is in THERMO_NUCLEAR_REVIEW.md on the review branch.

1. eeg_from_data auto-transposes on a shape>shape heuristic, silently risking channel/sample swap

  • functions/popfunc/_file_io.py (lines 122-123)
    • Why: When nbchan is not provided, eeg_from_data transposes any 2-D array where shape[0] > shape[1], assuming more rows than columns means rows are samples. This shared helper backs pop_importdata, pop_loadbci, pop_snapread and pop_fileio text/numpy imports. The channel-major invariant ((nbchan, pnts)) is decided by a guess, so a legitimately tall channel-major array (more channels than time point…
    • Failure mode: Importing a (256 chan x 100 samples) array without nbchan yields a (100 x 256) EEG with nbchan=100 and pnts=256 — every downstream channel operation, chanlocs mapping, and ICA is wrong, with no error.
    • Fix: Do not infer orientation from a size comparison; require nbchan (or an explicit orientation flag) for ambiguous 2-D imports, or align with EEGLAB's documented convention and fail clearly when it cannot be determined.
    • Evidence: if not nbchan and array.ndim == 2 and array.shape[0] > array.shape[1]: array = array.T

2. posact recompute folds non-identity sphere into icaweights (same invariant break as eeg_runica)

  • functions/popfunc/eeg_amica.py (lines 113-131)
    • Why: eeg_amica stores a real sphering matrix EEG['icasphere'] = mods['S'][:num_pcs, :] (line 85) and computes icaact via (icaweights @ icasphere) @ data (line 89). The posact branch ends with EEG['icaweights'] = pinv(EEG['icawinv']) (line 131), which makes icaweights equal the full unmixing weights@sphere, so icaweights@icasphere no longer reconstructs the unmixing matrix.
    • Failure mode: Reachable via bids_preproc.py:823 eeg_amica(EEG, posact=True, sortcomps=True, ...). After a sign flip, the standard EEGLAB ICA fields are mutually inconsistent: stored icaact (flipped) disagrees with any recomputation from icaweights@icasphere, corrupting pop_subcomp and downstream component analyses.
    • Fix: Flip the affected rows of icaweights directly instead of recomputing via pinv(icawinv); keep icasphere unchanged. Share one helper with eeg_runica/eeg_picard so the three backends cannot drift.
    • Evidence: line 85 EEG['icasphere'] = mods['S'][:num_pcs, :] (non-identity); line 89 EEG['icaact'] = (EEG['icaweights'] @ EEG['icasphere']) @ data; line 131 EEG['icaweights'] = pinv(EEG['icawinv']).

3. eeg_amica/eeg_picard flatten epoched data with C-order while eeg_runica uses F-order, an undocumented inconsistency in the same ICA layer

  • functions/popfunc/eeg_amica.py (lines 66-67)
    • Why: eeg_runica flattens via flatten_ica_data (order='F', the EEGLAB epoch ordering) and reshapes back via reshape_ica_activations (order='F'). eeg_amica (line 67 data.reshape(data.shape[0], -1)) and eeg_picard (line 37 same) use NumPy default C-order for both flatten and the icaact reshape-back. Because each backend is internally self-consistent (same order in and out), stored icaact is not numerica…
    • Failure mode: A future change that mixes a backend's stored icaact with the F-order flatten used elsewhere (e.g. feeding amica-produced data through a helper that assumes EEGLAB column-major epoch order) would silently scramble per-trial sample mapping. The divergence is a latent trap precisely because all three look like they do the same thing.
    • Fix: Use flatten_ica_data/reshape_ica_activations (order='F') in eeg_amica and eeg_picard too, matching eeg_runica and EEGLAB's documented epoch flattening; or add an explicit comment justifying C-order if the backend requires it.
    • Evidence: eeg_runica.py:29 data = flatten_ica_data(EEG['data'].astype('float64')) vs eeg_amica.py:66-67 data = EEG['data'].astype('float64'); data = data.reshape(data.shape[0], -1) and eeg_picard.py:37 dat…

4. eeg_amica and load_amica_model mutate the caller's EEG dict in place

  • functions/popfunc/eeg_amica.py (lines 8-133)
    • Why: Both functions assign directly into the passed EEG (EEG['icaweights']=..., EEG['icaact']=..., EEG['etc']['amica']=mods) with no copy. AGENTS.md mandates explicit inputs/return values and no hidden mutation of caller dicts. pop_runica shields this by deep-copying via _prepare_ica_dataset before calling, but the functions are exported in src/eegprep/init.py and called directly in bids_preproc.py…
    • Failure mode: A user calling out = eeg_amica(EEG, ...) (the documented public API) finds their original EEG silently overwritten with ICA fields, the prior icaweights gone, and EEG['etc']['amica'] injected. Code holding the pre-ICA EEG for comparison is corrupted. The in-place write also means a mid-run exception leaves a half-populated EEG.
    • Fix: Deep-copy at function entry (EEG = copy.deepcopy(EEG)) and return the copy, matching the explicit-return contract used elsewhere; same for eeg_runica/eeg_picard so all three backends are safe to call standalone.
    • Evidence: eeg_amica.py:84-97 writes EEG['icaweights'], EEG['icaact'], EEG['etc']['amica'] directly on the argument; no copy.deepcopy anywhere in the module (only import numpy/pinv/runamica).

5. posact sign-flip recompute folds sphere into icaweights, breaking the icaweights·icasphere·data = icaact invariant

  • functions/popfunc/eeg_runica.py (lines 66-85)
    • Why: EEGLAB's core ICA invariant is icaact = (icaweights @ icasphere) @ data. After flipping component signs, the code sets EEG['icaweights'] = finite_pinv(EEG['icawinv'], solver=pinv). pinv(icawinv) reconstructs the FULL unmixing matrix (weights @ sphere), not the weights factor. Since icasphere is the non-identity sphering matrix returned by runica (line 37 EEG['icasphere']=sphere), icaweights @ icas…
    • Failure mode: Reachable via src/eegprep/plugins/EEG_BIDS/bids_preproc.py:825 which calls eeg_runica(EEG, posact=True, ...). When at least one component is sign-flipped, EEG.icaweights no longer satisfies icaweights@icasphere = unmixing. pop_subcomp removal, ICLabel, topoplots, and rejection passes that recompute activations from weights@sphere will use a corrupted unmixin…
    • Fix: When flips happen, do not recompute icaweights via pinv(icawinv). Sign flips commute through the factorization, so flip the corresponding rows of icaweights directly (EEG['icaweights'][r, :] = -EEG['icaweights'][r, :] for flipped r), leavin…
    • Evidence: line 39 unmixing = finite_matmul(weights, sphere); line 79 EEG['icawinv'][:, r] = -EEG['icawinv'][:, r]; line 84 EEG['icaweights'] = finite_pinv(EEG['icawinv'], solver=pinv) — recompute discards…

6. pop_headplot silently mutates caller EEG dict but only returns figures

  • functions/popfunc/pop_headplot.py (lines 403-438, 95-111)
    • Why: EEGLAB's pop_headplot.m returns [EEG, com] precisely because it attaches the (re)computed spline file to EEG.splinefile/EEG.icasplinefile (pop_headplot.m lines 347-386). The EEGPrep port keeps the in-place mutation (EEG[fieldname]=path at lines 407, 425-426, 433; also EEG['headplotmeshfile']=... line 426) but the function signature returns figures (or (figures, command)) and never the EEG. The mut…
    • Failure mode: A caller doing figs = pop_headplot(EEG, ...) has EEG['splinefile'] silently rewritten. The persistent spline-file association is never surfaced through the return value, so any code that relied on EEG being unchanged by a plot call gets a mutated dict; the recomputed file path is also not recorded in the returned history command in a way that re-running wo…
    • Fix: Either keep EEG immutable in the plot path and return the spline assignment explicitly, or follow EEGLAB and return the mutated EEG alongside figures/command so the caller (and session) can store it deliberately. Do not mutate the caller di…
    • Evidence: EEG[fieldname] = path (l.407), EEG[fieldname] = splinefile / EEG["headplotmeshfile"] = ... (l.425-426), EEG[fieldname] = other (l.433); function returns (figures, command) (l.111) with no EE…

7. pop_saveset mutates the caller's live EEG dict, corrupting 0-based urchan/urevent/latency in memory

  • functions/popfunc/pop_saveset.py (lines 403-474)
    • Why: _matlab_empty_if_missing(EEG, 'chanlocs') and (EEG, 'event') return the caller's own list-of-dict objects without copying (only icachansind is .copy()d at line 379). The save path then mutates those shared dicts in place: eeglab_dict['chanlocs'][i]['urchan'] = ... + 1, eeglab_dict['event'][i]['urevent'] = ... + 1, and ev['latency'] = float(ev['latency']). EEGPrep's invariant is that…
    • Failure mode: After pop_saveset(EEG), EEG['chanlocs'][i]['urchan'] and EEG['event'][i]['urevent'] are now 1-based in memory; any 0-based consumer (interp, event lookups) reads the wrong channel/event, and a second save bumps them again to 2-based. Round-trip save->reload no longer matches the original session object.
    • Fix: Build the MATLAB-facing structures from copies (deepcopy the chanlocs/event lists, or apply the +1 offset while constructing new dicts) so the +1 conversions and latency float coercion never touch the caller's EEG. Mirror the `icachansind.c…
    • Evidence: eeglab_dict['chanlocs'][i]['urchan'] = eeglab_dict['chanlocs'][i]['urchan'] + 1 ... eeglab_dict['event'][i]['urevent'] = eeglab_dict['event'][i]['urevent'] + 1 ... ev['latency'] = float(ev['latency'])

8. pop_select mutates the caller's EEG dict in place (no deepcopy), and inconsistently so

  • functions/popfunc/pop_select.py (lines 44-576 (esp. 131, 304, 318, 428, 449, 539, 553))
    • Why: Every other pop_* in this scope (pop_reref:109, pop_epoch:238, pop_resample:188, pop_mergeset:130, pop_rmbase:177, pop_selectevent:229, pop_editeventvals:131, pop_adjustevents:81, eeg_eegrej:291, eeg_interp:46) copies the input before mutating, establishing a copy-on-write contract EEGLAB users rely on (the source dataset in ALLEEG must stay intact). pop_select breaks it: _pop_select_apply receive…
    • Failure mode: EEG2 = pop_select(EEG, channel=[0,1]) silently also corrupts the original EEG (data resized, reject/stats cleared, event latencies shifted). Worse, the behavior is path-dependent: when the continuous time-rejection branch runs, line 428 rebinds EEG = eeg_eegrej(EEG, pts) to a fresh deepcopy, so later mutations hit the copy and the caller is mostly spared — b…
    • Fix: Add EEG = copy.deepcopy(EEG) at the top of _pop_select_apply (matching siblings) and drop the now-redundant per-branch copy.deepcopy(ev) at line 371.
    • Evidence: Line 553 EEG['reject'] = {}; line 318 ev['latency'] = (...); line 539 ev.pop('epoch', None); line 449 EEG['data'] = data[chan_idx, :, :][:, :, trial_idx_0]. No deepcopy(EEG) exists anywhere…

9. runica() mutates the caller's data array in place (channel mean subtraction)

  • functions/sigprocfunc/runica.py (lines 226, 487-489)
    • Why: data = np.asarray(data, dtype=np.float64) at line 226 returns the same object when the input is already a float64 array (no copy). The training loop then subtracts each channel mean in place: data[i, :] = data[i, :] - rowmeans[i] (line 489), and later adds means back in place (lines 1322/1328). Any direct caller passing a float64 array has its data permanently altered. This violates the AGENTS.md…
    • Failure mode: A standalone caller doing weights, sphere, ... = runica(EEG['data']) (or any float64 array they still need) silently gets it mean-subtracted. The current GUI/session path is protected only by an incidental copy in eeg_runica (EEG['data'].astype('float64') copies), so the bug is latent but real and easy to reintroduce by changing that one upstream line.
    • Fix: Copy at entry: data = np.array(data, dtype=np.float64, copy=True) (or np.asarray(...).copy()). This guarantees runica never mutates its input regardless of dtype, and removes the hidden reliance on eeg_runica's incidental copy.
    • Evidence: L226 data = np.asarray(data, dtype=np.float64); L488-489 for i in range(data.shape[0]): data[i, :] = data[i, :] - rowmeans[i]. eeg_runica.py L29 data = flatten_ica_data(EEG['data'].astype('float6…

10. coords_to_mm and coords_RAS_to_ALS mutate the caller's array in place

  • plugins/EEG_BIDS/coords.py (lines 17-38)
    • Why: These are value-returning numeric helpers (sigprocfunc-style transforms) so callers reasonably assume they produce a new array. Instead coords_to_mm does 'coords *= 10.0' for cm/m and coords_RAS_to_ALS does 'coords[:, 1] = -coords[:, 1]', both mutating the input ndarray. coords_any_to_RAS uses np.array(coords, copy=False) then np.dot (returns new), so the chain is inconsistent: some links mutate,…
    • Failure mode: At pop_load_frombids.py:1046 the input is 'coords = best_data["coordinates"]' (a reference into the loaded montage dict). coords_to_mm(coords, unit) then scales best_data['coordinates'] in place for cm/m units, and coords_RAS_to_ALS flips its y column in place. Today best_data is loadmat'd fresh per call and not reused after the chain, so corruption is laten…
    • Fix: Make these helpers non-mutating: in coords_to_mm return 'coords * 10.0' (and operate on a copy / asarray with copy), and in coords_RAS_to_ALS build a new array rather than assigning into the input column. Match the copy semantics already us…
    • Evidence: coords_to_mm: 'elif unit in ("cm", "centimeters"): coords *= 10.0'. coords_RAS_to_ALS: 'coords = coords[:, [1, 0, 2]] # Swap x and y' then 'coords[:, 1] = -coords[:, 1] # Invert the y coordinate'. Cal…

11. eeg_rpsd mutates the global numpy RNG seed

  • plugins/ICLabel/eeg_rpsd.py (lines 56)
    • Why: This feature-extraction routine calls np.random.seed(0) to mimic MATLAB rng('default'), but seeding the global RNG is a hidden global-state mutation that affects every subsequent np.random call in the user's session. clean_channels.py (line 109) shows the correct pattern using a local RandomState(5489).
    • Failure mode: After ICLabel feature extraction runs, any unrelated downstream code in the same process that relies on np.random (e.g. RANSAC in clean_channels if it had used the global RNG, bootstrapping, jitter) silently gets a reseeded, reproducible-but-unexpected sequence. This makes results order-dependent on whether ICLabel ran first and is a classic source of irrepr…
    • Fix: Use a local rng = np.random.RandomState(0) and rng.permutation(n_seg) instead of seeding the global RNG; do not call np.random.seed at module/function scope.
    • Evidence: np.random.seed(0) # rng('default') in MATLAB followed by subset = np.random.permutation(n_seg)[...].

12. HP snapshot is a shallow copy sharing EEG['etc'] with later mutation stages

  • plugins/clean_rawdata/clean_artifacts.py (lines 200, 223-290)
    • Why: clean_artifacts returns HP as 'EEG dataset after initial high-pass (drift removal)'. A shallow EEG.copy() shares the nested etc dict (and any non-reassigned arrays) with the object that subsequent stages keep mutating.
    • Failure mode: HP = EEG.copy() is a shallow dict copy. After it, clean_channels writes EEG['etc']['clean_channel_mask'] (line 223 reads it; clean_channels writes it) and clean_windows writes EEG['etc']['clean_sample_mask'] into the same dict object referenced by HP['etc']. The returned HP therefore reports channel/window masks from stages that ran AFTER the high-pass sna…
    • Fix: Use copy.deepcopy(EEG) for the HP snapshot (and similarly verify BUR), so the returned intermediate datasets are true point-in-time snapshots.
    • Evidence: # Keep a copy after HP for optional return HP = EEG.copy() — shallow; later removed_channels = ~EEG['etc']['clean_channel_mask'] and clean_windows etc['clean_sample_mask'] = sample_mask mutate…

13. clean_asr mutates the caller's EEG['data'] array in place

  • plugins/clean_rawdata/clean_asr.py (lines 83-84, 152-153, 203, 371(asr_calibrate))
    • Why: clean_asr is a user-facing cleaning function. clean_artifacts already documented this hazard and worked around it (clean_artifacts.py lines 241-244 save original_data because 'Python dicts are passed by reference'), which is a smell that the underlying contract leaks mutation.
    • Failure mode: At line 83 data = np.asarray(EEG['data'], dtype=np.float64) aliases EEG['data'] when it is already float64. When ref_maxbadchannels='off' (or fallback), ref_section_data = data (the same array), and asr_calibrate does X[~np.isfinite(X)] = 0.0 (asr_calibrate.py line 371) in place — zeroing NaN/Inf samples directly in the caller's EEG data even on the ca…
    • Fix: Copy data with np.array(EEG['data'], dtype=np.float64) (force copy) and assign results to a freshly copied EEG dict rather than the input; or have asr_calibrate copy X before zeroing non-finite samples.
    • Evidence: clean_asr line 203: EEG['data'] = outdata; asr_calibrate line 94 X = np.asarray(X, dtype=float) then line 371 X[~np.isfinite(X)] = 0.0 mutate aliased arrays.

14. clean_windows mutates the caller's EEG dict before deep-copy boundary

  • plugins/clean_rawdata/clean_windows.py (lines 82-85, 195-209)
    • Why: Like clean_asr, clean_windows writes EEG['data'] (line 84) and EEG['etc'] (lines 195-209) directly on the input dict; only eeg_eegrej (line 189) returns a fresh deep-copied object. The pre-rejection writes and the etc/clean_sample_mask compositing happen on the caller's original object.
    • Failure mode: EEG['data'] = input_data.astype(np.float64, copy=False) aliases/overwrites the caller's data, and the clean_sample_mask block writes into the caller's etc. When clean_windows is called standalone (it is public and exported), the caller's input dataset is mutated even on the no-rejection path (rejected_intervals empty -> eeg_eegrej deep-copy skipped at line…
    • Fix: Deep-copy EEG at function entry (or operate on a local copy of data and build a new dict), so clean_windows returns a distinct object and never mutates its argument.
    • Evidence: EEG['data'] = input_data.astype(np.float64, copy=False) (line 84) and etc['clean_sample_mask'] = sample_mask writing into the input EEG's etc; eeg_eegrej (which deep-copies) is only invoked if re…

15. pop_clean_rawdata mutates caller EEG in place except when vis is on

  • plugins/clean_rawdata/pop_clean_rawdata.py (lines 72-78)
    • Why: This is the session/history entry point. Every other pop_* wrapper in scope (pop_iclabel, pop_icflag via _flag_dataset) defends against in-place mutation by deep-copying. Here the caller's EEG dict is passed straight into clean_artifacts unless show_vis_artifacts happens to be set (line 72 only deep-copies in that branch).
    • Failure mode: clean_artifacts mutates the passed dict in place through clean_flatlines/clean_drifts/clean_channels/clean_asr (they assign EEG['data'], EEG['etc'], EEG['nbchan'] on the same object). If any stage raises (e.g. ASR calibration 'Not enough calibration data', or clean_windows 'Empty data array'), the caller's original dataset is left half-cleaned: drift-filtere…
    • Fix: Deep-copy EEG once at the top of pop_clean_rawdata before calling clean_artifacts (mirroring pop_icflag's copy.deepcopy), so a failure leaves the input dataset untouched and success returns a distinct object.
    • Evidence: original_eeg = copy.deepcopy(EEG) if show_vis_artifacts else None then clean_eeg, _hp, _bur, _removed_channels = clean_artifacts(EEG, **options) — EEG is only copied for the vis path, never for th…

Generated by automated review; verify each finding from first principles before fixing.

Activity

  1. added
    phase
    on Jun 12, 2026
  2. claude commented on Jun 12, 2026

    @claude
    Contributor

    🤖 Plan:

    • Verify findings against the working tree
    • Check for overlapping open PRs/issues
    • Post research + proposed approach for human review
    • Await scope/sequencing decision before opening PRs

    Research

    All 15 findings reproduce on the current tip; no duplicate PRs found (gh pr list --state open returns only #190, #191, #177, none touching ICA/copy semantics). Scope is multi-module across 13 files; far beyond the small-self-contained-fix threshold, so per agent instructions I am stopping at analysis and not opening a parallel PR.

    The findings cluster into orthogonal problems with shared fixes — splitting into separately reviewable PRs is the right shape:

    1. ICA invariant breakage (posact path) — findings 2 & 5: eeg_runica.py:84 and eeg_amica.py:131 both do EEG['icaweights'] = pinv(EEG['icawinv']) after sign flips. Since icasphere is non-identity, this folds sphere into weights and breaks icaweights @ icasphere @ data = icaact. Fix is the same in both: flip EEG['icaweights'][r, :] rows directly instead of recomputing.
    2. ICA back-end inconsistencies — finding 3: eeg_amica.py:66-67 and eeg_picard.py:37 use C-order reshape while eeg_runica.py:29 uses F-order via flatten_ica_data. Internally consistent today, latent trap.
    3. Copy-on-entry contract violations — findings 4, 6, 7, 8, 9, 10, 12, 13, 14, 15: 10 user-facing functions mutate the caller's EEG dict, arrays, or nested chanloc/event records. Pattern is identical (no copy.deepcopy(EEG) at entry); fix is identical.
    4. Hidden global state — finding 11: eeg_rpsd.py:56 calls np.random.seed(0) reseeding the process RNG.
    5. Import-time shape guessing — finding 1: _file_io.py:122-123 infers orientation from shape[0] > shape[1].

    Relevant code (spot-confirmed)

    Proposed Approach

    Split into 4 PRs, smallest-blast-radius first. Each is independently reviewable and ~50–200 lines incl. tests.

    PR A — ICA posact invariant (findings 2, 5)

    • Add a shared helper _apply_sign_flips(EEG, flipped_indices) in a common module (likely functions/popfunc/_ica_common.py, new) that flips rows of icaweights and columns of icawinv and matching planes of icaact directly. No pinv recompute.
    • Wire eeg_runica, eeg_amica, eeg_picard through the same helper.
    • Tests: assert np.allclose(icaweights @ icasphere @ data_flat, icaact_flat) after posact=True for each backend. Use small synthetic data; reuse tests/test_eeg_runica.py style. The AMICA backend test must preserve the existing AMICA skip behavior.

    PR B — Copy-on-entry contract (findings 4, 6, 7, 8, 12, 13, 14, 15)

    • Add copy.deepcopy(EEG) at the top of each entry point: eeg_amica, load_amica_model, pop_headplot (or change return shape), pop_saveset, pop_select._pop_select_apply (drop the per-branch deepcopy(ev)), clean_asr, clean_windows, pop_clean_rawdata.
    • Promote clean_artifacts HP/BUR snapshots to copy.deepcopy (finding 12).
    • pop_headplot: prefer the EEGLAB shape — return (EEG, com) alongside figures — to preserve the spline-file association the caller needs. This is a small API break; confirm with maintainers.
    • Tests: one parametrized test that snapshots EEG via copy.deepcopy, runs each function, asserts the input is byte-identical (numerical hash of data, event[*]['latency'], event[*]['urevent'], chanlocs[*]['urchan'], etc).

    PR C — Misc hidden mutation (findings 9, 10, 11)

    • runica(): data = np.array(data, dtype=np.float64, copy=True) at entry.
    • coords_to_mm, coords_RAS_to_ALS: return new arrays (coords * 10.0, build new ndarray for sign flip).
    • eeg_rpsd: rng = np.random.RandomState(0); rng.permutation(n_seg).
    • Tests: pass a known float64 array / ndarray, assert input is unchanged after the call; for rpsd, snapshot np.random.get_state() before/after.

    PR D — Import orientation (finding 1)

    • Decide policy with maintainers: (a) require nbchan/orientation for ambiguous 2-D imports and raise otherwise, or (b) document EEGLAB's convention and stick to it without heuristic. EEGLAB's pop_importdata.m does not auto-transpose — it trusts nchan. Recommend matching that.
    • Tests: (256, 100) array without nbchan must error clearly; with nbchan=256 must produce nbchan=256, pnts=100.

    Plus finding 3 (C/F-order divergence): roll into PR A — same files. Replace direct data.reshape(...) in eeg_amica and eeg_picard with flatten_ica_data / reshape_ica_activations.

    Sequencing. A and C are pure bug fixes, low risk, can land in parallel. B is larger and touches the GUI/console history contract for pop_headplot — needs explicit sign-off on whether to change its return signature. D needs a small policy call.

    Questions before I implement

    1. Confirm 4-PR split (A/B/C/D) vs. one big PR closing the issue in a single sweep.
    2. PR B: is changing pop_headplot to return (EEG, figs, com) (matching EEGLAB) acceptable, or should it keep the current (figs, com) and avoid touching EEG entirely (i.e. require caller to assign EEG['splinefile'] explicitly via the returned command)?
    3. PR D: agree on EEGLAB-parity policy — require explicit nbchan for ambiguous 2-D imports, no heuristic?
    4. Any of these you'd prefer I drop or de-prioritize for this phase?

    Will start on PR A as soon as scope is confirmed.

  3. suraj-ranganath commented on Jun 12, 2026

    @suraj-ranganath
    MemberAuthor

    🤖 Closing because Phase 2 was completed by merged PR #202 and is included in epic PR #206.

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

Metadata

Metadata

Labels

phase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions