Skip to content

[STUDY] Complete standalone integration - #93

Merged
arnodelorme merged 42 commits into
developfrom
feature/study-standalone-completion
Jun 2, 2026
Merged

arnodelorme merged 42 commits into
developfrom
feature/study-standalone-completion

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented May 30, 2026 •

Copy link
Copy Markdown
Member

Complete STUDY and standalone EEGPrep integration after the phase branches landed on the epic branch. Adds closeout fixes for STUDY replay, component measure selection, dataset resave parity, GUI visual parity polish, and autonomous review findings. Detailed phase breakdown and GUI evidence are in the first PR comment.

Fixes #78

Implement STUDY metadata and design workflow
…ion' into phase/6a-admin-help-docs

# Conflicts:
#	src/eegprep/resources/help/pop_loadstudy.md
#	src/eegprep/resources/help/pop_savestudy.md
#	src/eegprep/resources/help/pop_study.md
#	src/eegprep/resources/help/pop_studyerp.md
#	src/eegprep/resources/help/pop_studywizard.md
#	tests/test_menu_placeholder_inventory.py
[Study] Add packaged help and menu docs
Phase 6b: public API and plugin packaging
[STUDY] Implement measure precompute workflows
Phase 5c STUDY component clustering
Phase 6c standalone STUDY integration hardening
@claude

claude Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Code review in progress

  • Load skill and gather PR context
  • Identify relevant CLAUDE.md/AGENTS.md files
  • Summarize PR scope and risk areas
  • Run 4 parallel review agents (compliance, conventions, correctness, EEGLAB parity)
  • Validate candidate issues
  • Post final review

View job run • Branch: feature/study-standalone-completion

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Epic closeout details for #78.

This PR integrates the STUDY and standalone EEGPrep epic branch feature/study-standalone-completion into origin/develop. It includes all phase PRs that were merged into the epic branch, plus the final closeout fixes from autonomous review and integration testing.

Phase and issue map:

Phase Issue PR Scope
5a #65 #89 STUDY metadata, datasetinfo/design editing, save/load/resave, session and console synchronization.
5b #79 #91 STUDY precompute, cached measure readers, channel/component measure plotting.
5c #83 #90 STUDY preclustering, k-means clustering, cluster editing, cluster plotting hooks.
5d #80 #92 End-to-end STUDY parity fixtures, GUI/console QA, final STUDY integration hardening.
6a #66 #87 Packaged help resources, Help/admin menu docs, menu inventory parity.
6b #81 #88 Public API exports, plugin-management UX, package data, examples.
6c #82 #92 Standalone release hardening, runtime EEGLAB decoupling, final evidence.
Epic #78 #93 Final integration PR to origin/develop.

Implemented features, organized by phase:

Phase 5a, STUDY metadata and session foundation:

  • Added STUDY creation/edit flows through pop_study, pop_studydesign, std_editset, std_makedesign, std_selectdesign, and std_checkset.
  • Added STUDY save/load/resave via pop_savestudy and pop_loadstudy, including dataset loading behavior and metadata consistency checks.
  • Wired STUDY state into EEGPrepSession, the GUI Study menu, and eegprep-console so STUDY, CURRENTSTUDY, ALLEEG, and CURRENTSET stay synchronized.
  • Added STUDY GUI dialog specs, visual parity cases, help resources, and tests for GUI cancel paths and console replay.

Phase 5b, STUDY measures and plotting:

  • Added std_precomp and pop_precomp for channel and component ERP, spectrum, ERSP, and ITC measure precompute.
  • Added cached measure readers (std_readdata, std_readerp, std_readspec, std_readersp) and cached plotting through std_erpplot, std_specplot, std_erspplot, std_itcplot, and pop_chanplot.
  • Stored channel measures in STUDY.changrp and component measures on the parent cluster with EEGLAB-style field names such as erpdata, specdata, erspdata, itcdata, erptimes, specfreqs, ersptimes, and erspfreqs.
  • Closeout fixes now preserve per-dataset component selections as row-aligned sets/comps, avoid corrupting STUDY when replaying std_*plot history, and add tests for those cases.

Phase 5c, STUDY clustering:

  • Added std_preclust and pop_preclust for building component clustering matrices from scalp maps, dipoles, and cached Phase 5b measures.
  • Added deterministic pop_clust plus std_createclust to write EEGLAB-shaped parent/child cluster structures.
  • Added pop_clustedit, std_clustplot, and cluster editing helpers for rename, merge, component move/reassignment, outlier movement, and outlier rejection.
  • Closeout fixes include child-cluster measure reads from parent-cluster caches and an EEGLAB-style mean-distance guard for outlier detection.

