Skip to content

[STUDY] Load EEGLAB MATLAB STUDY files - #653

Merged
suraj-ranganath merged 4 commits into
developfrom
cursor/study-mat-load-b663
Nov 18, 2026
Merged

suraj-ranganath merged 4 commits into
developfrom
cursor/study-mat-load-b663

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

pop_loadstudy reads EEGLAB MATLAB .study files, decodes uint16 characters as Latin-1, and rebases dataset paths after the study directory moves. EEGLAB pop_loadstudy.m line 182 (d0963be) calls std_checkfiles. That function returns immediately at std_checkfiles.m line 47, so the call does not inspect measures. A changrp.erpdata cell of lengths 2 and 5 stays a cell. eeg_getversion reports the installed package version. The STUDY fixture cluster went from 9 strict xfails to 6 passing and 3 remaining. No MATLAB reference run.

Part of #430

Open in Web Open in Cursor 

pop_loadstudy reads MATLAB .study files, decodes uint16 characters as Latin-1, and rebases dataset paths when the study directory has moved.

Co-authored-by: Suraj Ranganath <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 25s —— View job


Code review

  • Overall assessment: Needs changes. Reading .mat STUDY files, decoding text as Latin-1 and rebasing dataset paths all look right. One new call can break loading of real EEGLAB STUDY files, and the reference run this PR needs is missing.
  • Highest-risk area: pop_loadstudy running std_checkfiles on measure data kept from a .mat STUDY.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  1. pop_loadstudy.py:93: std_checkfiles(study, alleeg) can only fail; its result is never used.
    • std_checkfiles builds a report and changes nothing, so on success the call does nothing.
    • Its _measure_cache_report runs np.asarray(group[field], dtype=float) on changrp/cluster measure fields (std_checkfiles.py:43-46).
    • EEGLAB stores those fields as {cond x group} cells whose entries have different column counts. This PR keeps them after a .mat load (see the docstring), so a STUDY with precomputed measures can make the load fail with ValueError: inhomogeneous shape.
    • Fix: remove the call. Alternatively, log report["problems"] from return_report=True and make the measure check handle cells. Add a regression test with a ragged changrp.erpdata. Details in the inline comment.
  2. The MATLAB reference run is missing. The PR changes pop_loadstudy, a core user-facing loader, and the description says "MATLAB was not available for the reference suite." AGENTS.md › Testing requires one run of .github/workflows/eeglab-reference.yml, or a local --eeglab-backend=matlab run, on this branch before merge. Put its counts and commits in the PR body. Dispatch the workflow on cursor/study-mat-load-b663 before asking for approval.

Nits

  • tests/test_study_metadata.py:7-8 imports scipy private modules (scipy.io.matlab._mio5, _mio5_params) to write uint16 chars. That works today but may break on a SciPy upgrade. A small checked-in .study fixture saved by EEGLAB, or the existing EEGLAB sample STUDY fixture, would be sturdier.
  • tests/test_eeg_getversion.py: two assertions add nothing. result.number == numeric_version(__version__) rebuilds the expected value with the code under test, and version != "dev" just repeats version == __version__. The checks on numeric_version("11.3.2.4b"), "0.5.0" and "dev" are the useful part.

Test gaps

EEGLAB parity notes

  • I couldn't diff against pop_loadstudy.m, std_loadalleeg.m or eeg_getversion.m: the vendored src/eegprep/eeglab/ checkout isn't in this CI workspace. I checked against the described EEGLAB behavior instead:
    • The dataset search order (rebase from etc.oldfilepath, then beside the STUDY, then under sub1/sub2, then lowercase) matches what std_loadalleeg does.
    • Writing the found filename/filepath back into datasetinfo matches EEGLAB.
  • Keeping measure arrays on load, where EEGLAB clears them, is documented in the docstring, but no test locks it in. AGENTS.md asks for a test on every intentional difference from EEGLAB.

Checked: correctness of the .mat/JSON detection and the normalization helpers, candidate-path dedup, option_storedisk → loadmode="info", the xfail list updates, docs/help/changelog, and AGENTS.md compliance.

_warn_legacy_design(study)
alleeg = _load_datasets(study) if load_datasets else []
study, alleeg = std_checkset(study, alleeg)
std_checkfiles(study, alleeg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: the return value is thrown away, so this call has no effect. The only thing it can do is raise an error.

std_checkfiles only builds a report (check_datasetinfo and _measure_cache_report mutate nothing). Its _measure_cache_report runs np.asarray(group[field], dtype=float) on every changrp/cluster erpdata/specdata/erspdata/itcdata/topo. EEGLAB stores those as {cond x group} cell arrays whose cells have different column counts (subjects per condition). Your docstring says these measure arrays now "stay in place" after a .mat load, so a STUDY saved with precomputed measures reaches this call as a ragged list. NumPy then raises ValueError: inhomogeneous shape, and pop_loadstudy fails on a file EEGLAB loads without trouble.

See

def _measure_cache_report(study: dict[str, Any], dataset_count: int) -> dict[str, Any]:
problems = []
checked = []
for group_name in ("changrp", "cluster"):
for index, group in enumerate(study.get(group_name) or [], start=1):
if not isinstance(group, dict):
continue
for field in ("erpdata", "specdata", "erspdata", "itcdata", "topo", "pacdata"):
if field not in group:
continue
array = np.asarray(group[field], dtype=float)
checked.append({"group": group_name, "index": index, "field": field, "shape": list(array.shape)})
if array.size == 0:
problems.append(f"{group_name}[{index}].{field} is empty")
if dataset_count and array.ndim and group_name == "changrp" and array.shape[0] != dataset_count:
problems.append(f"{group_name}[{index}].{field} dataset axis does not match ALLEEG")
return {"checked": checked, "problems": problems}

Fix: remove the call. If you want EEGLAB's load-time warning, use ok, report = std_checkfiles(study, alleeg, return_report=True) and logger.warning the problems, and make _measure_cache_report handle cell-shaped measures. Either way, add a test that loads a .mat STUDY with a ragged changrp.erpdata cell.

cursoragent and others added 3 commits November 18, 2026 19:09
std_checkfiles was called for a discarded report and raised on cell arrays whose cells have different lengths.

Co-authored-by: Suraj Ranganath <[email protected]>
EEGLAB pop_loadstudy.m calls std_checkfiles. A cell whose arrays differ in length stays a cell, which is how MATLAB stores changrp.erpdata.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath merged commit dbc5516 into develop Nov 18, 2026
22 of 23 checks passed
cursor Bot pushed a commit that referenced this pull request Nov 18, 2026
Keep both changelog bullets. Drop the STUDY load xfails that #653 made
pass, and keep the three design-cell failures from that branch.

Co-authored-by: Suraj Ranganath <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 18, 2026
Keep the ASRCalibrationError changelog bullet, then the pop_loadstudy
bullet from #653, then the existing Unreleased notes.

Co-authored-by: Suraj Ranganath <[email protected]>
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.

2 participants