Repository navigation
Implement STUDY metadata and design workflow - #89
suraj-ranganath merged 3 commits into
Conversation
|
Claude finished @suraj-ranganath's task in 12m 21s —— View job Code review
Blocking
Important
Nits
Test gaps
EEGLAB parity notes
8 inline comments left on the changed lines for the items above. |
| @@ -690,8 +699,21 @@ def _study_action(self, action: str, variant: str, parent: Any | None) -> None: | |||
| from eegprep.functions.studyfunc.pop_savestudy import pop_savestudy | |||
|
|
|||
| study, command = pop_savestudy(self.session.STUDY, self.session.EEG, filename, savemode=variant or None) | |||
There was a problem hiding this comment.
Blocking — passes single EEG instead of ALLEEG to pop_savestudy.
self.session.EEG is one dataset; pop_savestudy runs std_checkset(STUDY, as_alleeg_list(EEG)) (pop_savestudy.py:41-42) and sync_datasetinfo rebuilds STUDY.datasetinfo from that single entry. A STUDY with N datasets is saved with only the currently selected row, and any per-row metadata (subject/session/run/comps) for the other rows is lost.
Fix: pass self.session.ALLEEG. The recorded history string pop_savestudy(STUDY, EEG, ...) (pop_savestudy.py:50-57) should also become STUDY = pop_savestudy(STUDY, ALLEEG, ...) so replay reproduces the same STUDY.
| study, command = pop_savestudy(self.session.STUDY, self.session.EEG, filename, savemode=variant or None) | |
| study, command = pop_savestudy(self.session.STUDY, self.session.ALLEEG, filename, savemode=variant or None) |
Ref:
eegprep/src/eegprep/functions/guifunc/menu_actions.py
Lines 699 to 705 in b8a7eb3
| def _load_datasets(study: dict[str, Any]) -> list[dict[str, Any]]: | ||
| datasets = [] | ||
| for info in study.get("datasetinfo") or []: | ||
| path = dataset_path(info) | ||
| if path is None: | ||
| continue | ||
| if not path.is_absolute() and not path.exists(): | ||
| path = Path(study.get("filepath") or "") / path | ||
| if path.exists(): | ||
| datasets.append(pop_loadset(str(path))) | ||
| return datasets |
There was a problem hiding this comment.
Blocking — partial load silently scrambles datasetinfo rows.
When a file at original position k is missing, _load_datasets continues and the loaded list compacts. pop_loadstudy then calls std_checkset(study, alleeg) (line 44), and sync_datasetinfo (_study_utils.py:96-101) overlays each loaded row with existing[index - 1] keyed by the new enumeration. If files 2 and 4 of 5 are missing, the metadata from saved rows 3 and 5 ends up overlaid onto loaded rows 2 and 3 — every field that lives only in STUDY.datasetinfo (notably session, run, comps, and any custom factor added via std_editset) is silently rebound to the wrong dataset. The user also gets no warning that any files were missing.
Fix: either preserve STUDY.datasetinfo row alignment when partial-loading (insert a placeholder / None for missing files, or short-circuit sync_datasetinfo when len(datasets) != len(existing)), or raise/log a clear error listing the missing paths so the user can rebase filepath before retrying. The current "drop silently" path is the dangerous case.
Ref:
eegprep/src/eegprep/functions/studyfunc/pop_loadstudy.py
Lines 60 to 74 in b8a7eb3
| else: | ||
| if not self.session.ALLEEG: | ||
| self._warn(parent, "Load at least one dataset before creating a study") | ||
| return | ||
| from eegprep.functions.studyfunc.pop_study import pop_study | ||
|
|
||
| study, alleeg, command = pop_study(None, self.session.ALLEEG) |
There was a problem hiding this comment.
Important — Create-new-STUDY menu path skips the dialog.
pop_study defaults use_gui to False when gui is None (pop_study.py:44), so this branch silently builds a STUDY from current ALLEEG with no chance for the user to set name/task/notes or per-dataset metadata. It also can't be cancelled. Mirror the pop_study:edit branch (menu_actions.py:736-744): pass gui=True and treat empty command as cancel.
| else: | |
| if not self.session.ALLEEG: | |
| self._warn(parent, "Load at least one dataset before creating a study") | |
| return | |
| from eegprep.functions.studyfunc.pop_study import pop_study | |
| study, alleeg, command = pop_study(None, self.session.ALLEEG) | |
| else: | |
| if not self.session.ALLEEG: | |
| self._warn(parent, "Load at least one dataset before creating a study") | |
| return | |
| from eegprep.functions.studyfunc.pop_study import pop_study | |
| study, alleeg, command = pop_study(None, self.session.ALLEEG, gui=True) | |
| if not command: | |
| return |
Ref:
eegprep/src/eegprep/functions/guifunc/menu_actions.py
Lines 743 to 753 in b8a7eb3
| gui = options.pop("gui", gui) | ||
| if designind is None: | ||
| designind = int(options.pop("designind", study.get("currentdesign") or 1)) | ||
| use_gui = is_on(gui) if gui is not None else not bool(options) |
There was a problem hiding this comment.
Important — opens GUI on non-interactive calls.
When a caller writes pop_studydesign(STUDY, ALLEEG, 2), designind is consumed positionally on line 25, options is empty, and not bool(options) is True, so this heuristic launches Qt despite no gui=True. This breaks headless scripting and contradicts the default gui: bool | None = None declared in the signature.
Default use_gui to False (consistent with pop_study.py:44); require explicit gui=True to open the dialog.
| use_gui = is_on(gui) if gui is not None else not bool(options) | |
| use_gui = is_on(gui) if gui is not None else False |
Ref:
eegprep/src/eegprep/functions/studyfunc/pop_studydesign.py
Lines 37 to 46 in b8a7eb3
| for index, info in enumerate((checked.get("datasetinfo") or [])[:10], start=1): | ||
| controls.extend( | ||
| ( | ||
| ControlSpec("text", str(index)), | ||
| ControlSpec("edit", tag=f"dataset_{index}_filename", value=_display_path(info), enabled=False), | ||
| ControlSpec("edit", tag=f"dataset_{index}_subject", value=str(info.get("subject") or "")), | ||
| ControlSpec( | ||
| "edit", tag=f"dataset_{index}_session", value=_display_optional_number(info.get("session")) | ||
| ), | ||
| ControlSpec("edit", tag=f"dataset_{index}_run", value=_display_optional_number(info.get("run"))), | ||
| ControlSpec("edit", tag=f"dataset_{index}_condition", value=str(info.get("condition") or "")), | ||
| ControlSpec("edit", tag=f"dataset_{index}_group", value=str(info.get("group") or "")), | ||
| ) | ||
| ) | ||
| controls.append( | ||
| ControlSpec( | ||
| "text", | ||
| "Important note: Removed datasets will not be saved before being deleted from EEGPrep memory", | ||
| ) | ||
| ) | ||
| dataset_row_geometry = (0.22, 2.6, 0.9, 0.7, 0.55, 1.3, 0.9) | ||
| geometry = [(1,), (1.2, 5), (1.2, 5), (1.2, 5), dataset_row_geometry] | ||
| geometry.extend(dataset_row_geometry for _info in (checked.get("datasetinfo") or [])[:10]) |
There was a problem hiding this comment.
Important — dialog hides datasets beyond row 10.
Both the controls loop (line 113) and the geometry list (line 135) slice [:10]. For a STUDY with >10 datasets, rows 11..N are not rendered and not editable from the GUI; _dataset_row_commands iterates the full ALLEEG so rows beyond 10 keep their stale values, but the user has no way to fix them. EEGLAB's pop_study shows all rows. The known_differences tuple (lines 147-149) doesn't mention this cap, so the visual_parity capture is also misleading.
Fix: drop the [:10] slices and let the dialog scroll, or — at minimum — surface a "+N rows hidden" notice and call it out in known_differences. If the cap stays, document it in src/eegprep/resources/help/pop_study.md as well.
Ref:
eegprep/src/eegprep/functions/studyfunc/pop_study.py
Lines 111 to 150 in b8a7eb3
| from eegprep.functions.studyfunc.pop_loadstudy import pop_loadstudy | ||
| from eegprep.functions.studyfunc.pop_savestudy import pop_savestudy | ||
| from eegprep.functions.studyfunc.pop_study import pop_study | ||
| from eegprep.functions.studyfunc.pop_studydesign import pop_studydesign | ||
| from eegprep.functions.studyfunc.pop_studyerp import pop_studyerp | ||
| from eegprep.functions.studyfunc.pop_studywizard import pop_studywizard | ||
| from eegprep.functions.studyfunc.std_checkset import std_checkdatasetinfo, std_checkset | ||
| from eegprep.functions.studyfunc.std_editset import std_editset | ||
| from eegprep.functions.studyfunc.std_makedesign import std_makedesign | ||
| from eegprep.functions.studyfunc.std_selectdesign import std_selectdesign | ||
|
|
||
| __all__ = [ | ||
| "pop_loadstudy", | ||
| "pop_savestudy", | ||
| "pop_study", | ||
| "pop_studydesign", | ||
| "pop_studyerp", | ||
| "pop_studywizard", | ||
| "std_checkdatasetinfo", | ||
| "std_checkset", | ||
| "std_editset", | ||
| "std_makedesign", | ||
| "std_selectdesign", | ||
| ] |
There was a problem hiding this comment.
Important — inconsistent with sibling subpackage __init__.py files.
popfunc/__init__.py, adminfunc/__init__.py, sigprocfunc/__init__.py, and guifunc/__init__.py are all docstring-only. The eager imports here pull in numpy (via _study_utils) and Qt (via inputgui through pop_study/pop_studydesign) on any from eegprep.functions.studyfunc import ..., and they force the local-import workaround at std_checkset.py:22 to break the cycle this __init__.py introduces.
src/eegprep/__init__.py already re-exports the public STUDY entry points, so no caller depends on eegprep.functions.studyfunc.pop_* being preloaded. Make this file docstring-only like its siblings.
| from eegprep.functions.studyfunc.pop_loadstudy import pop_loadstudy | |
| from eegprep.functions.studyfunc.pop_savestudy import pop_savestudy | |
| from eegprep.functions.studyfunc.pop_study import pop_study | |
| from eegprep.functions.studyfunc.pop_studydesign import pop_studydesign | |
| from eegprep.functions.studyfunc.pop_studyerp import pop_studyerp | |
| from eegprep.functions.studyfunc.pop_studywizard import pop_studywizard | |
| from eegprep.functions.studyfunc.std_checkset import std_checkdatasetinfo, std_checkset | |
| from eegprep.functions.studyfunc.std_editset import std_editset | |
| from eegprep.functions.studyfunc.std_makedesign import std_makedesign | |
| from eegprep.functions.studyfunc.std_selectdesign import std_selectdesign | |
| __all__ = [ | |
| "pop_loadstudy", | |
| "pop_savestudy", | |
| "pop_study", | |
| "pop_studydesign", | |
| "pop_studyerp", | |
| "pop_studywizard", | |
| "std_checkdatasetinfo", | |
| "std_checkset", | |
| "std_editset", | |
| "std_makedesign", | |
| "std_selectdesign", | |
| ] | |
| """EEGLAB-style STUDY helper functions.""" |
Ref:
eegprep/src/eegprep/functions/studyfunc/__init__.py
Lines 1 to 26 in b8a7eb3
| *args: Any, | ||
| filepath: str | Path | None = None, | ||
| load_datasets: bool = True, | ||
| return_com: bool = False, |
There was a problem hiding this comment.
Important — return_com parameter is dead.
Declared here but never read; the function unconditionally returns (study, alleeg, command) at line 52. Same lying signature appears in pop_savestudy.py:22, pop_studyerp.py:13, pop_studywizard.py:15. A caller writing pop_savestudy(STUDY) expecting STUDY per the declared default gets a 2-tuple instead.
Either branch on return_com (matching std_editset.py / pop_reref.py) and return just the primary object when False, or drop the parameter from these four signatures.
Ref:
eegprep/src/eegprep/functions/studyfunc/pop_loadstudy.py
Lines 15 to 52 in b8a7eb3
| options: str | None = None, | ||
| *, | ||
| return_com: bool = False, | ||
| ) -> Any: | ||
| """Normalize a STUDY dict and refresh dataset/design consistency metadata.""" | ||
| _ = options |
There was a problem hiding this comment.
Nit — options parameter is dead.
Accepted and immediately discarded with _ = options. The console wrapper exposes this surface (callers see std_checkset(STUDY, ALLEEG, options=...) work without effect). Either wire it through (mirror the corresponding EEGLAB options arg) or drop it from the signature.
Ref:
eegprep/src/eegprep/functions/studyfunc/std_checkset.py
Lines 10 to 20 in b8a7eb3


Summary
Verification
Closes #65