Phase 5d and 6c, integration hardening:

  • Added end-to-end multi-dataset STUDY workflow coverage over saved ICA datasets, STUDY creation, design editing, channel/component precompute, plotting, preclustering, clustering, cluster plotting, save/load, and console inspection.
  • Removed runtime dependence on the vendored EEGLAB checkout for compatibility helpers; runtime paths now use explicit EEGPREP_EEGLAB_ROOT or a sibling development checkout only for parity tooling.
  • Fixed loaded MATLAB-file edge cases including non-dict EEG["etc"] and NumPy epoch truthiness in STUDY trialinfo extraction.
  • Added final closeout review fixes for component measure selection, STUDY GUI replay, pop_loadstudy(load_datasets=False) history, pop_study(commands=...) replay, scikit-learn runtime dependency, and pop_savestudy(resavedatasets='on') dataset writes.

Phase 6a, help/admin/docs/menu inventory:

  • Added EEGPrep-owned packaged help resources and removed runtime fallback to the vendored EEGLAB tree or docstrings.
  • Added tests that implemented Help/menu actions have packaged resources and missing resources fail clearly.
  • Updated docs for GUI Help menus, admin/help surfaces, and STUDY workflows.

Phase 6b, public API, plugin management, and packaging:

  • Exposed completed GUI/session/console/admin/plugin/STUDY helpers through lazy eegprep.* public API exports without making import eegprep heavy.
  • Added a read-only bundled extension manager for in-repo plugins and wired File > Manage EEGPrep extensions into EEGPrepSession.PLUGINLIST.
  • Expanded package-data coverage for help resources, headplot assets, montages, ICLabel assets, and plugin metadata while keeping eegprep/eeglab/ out of packaged runtime data.
  • Added public API docs, interactive-console guidance, and runnable examples.

Verification run on the final epic branch before opening this PR:

  • uv run --no-sync ty check passed.
  • uv run --no-sync pytest tests/test_visual_parity.py tests/test_gui_pop_study.py tests/test_study_measures.py tests/test_study_clustering.py tests/test_phase4_plot_wrappers.py tests/test_file_menu_pop_functions.py tests/test_study_metadata.py -q passed: 132 passed, 30 subtests passed.
  • uv run --no-sync pytest tests/test_study_measures.py::test_component_precompute_preserves_per_dataset_component_pairs tests/test_study_metadata.py::test_pop_savestudy_resavedatasets_writes_loaded_dataset_files -q passed: 2 passed.
  • ./pre-commit.py --changed-from origin/develop passed.
  • Autonomous closeout review was run repeatedly. The last review findings were fixed in the final pushed commit: per-dataset component precompute no longer flattens datasetinfo.comps, and resavedatasets='on' now writes loaded dataset files instead of being silently ignored.

GUI visual evidence and user attachments:

Phase 6c final STUDY/main-window evidence:

phase6c-main-window-study-side-by-side.png
phase6c-study-menu-side-by-side.png
phase6c-pop-study-dialog-side-by-side.png
phase6c-pop-studydesign-dialog-side-by-side.png

Phase 5a original STUDY dialog evidence:

pop_study_dialog side-by-side
pop_studydesign_dialog side-by-side

Phase 5c clustering dialog evidence:

pop_preclust_dialog side-by-side
pop_clustedit_dialog side-by-side

Phase 5b/5c/6c EEGPrep-only captures where EEGLAB capture timed out or the UI is EEGPrep-owned:

phase6c-pop-precomp-dialog-eegprep-only.png
phase6c-pop-chanplot-dialog-eegprep-only.png
phase6c-pop-preclust-dialog-eegprep-only.png
phase6c-pop-clust-dialog-eegprep-only.png
phase6c-pop-clustedit-dialog-eegprep-only.png

Phase 6b plugin manager evidence:

eegprep-plugin-manager.png

