Repository navigation
[STUDY] Implement measure precompute workflows - #91
suraj-ranganath merged 3 commits into
Conversation
|
Claude finished @suraj-ranganath's task in 7m 2s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Inline suggestions posted on |
|
🤖 Problem Approach Key code Tests Verification Parity and GUI evidence Open risks |
| study.setdefault("etc", {}).setdefault("eegprep", {})["study_measures"] = { | ||
| "kind": kind, | ||
| "design": int(design), | ||
| "computed": computed, | ||
| "storage": "STUDY in-memory JSON-safe arrays", | ||
| "recompute": "on" if is_on(recompute) else "off", | ||
| } |
There was a problem hiding this comment.
Important — EEGLAB parity gap. design is validated and recorded here, but _channel_erp/_component_erp/_channel_spec/_channel_time_frequency all average over every trial in every dataset; nothing actually filters by the selected design's condition cells. EEGLAB's std_precomp computes condition-specific measure files keyed off the design. Either implement design-aware trial filtering, or call this out explicitly in pop_precomp_dialog_spec.known_differences and the STUDY user guide so EEGLAB users don't read these cached arrays as condition-specific.
Adding a regression test that pins per-condition expected values (or asserts the current "averaged across conditions" behavior with a code comment explaining why) would also lock in the contract for the next phase.
| ignored = {"interp", "savetrials", "rmicacomps", "rmclust", "cell", "erpim", "erpimparams"} | ||
| unsupported = sorted(key for key in options if key not in ignored) | ||
| if unsupported: | ||
| raise ValueError(f"Unknown std_precomp option(s): {', '.join(unsupported)}") |
There was a problem hiding this comment.
Nit. EEGLAB-only options (interp, savetrials, rmicacomps, rmclust, cell, erpim, erpimparams) are silently dropped. EEGLAB users porting scripts will not notice their flags had no effect. A one-line warning would make the gap visible without changing behavior:
ignored_present = sorted(key for key in options if key in ignored)
if ignored_present:
logger.warning("std_precomp: ignoring EEGLAB-only option(s): %s", ", ".join(ignored_present))| study = dict(STUDY) | ||
| study.setdefault("etc", {})["last_chanplot"] = last_selection |
There was a problem hiding this comment.
Nit — aliasing. study = dict(STUDY) is a shallow copy. When STUDY already has an etc dict, setdefault("etc", {}) returns the same dict reference held by the input, and ["last_chanplot"] = ... mutates STUDY["etc"] in place. If the intent is to leave the input untouched, copy etc explicitly:
| study = dict(STUDY) | |
| study.setdefault("etc", {})["last_chanplot"] = last_selection | |
| study = dict(STUDY) | |
| study["etc"] = {**(STUDY.get("etc") or {}), "last_chanplot": last_selection} |
| def _popup_index(value: Any, default: int) -> int: | ||
| try: | ||
| index = int(value) | ||
| except (TypeError, ValueError): | ||
| index = default | ||
| return max(1, min(index, len(MEASURE_OPTIONS))) |
There was a problem hiding this comment.
Nit. _popup_index clamps to len(MEASURE_OPTIONS) = 4 but it's also used for the mode popup at line 114, which only has 2 options (Channels|Components). Out-of-range mode values (3, 4) silently fall through to "channels" via the mode_index == 2 check rather than being clamped to a valid mode index. Either split the helper or accept an explicit maximum argument:
| def _popup_index(value: Any, default: int) -> int: | |
| try: | |
| index = int(value) | |
| except (TypeError, ValueError): | |
| index = default | |
| return max(1, min(index, len(MEASURE_OPTIONS))) | |
| def _popup_index(value: Any, default: int, maximum: int = len(MEASURE_OPTIONS)) -> int: | |
| try: | |
| index = int(value) | |
| except (TypeError, ValueError): | |
| index = default | |
| return max(1, min(index, maximum)) |
and call _popup_index(result.get("mode"), 1, maximum=2) at line 114.
| def _history_command(*, channels: Any, components: Any, measure: str, mode: str) -> str: | ||
| pieces = ["STUDY", "ALLEEG"] | ||
| kwargs = { | ||
| "channels": channels, | ||
| "components": components, | ||
| "measure": measure, | ||
| "mode": mode, | ||
| } | ||
| rendered = [python_literal(piece) if piece not in {"STUDY", "ALLEEG"} else piece for piece in pieces] | ||
| rendered.extend(f"{key}={python_literal(value)}" for key, value in kwargs.items() if value not in (None, [])) | ||
| return f"pop_chanplot({', '.join(rendered)})" |
There was a problem hiding this comment.
Nit. value not in (None, []) raises ValueError: The truth value of an array with more than one element is ambiguous. if a caller passes a numpy array for channels/components. The GUI flow normalizes to lists via .tolist() at line 116-117, so this is fine in practice, but the public API accepts Any for channels/components. Suggest coercing or using an explicit empty/None check:
def _is_empty_arg(value: Any) -> bool:
if value is None:
return True
if isinstance(value, np.ndarray):
return value.size == 0
if isinstance(value, (list, tuple)):
return len(value) == 0
return False
Add STUDY precompute, cached measure readers, and cached channel/component plotting so Phase 5b workflows work from API, GUI menus, and the console. Documents the measure storage contract and adds regression coverage for multi-dataset, component, cancel, history, and sample-data paths.
Closes #79