Repository navigation
Stream 10: Export and BIDS - #562
Conversation
File export and BIDS tools now follow the pinned EEGLAB dialogs and file layouts: decimal-place text export, save -ascii ICA weights, event tables, EDF/BDF length and annotations, value-column BIDS import, and the required BIDS sidecars. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
Windows history was storing backslashes, so the command no longer matched the derivatives/eeglab path checked on every platform. Co-authored-by: Suraj Ranganath <[email protected]>
Electrodes and coordsystem files drop task- and desc-. Export and import edit fields keep their dialog defaults. Subject codes unwrap a one-element list, and validate_bids runs bids-validator when it is installed. Co-authored-by: Suraj Ranganath <[email protected]>
The expevents, event-import, and EDF checks were sending list-of-dict events and chanlocs, which MATLAB reads as cells, and an EEG missing setname. The fixtures now use structured arrays and the fields eeg_checkset reads, including setname and struct chaninfo and etc. Co-authored-by: Suraj Ranganath <[email protected]>
EEGPrep keeps every sample. The MATLAB file is checked against the header record length, the shared prefix uses the file quantum, and the padded tail is the physical minimum. Co-authored-by: Suraj Ranganath <[email protected]>
There was a problem hiding this comment.
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 finished @suraj-ranganath's task in 37s —— View job Reviewing PR #562
|
|
Claude finished @suraj-ranganath's task in 26s —— View job Reviewing PR #562
|
Keep both changelog entries after #558 and #563. Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
|
Claude finished @suraj-ranganath's task in 2m 7s —— View job Code review
Blocking
Important
NitsNone. Test gaps
EEGLAB parity notes
Inline comments are posted on the three findings. |
| run_counts: dict[str, int] = {} | ||
| subjects: list[str] = [] | ||
| for index, eeg in enumerate(datasets, start=1): | ||
| subject_label = f"{index:02d}" if createids else str(subject).removeprefix("sub-") |
There was a problem hiding this comment.
Blocking: study export puts every dataset under one subject.
File > Export > BIDS calls pop_exportbids(datasets, gui=True, require_study=True, study=...) without subject, so subject_label is "01" for every dataset. A study with subjects S01–S10 is written as sub-01/eeg/sub-01_task-X_run-01..10_eeg.set. participants.tsv gets only one row, because subjects holds unique labels while zip(datasets, subjects) at L255 pairs them by position.
EEGLAB groups files by EEG.subject, falling back to STUDY.datasetinfo.subject, and errors when both are empty (pop_exportbids.m, "get subjects and sessions" block). It also takes session and run from EEG.session and EEG.run. With createids=True this code goes the other way and gives each dataset its own new ID, which splits one subject's sessions across several fake subjects.
Fix: when exporting a study (or whenever eeg["subject"] is set), derive the label per dataset from eeg["subject"] or study["datasetinfo"][i]["subject"]. Unwrap it with _subject_text, as bids_tools does. Map createids over the unique subjects, and build participants.tsv from one row per unique subject. Add a test that exports two datasets with subject "S01" and "S02" and asserts sub-S01/ and sub-S02/ exist, with two participants rows.
| if chosen: | ||
| options["recordings"] = chosen | ||
| if result.get("bidssubjects"): | ||
| subjects = _split_list(result.get("bidssubjectsstr")) |
There was a problem hiding this comment.
Important: "participant indices" are used as subject labels.
The checkbox says Import only the following participant indices, and EEGLAB treats the entry as numeric indices into participants.tsv. It runs str2double(res.bidssubjectsstr) (pop_importbids.m:163), then opt.subjects = opt.subjects+1 (:281). Here the raw strings go to bids_list_eeg_files(subjects=...) as BIDS labels. On a dataset with sub-001 … sub-010, typing 1 2 matches no files, and the import fails with "no supported EEG files found".
Fix: parse the entries as 1-based integers and map them through the sorted subject list (participants.tsv order, or sub-* folder order when that file is missing) to labels before filtering. Also emit numeric 'subjects', [1 2] in the history command. Add a test using the existing scanned-selector fixture with subjects 001/002 and bidssubjectsstr="2".
| (root / "CHANGES").write_text(str(changes).rstrip() + "\n", encoding="utf-8") | ||
| subjects = _write_recordings(root, datasets, subject=subject, task=task, createids=createids, task_info=task_info) | ||
| _write_participants(root / "participants.tsv", datasets, subjects) | ||
| command = f"LASTCOM = pop_exportbids(EEG, {format_history_value(root)});" |
There was a problem hiding this comment.
Important: the GUI export's history command does not reproduce the export.
After the study wizard, the command recorded is always LASTCOM = pop_exportbids(EEG, '<folder>');. It leaves out the task name, licence, CHANGES and createids, and it names EEG rather than the study datasets. Replaying it from eegprep-console exports only the current dataset, with task='eeg'. EEGLAB returns an empty comOut for the GUI path because of this same problem (the history block at the end of pop_exportbids.m is commented out).
Fix: either pass the dialog-chosen task, license, changes and createids into the command, with the dataset list (ALLEEG), or return "" from the GUI path, as EEGLAB does. The second option means menu_actions skips history (it already returns early on an empty command).
Study export reads EEG.subject, then STUDY.datasetinfo, and writes one participants row per subject. Import participant indices are 1-based. The export dialog history includes task, license, changes, and createids. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 7s —— View job Code review (re-review of
|
| indices = _participant_indices(text) | ||
| labels = _indexed_participants(source) | ||
| _check_participant_indices(indices, labels) | ||
| options["subjects"] = indices |
There was a problem hiding this comment.
Important: the recorded 'subjects', [1 2] imports different subjects when replayed.
eegprep/src/eegprep/plugins/EEG_BIDS/pop_importbids.py
Lines 212 to 218 in 7ff0dc0
In the dialog, these numbers are 1-based indices into participants.tsv. The filter actually uses subject_labels. The history command at L440-L442 records only the numeric subjects. When that command is replayed, subjects=[1, 2] falls through _list_filters (L354) to bids_list_eeg_files. That function treats integer subject queries as 0-based indices into the sorted subject labels:
eegprep/src/eegprep/plugins/EEG_BIDS/bids_list_eeg_files.py
Lines 95 to 101 in 7ff0dc0
With sub-001/sub-002:
- The dialog with
2loads002and records'subjects', [2]. Replaying it drops the out-of-range index 2, filters to nothing, and raises "no supported EEG files found". - The dialog with
1 2loads both subjects. Replaying it loads only002.
The order can differ too. The dialog uses participants.tsv order, while the replay sorts the labels.
Fix: make the command-line subjects= option resolve integers the same way the dialog does. In _list_filters, when kwargs["subjects"] holds ints, map them through _indexed_participants(source) with _check_participant_indices, as _import_dialog does. Then the recorded [1 2] replays the same import and matches EEGLAB's 'subjects' (pop_importbids.m:281). Extend test_import_dialog_participant_indices_are_one_based to replay command and check that it loads the same subjects.
Dialog history and pop_importbids(subjects=[1, 2]) both use 1-based participant positions, so replaying the command imports the same subjects. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 17s —— View job Code review (re-review of
|
| call = f"pop_importbids({', '.join(parts)})" | ||
| if return_study: | ||
| return f"[STUDY, ALLEEG] = {call};" |
There was a problem hiding this comment.
Important: the File > Import > BIDS history command does not give back a STUDY when replayed.
eegprep/src/eegprep/plugins/EEG_BIDS/pop_importbids.py
Lines 472 to 476 in d9c1eb4
menu_actions._import_dataset calls this with return_study=True and echoes [STUDY, ALLEEG] = pop_importbids('<bids>', ...) to eegprep-console. _console_python_command turns that into STUDY, ALLEEG = pop_importbids(...), and that call has no return_study. So the function returns the plain EEG list (or a single dict) instead of (study, datasets):
- With 2 datasets,
STUDYbecomes the first EEG dict andALLEEGthe second. Nothing raises. - With 3 or more datasets, the unpack raises
ValueError. - With 1 dataset, Python unpacks the dict's keys.
This is the GUI-to-console replay path that AGENTS.md asks to keep seamless.
Fix: put something in the recorded command that brings back the study return when the console replays it. One way is to emit a 'return_study' pair that the keywordizer turns into return_study=True. Another is to make the two-output form the default for folder imports, which is what EEGLAB pop_importbids always returns. Then add a replay check next to the return_study=True test at tests/test_stream10_export_bids.py:384. That test checks only the command prefix today.
| parts.extend([format_history_value("studyName"), format_history_value(dialog["studyName"])]) | ||
| if dialog.get("outputdir"): | ||
| parts.extend([format_history_value("outputdir"), format_history_value(Path(dialog["outputdir"]))]) | ||
| for key in ("bidstask", "sessions", "runs", "subjects"): |
There was a problem hiding this comment.
Important: the recordings choice from the dialog is not in the history command.
_import_dialog sets options["recordings"], and _list_filters uses it to filter, but this loop leaves out recordings. On a multi-device dataset, replaying the command imports every recording, not just the ones chosen in the dialog. That is the same replay mismatch as the subject-index fix in d9c1eb4.
| for key in ("bidstask", "sessions", "runs", "subjects"): | |
| for key in ("bidstask", "sessions", "runs", "recordings", "subjects"): |
The dialog history now records return_study on and the selected recordings, so running that command again rebuilds the same STUDY and ALLEEG. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 37s —— View job Code review (re-review of
|
|
Review follow-up at e2ba7b6. Fixed (all review rounds):
Process points:
CI is green on Ubuntu 3.12/3.13, macOS and Windows. |

Match File > Export and the BIDS tools to pinned EEGLAB
8ac485f654d6bbb1a6acb8dc9ef3f2eaf3d409ba. The MATLAB reference suite in this repo is pinned to EEGLABd0963be9d81acc5b66e84f8d3d7c89e3ce127cc4and eeglab_testsfec88f9ffe7c225eb1de8924db8b6a3e0d53a4d9. Those pins were not changed.Two files outside this stream were edited, and only for the dialogs this stream opens.
menu_actions._import_datasetis owned by stream 9: the BIDS branch now callspop_importbids(..., gui=True, return_study=True)and stores the in-memory study.qt._select_fileis owned by stream 2:mode="directory"usesQFileDialog.getExistingDirectoryso the import and export browse buttons can pick a folder.tests/test_tutorial_eeglab_tests.pynow selects subjectsS01andS02because those datasets already setEEG.subject, and that field wins over thesubject=argument.pop_exportbids(EEG, folder)still writes one dataset from memory. A study export takes each subject fromEEG.subject, thenSTUDY.datasetinfo, and raises when both are empty.createidsnumbers the unique subjectssub-001,sub-002, andparticipants.tsvhas one row per subject. The export dialog records a replayable command with the dataset list, task, license, changes, and createids. EEGLAB leaves that command empty (pop_exportbids.mlines 247-252). The import field "Import only the following participant indices" takes 1-based indices and records'subjects', [1 2]. Both that replayed command andpop_importbids(..., subjects=[1, 2])resolve those indices to participant labels before listing files. A folder import records[STUDY, ALLEEG] = pop_importbids(...)withreturn_studyon, plus the selected recordings, task, sessions, and runs. Replaying that command rebuilds the same study. A direct call still returns the datasets unlessreturn_study=True.validate_bidsdoes not writeeegprep_bids_validation.json.MATLAB was not run here. These five checks stay deselected unless
--eeglab-backend=matlabis passed:uv run --no-sync pytest tests/test_stream10_export_bids.py -k test_reference_ --eeglab-backend=matlabtest_reference_pop_export_decimal_places—%.7ftext equalspop_export.m:179.test_reference_pop_expica_save_ascii—f"{v:16.7e}"equalssave -ascii(pop_expica.m:79). MATLAB argument order is whichica, then filename (pop_expica.m:81). Confirm the field width is 16, not the audit's 15.test_reference_pop_expevents_table— Pythonurevent0 and MATLABurevent1 both write1.000000(eeg_eventtable.m:123-159). Events are a NumPy structured array, because a list of dicts arrives as a cell andfieldnamesfails (eeg_eventtable.m:95).test_reference_bids_importeventfile_uses_value— skips ifbids_importeventfileis missing. Expects stimulus/response from the value column (bids_importeventfile.m:14). The EEG includessetnameand the other fieldseeg_checksetreads atd0963be9(eeg_checkset.m:687,:769,:1090,:1155,:1297), withchaninfoandetcas structs.test_reference_pop_writeeeg_edf_length— skips if Biosigsopenis missing (pop_writeeeg.m:49). EEGPrep keeps 2112 samples. The EEGLAB file length ispntsrounded up tosamples_in_datarecordfrom the header (writeeeg.m:139). The shared prefix matches within the EDF quantum, and the padded tail is the physical minimum.test_pop_writeeeg_edf_record_duration_at_256_hzis a Python unit test, not a MATLAB reference test. It writes 1000 samples at 256 Hz throughpop_writeeegand checks the record duration and sample count on read-back.The core
.github/workflows/eeglab-reference.ymlrun was not started. Hands-on side-by-side GUI screenshots are still a pre-merge step.pop_export,pop_writeeeg, andpop_exportbidsopen their EEGLAB dialogs.pop_expicaandpop_expeventsstay file pickers.subjectrendered assub-['001'].sub-.sub-001/sub-002for a list and an ndarray.plotrad/shrinkwere None, so save failed, and import never built a study.derivatives/eeglab.LASTCOM. EEGPrep keeps every sample. EEGLABwriteeeg.m:139still uses a one-second record and Biosig fills the tail with the digital minimum.pntsrounded up to its header record length; the shared prefix matches within that quantum and the tail is the physical minimum. Skips without Biosig.test_pop_writeeeg_edf_record_duration_at_256_hzchecks 1000 samples at 256 Hz.%.7g, ICA weights were tab-separated, events had no number column.%.Nf, concatenated%16.7e, andeeg_eventtablecolumns.1.0, and validation reported 0 errors. A study export wrote every dataset assub-01and one participants row. The dialog history could not be replayed.*_eeg.json,*_electrodes.tsv, and*_coordsystem.json. Each dataset usesEEG.subject, thenSTUDY.datasetinfosubject.createidsassigns onesub-001-style id per subject, andparticipants.tsvhas one row per subject. The dialog command includes the dataset list, task, license, changes, and createids.sub-S01/sub-S02, one anonymized id for two sessions, empty-subject error, and a console replay that matches the output tree.trial_typeand had no options dialog. The participant field treated2as a subject label. A folder history omittedreturn_studyand the recordings filter, so a replay unpacked the datasets instead of the study and imported every recording.value. Participant indices are 1-based intoparticipants.tsvorder, or sortedsub-*folders when that file is missing, and are mapped to labels before filtering. History records'subjects', [1 2],'recordings', and'return_study', 'on'on[STUDY, ALLEEG] = pop_importbids(...).bidssubjectsstr='2', history replay of[2]and[1 2], a 2-subject study replay, a recordings-filtered replay, and non-numeric / out-of-range errors.precision=7wrote 7 significant digits, and an empty edit field fell through to 7 instead of the dialog default 4.%.Nfdecimal places. The default4and1E-3are the editvalue, so Ok with untouched fields writes 4 decimal places.1.2346is written and1.2345679is not.Refs #555