Known visual-evidence caveat:

  • Some EEGLAB STUDY captures timed out in the MATLAB visual harness, so the PR includes EEGPrep-only user attachments for those dialogs and side-by-side evidence where EEGLAB capture succeeded. The artifacts remain user attachments and are not committed to the repository.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 CI checkout follow-up: the initial PR run failed before Ruff/ty executed because Actions recursively fetched EEGLAB's nested plugin submodules and upstream EEGLAB currently points at an unavailable EEG-BIDS commit. I pushed commit 349e674 to fetch only the top-level vendored EEGLAB reference in CI, matching EEGPrep's runtime contract that nested EEGLAB plugin checkouts are not required.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 CI follow-up: pushed c8a9891 to fix the remaining test failures. Python 3.10 now uses a tomllib/tomli fallback in the help packaging test, and the Windows STUDY history test now asserts the escaped Python literal form of the filepath so replayable console commands remain valid. The rerun is green across docs, pre-commit, Ruff/ty, Ubuntu 3.10/3.11/3.12, macOS 3.12, and Windows 3.12. I also checked the cancelled Claude review log: the "directory mismatch" message is an internal claude-code-action post-step bug after the review timed out/cancelled, not an EEGPrep checkout or test failure.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

@claude review this PR thoroughly

@claude

claude Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 7m 13s —— View job


Code review

I ran four parallel review agents over the 11468-line diff (134 files), then spot-validated the highest-priority findings against the working tree. Overall: layout, EEGLAB parity, runtime EEGLAB independence, lazy public API, help-resource coverage, and session/console sync look solid. Findings below are grouped by severity.

