Skip to content

[STUDY] Add group-level depth helpers - #144

Merged
suraj-ranganath merged 2 commits into
feature/eeglab-core-parity-completionfrom
phase/6-study-depth
Jun 6, 2026
Merged

suraj-ranganath merged 2 commits into
feature/eeglab-core-parity-completionfrom
phase/6-study-depth

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Add standalone STUDY design, measure reader, consistency, clustering, and explicit LIMO limitation helpers for Phase 6 group workflows. Updates tests, help, docs, implementation notes, and parity matrix rows for the supported STUDY surface.

Fixes #137
Part of #131

@claude

claude Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 56s —— View job


Reviewing PR #144 — [STUDY] Add group-level depth helpers

  • Gather context (diff, CLAUDE.md/AGENTS.md, EEGLAB references)
  • Correctness & regression review
  • EEGLAB parity & data-structure review
  • Repo convention & CLAUDE.md compliance review
  • Test coverage review
  • Post consolidated review

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Phase 6 implementation specification

Problem
EEGPrep had a core STUDY skeleton but several Phase 6 rows remained as unimplemented or unverified: design and variable helpers, EEGLAB-named measure readers, file/session consistency helpers, deterministic clustering helpers, and LIMO behavior classification. The missing surface made real multi-dataset workflows harder to inspect from Python and console flows, and left external LIMO behavior ambiguous.

Approach
Added standalone STUDY helpers under src/eegprep/functions/studyfunc for design variables, matrix construction, imported group variables, design rebuilds, consistency checks, cached measure reading/writing, deterministic clustering, and explicit LIMO limitations. Extended std_readdata for ITC/topography/PAC cache behavior, range slicing, and subject filtering where the cache axis is a dataset axis. Exported public names from eegprep.init, updated help/docs/implementation notes, and marked Phase 6 matrix rows as implemented, partial, or external-dependency limitations.

Key code

  • std_addvarlevel assigns EEGLAB-like one/two variable levels and preserves numeric level indices as levelindex.
  • std_readpac raises unless an EEGPrep-owned pacdata cache exists, so external PAC/LIMO output is not faked.
  • pop_limo, pop_limoresults, std_limo*, and std_readfilelimo raise explicit NotImplementedError limitation messages.
  • robust_kmeans, optimal_kmeans, std_apcluster, std_centroid, and std_findoutlierclust provide deterministic in-package clustering helpers.

Tests
Focused tests cover multi-dataset design helpers, imported group variables, design matrices, measure readers and sidecar writes, consistency checks, deterministic clustering helpers, LIMO limitation behavior, and console STUDY sync. Clean branch verification also passed ruff check, ruff format check, ty check, parity matrix validation, PR-scope pre-commit, and EEGPREP_SKIP_MATLAB=1 pytest -m "not slow".

@suraj-ranganath

Copy link
Copy Markdown
Member Author

@claude review this

@claude

claude Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 4m 40s —— View job


Reviewing PR #144 — [STUDY] Add group-level depth helpers

  • Gather context (diff, CLAUDE.md/AGENTS.md, EEGLAB references)
  • Correctness & regression review
  • EEGLAB parity & data-structure review
  • Repo convention & CLAUDE.md compliance review
  • Test coverage review
  • Post consolidated review

Summary