Scope hygiene (please address before merge)

  • .notes/implementation-notes.html (NEW, 268 lines) is committed despite .gitignore. .gitignore lines 4-5 are .notes/* / !.notes/.gitkeep; this HTML file is force-added against that rule. Implementation notes belong in the PR description, a tracking issue, or docs/source/, not a checked-in HTML dump. Recommend git rm .notes/implementation-notes.html.
  • .agents/skills/oc-autoreview-adapted/ (NEW, ~1230 lines) is out of scope for a STUDY closeout PR. SKILL.md, the 895-line scripts/autoreview, harness, and agents/openai.yaml are an entire autonomous-review tool. Per AGENTS.md "make the smallest change... no speculative configurability," split into a separate PR so the skill design can be reviewed on its own merits.

Correctness (verify or fix)

  • pop_savestudy(resavedatasets='on') mutates caller EEG dicts in place — src/eegprep/functions/studyfunc/pop_savestudy.py:107-109 writes eeg["filename"], eeg["filepath"], eeg["saved"] = "yes" directly on items from as_alleeg_list(ALLEEG) (which does list(ALLEEG) without deepcopy). Console callers will see their session ALLEEG silently rewritten. Either deepcopy before mutating, or document this is intended EEGLAB-parity behaviour. Same pattern in std_editset.py:108-109.
  • _normalize_one_spec silently drops measure when both keys are present — src/eegprep/functions/studyfunc/std_preclust.py:115: spec["measure"] = str(spec.pop("command", spec.get("measure", ""))).lower(). When a dict has both command and measure, command wins implicitly. EEGLAB cell specs sometimes carry both. Use explicit precedence: command = spec.pop("command", None); spec["measure"] = (command or spec.get("measure") or "").lower().
  • NumPy truthiness pitfall in std_makedesign — src/eegprep/functions/studyfunc/std_makedesign.py:158: if subjselect is None or subjselect == []: raises "truth value of an array is ambiguous" when subjselect is an ndarray. Reuse _empty_value(...) from _study_utils.py, which the rest of this module already uses.
  • pop_clustedit._clusters_from_list_selection silently discards explicit picks when "All" is selected — src/eegprep/functions/studyfunc/pop_clustedit.py:273: any presence of index 1 (the "All clusters" header) wipes the rest of the selection. That breaks rejectoutliers / merge when the user multi-selects "All" + a specific cluster (a plausible UX). Either fail with a clear message or expand "All" to the full cluster list.
  • pop_chanplot channel-mode dialog has no component selector but routes both modes through _plot_channel_measure — src/eegprep/functions/studyfunc/pop_chanplot.py:169-173. On a component-precomputed STUDY, clicking a measure button currently raises "channel measures have not been precomputed" instead of routing into the component branch. Add a mode switch or fail with a clearer error.
  • pop_chanplot shallow-copies STUDY then writes nested state — pop_chanplot.py:60-61: study = dict(STUDY); study["etc"] = {**(STUDY.get("etc") or {}), ...} leaves cluster, changrp, design as shared references. Safe today but brittle; either deepcopy or note the contract.
  • _is_study_selection requires datasetinfo — src/eegprep/functions/adminfunc/console.py:1203-1204. A freshly created STUDY (pre-ensure_study) lacks this key, so the console routes through the EEG path and never updates session.STUDY. Most pop_* paths go through ensure_study, so it's latent, but prefer detecting "design" in value or any canonical key.

Tests / packaging

  • tests/test_gui_pop_study.py will NOT receive the gui marker. tests/conftest.py:41-51 (GUI_FILE_SUFFIXES) is unchanged, and the file's test functions are test_pop_study_* (not test_gui_*), so neither the path rule nor the ::test_gui_ nodeid rule fires. The file runs unconditionally under -m "not gui". Add "tests/test_gui_pop_study.py" to GUI_FILE_SUFFIXES in tests/conftest.py.
  • tests/test_pop_select.py:365-369 is too loose for the new bounds check. assertRaises(Exception) will catch anything (including unrelated failures). Use assertRaisesRegex(ValueError, "Wrong channel range") and add an upper-bound case (nochannel=[EEG['nbchan']]).
  • Tautological tests violating AGENTS.md "no tests that only assert types, constants, or implementation details":
    • tests/test_package_exports.py:13-22 iterates eegprep._LAZY_EXPORTS and asserts that getattr(eegprep, name) is direct_import — checks the lazy mapping against itself.
    • tests/test_plugin_menu.py:16-24 pins a hard-coded plugin name list.
    • tests/test_study_measures.py:339-342 and tests/test_study_end_to_end.py:166-182 only assert action_kind(...) == "implemented" over hard-coded action lists.
    • tests/test_public_api_examples.py:33-62 asserts pyproject.toml literal entries against themselves.
    • tests/test_gui_pop_study.py:25-41 pins spec.size == (1080, 834) and other dialog-spec literals.
    • tests/test_study_clustering.py:355-377 asserts dialog control labels/flags rather than user-visible behaviour.
  • Untested helpers: src/eegprep/functions/studyfunc/_cluster_utils.py (289), _std_measureplot.py (226), _study_utils.py (418) — ~930 lines covered only transitively. Worth at least minimal direct tests for the distance/centroid math and the truthiness/normalisation helpers (where bug Fix mutable default argument and incorrect file loading order #3 above lives).
  • Coverage gaps in modified code paths worth noting: std_precomp recompute='off' caching path, std_readdata subject/group/condition filtering, pop_chanplot ersp/itc/topo plot modes, std_movecomp/std_moveoutlier/std_rejectoutliers/std_renameclust edge cases (last component out of cluster, duplicate names, etc.).

Docs / packaging nits

  • Duplicate autosummary entries in docs/source/api/index.rst:34, 65 — eegprep.gui and eegprep.eeglab are listed in both "Interactive GUI and Console" and "GUI and Session Entry Points" sections. Sphinx will warn. Pick one section.
  • scikit-learn for a single KMeans call — added as a runtime dep in pyproject.toml:38 (>=1.1,<1.8) for pop_clust.py:8. For deterministic Lloyd's on small precluster matrices a pure-numpy implementation (~30 lines) avoids the transitive footprint. Keep sklearn if you value the future option of MiniBatchKMeans/KMeans++, but it's flagged as heavyweight for one call site.

What looks good

  • New files live in correct EEGLAB-parity directories (functions/studyfunc/, functions/adminfunc/, etc.).
  • No runtime references to src/eegprep/eeglab/ in the new code — eeglabcompat.py:37-53 correctly gates EEGLAB-checkout access behind EEGPREP_EEGLAB_ROOT env / sibling-checkout discovery for parity tooling only.
  • All 11 new study pop_* functions have packaged Markdown help under src/eegprep/resources/help/.
  • src/eegprep/__init__.py lazy __getattr__ over _LAZY_EXPORTS keeps import eegprep light.
  • No TYPE_CHECKING guards, no ad-hoc hasattr(...) compat checks, no mocks on numerical transforms.
  • Session/console sync via EEGPrepSession.set_study(...) and WORKSPACE_NAMES is consistent; both directions exercised in test_console_workspace.py and test_study_end_to_end.py.
  • .github/workflows/test.yml:50, 100 submodule fix (submodules: true only) is correct and doesn't regress the MATLAB parity job.
  • uv.lock diff is minimal (sklearn only) — joblib/threadpoolctl already pinned.

Checklist

  • Load skill and gather PR context
  • Identify relevant CLAUDE.md/AGENTS.md files
  • Summarize PR scope and risk areas
  • Inspect PR diff and key files
  • Run 4 parallel review agents (compliance, correctness, tests, packaging/docs)
  • Validate top findings against working tree
  • Post final review
    • Branch: feature/study-standalone-completion

@arnodelorme
arnodelorme merged commit ddd43ae into develop Jun 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: STUDY and standalone EEGPrep integration parity

2 participants