Solid Phase 6 increment. The new helpers each live in their own studyfunc/*.py mirroring EEGLAB, parity-matrix rows are updated together with code + tests + docs + help, LIMO surface is explicit-limitation rather than faked, and the PAC reader correctly refuses to return data unless an EEGPrep-owned pacdata cache exists. Tests are well-scoped (138 passed locally, MATLAB-parity skip preserved). std_makedesign now wires through std_addvarlevel so the one/two level metadata gets set on the canonical create path — nice. Pre-commit on the diff scope is clean.

Below are the concrete review findings, ordered roughly by impact.

Correctness

  1. Dead loop in pop_addindepvar._factor_lists — src/eegprep/functions/studyfunc/pop_addindepvar.py:65-66

    for label in study.get("subject", []):
        _ = label

    Pure no-op; nothing is consumed or asserted. Remove it. Fix this →

  2. _subject_filter silently ignores the request when the cache axis is not dataset-major — src/eegprep/functions/studyfunc/std_readdata.py:338

    if data.ndim == 0 or data.shape[0] != len(datasetinfo):
        return data

    The implementation notes call this out as a tradeoff, but from the caller's perspective an explicit subject="S01" argument either filters or it doesn't — silently passing back the full array when the shape mismatch occurs (e.g., child cluster reads) is a quiet footgun, especially since you already explicitly skip the call for cluster_index > 1. Either raise a clear error ("subject filter requires a dataset-axis cache") or log it at warning level so the user knows the filter was a no-op.

  3. std_readpac accepts but ignores components — src/eegprep/functions/studyfunc/std_readdata.py:114-141
    _ = ALLEEG, components explicitly drops the components argument. If the caller asks for a subset, it silently returns the whole array. Either honor the argument (mirroring std_readtopo/std_readdata) or raise ValueError("std_readpac does not yet support component selection"). Right now the surface looks parametric but isn't.

  4. pop_listfactors accepts then silently drops several EEGLAB options — src/eegprep/functions/studyfunc/pop_listfactors.py:20-22

    options.pop("splitreg", "off")
    options.pop("contrast", "off")
    options.pop("interaction", "off")

    Calling pop_listfactors(study, splitreg="on") returns the same factors as splitreg="off". std_precomp logs ignored EEGLAB-only options at warning level — apply the same pattern here for consistency, or drop the kwargs from the accepted surface so a user gets a clear Unknown pop_listfactors option(s) error today rather than wrong results tomorrow.

  5. std_uniformfiles returns 1 for empty ALLEEG — src/eegprep/functions/studyfunc/std_uniformfiles.py:18-19
    With no loaded datasets the function reports "uniform". std_checkfiles then has nothing to flag, so a study with load_datasets="off" looks healthy when it really has no opinion. Returning 1 here is defensible if documented, but worth either confirming against EEGLAB's std_uniformfiles.m behavior or short-circuiting std_checkfiles to skip the "uniform" claim when datasets are empty.

Style / Simplification

  1. std_apcluster._assign_exemplars over-engineered remap — src/eegprep/functions/studyfunc/std_apcluster.py:87-88

    remap = {position: index + 1 for index, position in enumerate(range(len(exemplars)))}
    return np.asarray([remap[int(item)] for item in raw], dtype=int)

    remap[k] is always k + 1 for k in range(len(exemplars)), so the dict adds no information. Replace with return raw.astype(int) + 1. Fix this →

  2. Double deepcopy in pop_listfactors._designs — src/eegprep/functions/studyfunc/pop_listfactors.py:59-60
    std_addvarlevel already deepcopies the STUDY; the list comprehension then deepcopies each design again. Not incorrect, just wasteful on large designs. Drop the inner deepcopy (these designs are not mutated downstream — they're only inspected for level/vartype/value).

Repo Conventions / AGENTS.md

  1. Missing help markdown for new user-facing wrappers — src/eegprep/resources/help/
    AGENTS.md: "When adding a user-facing function or GUI dialog with a Help button, add or update the corresponding Markdown help resource in src/eegprep/resources/help/." pop_importgroupvar, pop_limo, and pop_limoresults have packaged help. pop_addindepvar and pop_listfactors are listed as user_facing_surface: ["api", "console", "gui", "study"] in the parity matrix but don't have help resources. If they're truly only programmatic (no Help button), update the parity-matrix surface accordingly; if they're console-facing, add pop_addindepvar.md and pop_listfactors.md.

Tests

Test coverage is appropriate for the new surface:

  • tests/test_study_metadata.py::test_design_variable_helpers_build_factors_and_matrices exercises std_addvarlevel, pop_listfactors, pop_addindepvar, std_builddesignmat.
  • tests/test_study_metadata.py::test_import_save_and_rebuild_independent_variables covers pop_importgroupvar + std_saveindvar + std_rebuilddesign + std_findgroupvars.
  • tests/test_study_measures.py::test_std_precomp_ersp_and_itc_store_frequency_time_axes exercises range/subject slicing through std_readitc.
  • tests/test_study_clustering.py::test_deterministic_clustering_helpers_return_stable_shapes covers all four clustering helpers and the outlier helper.
  • LIMO limitation is asserted in tests/test_study_end_to_end.py::test_limo_entry_points_report_standalone_limitation.

Suggested additional cases (small, optional):

  • std_readdata with subject= on a child cluster (the silently-skipped branch) — assert your chosen contract (raise / warn / passthrough) explicitly.
  • pop_listfactors(study, splitreg="on") once you decide whether to error, warn, or document the no-op.
  • std_findoutlierclust zero/one-row label edge cases to lock in the "skip when fewer than 2 rows" branch.

Verification

uv run pytest tests/test_study_metadata.py tests/test_study_measures.py \
  tests/test_study_clustering.py tests/test_study_end_to_end.py \
  tests/test_console_workspace.py -q
# 138 passed, 1 skipped (MATLAB engine unavailable)

./pre-commit.py --changed-from origin/feature/eeglab-core-parity-completion
# OK

No blocking issues. Items 1, 6 are pure cleanups; 2, 3, 4 are user-facing contract choices worth nailing down before merge so the surface stays consistent.

@suraj-ranganath
suraj-ranganath merged commit 213150d into feature/eeglab-core-parity-completion Jun 6, 2026
1 check failed
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.

1 participant