Repository navigation
Stream 9: Importers and dataset files (F10, F15, F18–F23, F26, F34, F119) - #575
Conversation
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 3m 4s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Checked: Cancel/return-com paths in |
| def _sidecar_path(datfile: str, file_path: Path) -> Path: | ||
| path = Path(datfile) | ||
| if path.is_absolute(): | ||
| return path | ||
| return file_path.parent / path.name | ||
| path = Path(datfile.replace("\\", "/")) | ||
| candidate = path if path.is_absolute() else file_path.parent / path | ||
| if PureWindowsPath(datfile).drive or candidate.resolve().parent != file_path.parent.resolve(): | ||
| raise ValueError( | ||
| f"pop_loadset: sample reference {datfile!r} leaves the dataset directory. " | ||
| "Keep the .set and .fdt together and use the companion filename in the header." | ||
| ) | ||
| return candidate |
There was a problem hiding this comment.
Important: .set files from DataLad or git-annex datasets no longer load
candidate.resolve() follows the .fdt symlink. In a DataLad or git-annex checkout, which is how OpenNeuro EEGLAB-format datasets are usually fetched, every annexed file is a symlink into <repo>/.git/annex/objects/.... The resolved parent therefore never equals file_path.parent.resolve(), so pop_loadset (and pop_load_frombids through it) raises leaves the dataset directory on a normal OpenNeuro download. pop_loadbv._referenced_file has the same problem with annexed .eeg and .vmrk files (pop_loadbv.py#L636-L647).
#561 is about the header string pointing elsewhere (.., a subdirectory, an absolute path). You can enforce that by checking the reference string, without following symlinks:
name = datfile.replace("\\", "/")
if PureWindowsPath(datfile).drive or Path(name).name != name:
raise ValueError(...)
return file_path.parent / nameIf you also want to block hostile symlinks, decide that explicitly and document it. Rejecting every symlink target breaks the most common way researchers get public EEG data. Whichever you choose, update test_561_* (the symlink cases at tests/test_stream9_dataset_files.py:79,92) and the "including symlink targets" sentence in pop_loadbv.md.
There was a problem hiding this comment.
Fixed. Companion checks now validate the header string (bare filename only). Same-directory DataLad/git-annex symlinks are allowed; .. / absolute / drive / separator references still raise. Tests updated accordingly.
| try: | ||
| import_module("defusedxml") | ||
| except ImportError as exc: | ||
| raise ImportError( | ||
| f'{feature}: MFF XML support is missing. Install it with pip install "eegprep[mne]".' | ||
| ) from exc |
There was a problem hiding this comment.
Nit: this duplicates an existing helper
eegprep.extras.import_optional_dependency already builds the "install eegprep[<extra>]" error from OPTIONAL_LIBRARIES (extras.py#L13-L19). AGENTS.md says: "Before writing any utility, helper … search for existing implementations" and lists "Parallel implementations of existing helpers" as a failure pattern.
Suggested fix: add "defusedxml": "mne" to OPTIONAL_LIBRARIES, replace this block with import_optional_dependency("defusedxml", feature=feature), and drop the importlib.import_module import.
There was a problem hiding this comment.
Fixed. Added "defusedxml": "mne" to OPTIONAL_LIBRARIES and switched _reader_for_suffix to import_optional_dependency.
| except (ValueError, OSError, TypeError) as exc: | ||
| raise ValueError( | ||
| f"pop_loadset: {file_path!r} is not a valid MATLAB .set dataset (MAT file). " | ||
| "Re-export the dataset from its source or restore an intact copy." | ||
| ) from exc |
There was a problem hiding this comment.
Nit: decoder bugs get reported as corrupt files
This try covers both opening the file and the whole new _read_set_h5 / dataset_from_mat decode. Any TypeError or ValueError from a decoding gap, such as a v7.3 field shape _read_value doesn't handle yet, reaches the user as "is not a valid MATLAB .set dataset … Re-export the dataset". The file is fine in that case, so the advice is wrong. AGENTS.md lists "Over-protective try/except blocks" as a failure pattern.
Suggested fix: wrap only the open/parse step. For example, catch OSError from h5py.File and scipy.io.matlab.MatReadError/ValueError from loadmat, and let decoding errors propagate.
There was a problem hiding this comment.
Fixed. Open/parse failures stay as the corrupt-file message; decoder TypeError/ValueError propagate.
…decoder errors - Allow same-directory companion symlinks (DataLad/git-annex); reject path/drive references in the header string - Use import_optional_dependency for defusedxml - Narrow pop_loadset open/parse exception handling so decoder errors propagate
Claude review follow-up (head
|
| Finding | eegprep | EEGLAB |
|---|---|---|
| F21 / F10 ASCII options | Full importdata dialog (srate, pnts, xmin, nbchan, ref, ICA, …) — screenshots/pr575_F21_ascii_opts_eegprep_*.png |
Matching dialog — screenshots/pr575_F21_ascii_opts_eeglab_*.png |
| F19 event import options | Fields / append / headerlines / timeunit / align — pr575_F19_importevent_opts_eegprep_*.png |
Audit reference pr575_F19_importevent_opts_eeglab_audit.png |
| F20 channel events | Edge / transition / delete options — pr575_F20_chanevent_opts_eegprep_*.png |
Audit reference pr575_F20_chanevent_opts_eeglab_audit.png |
| F15 HDF5 load | Labels FPz,EOG1,…; event type square; 32×30504 — pr575_F15_hdf5_loaded_eegprep_*.png |
(MATLAB suite) |
| F26 Save as | noext → noext.set+.fdt; two-file preserved (API) |
— |
| F34 errors | Helpful corrupt / missing-.fdt messages with function name + fix |
— |
F18 MFF folder picker and F119 Neuroscan covered by Qt/function tests; MFF/CNT/.EEG EEGLAB comparisons that need non-pinned plugins (mffmatlabio / neuroscanio / Fileio) are labelled as such.
Intentional differences
- F119: keep all Neuroscan sweeps including rejected (documented).
- F23 / pinned plugins: eegprep imports without installing neuroscanio/Biosig/bva-io.
- pop_load_frombids leaves None in chanlocs fields; pop_saveset raises TypeError on them #538: Stream 10.
Retriggering Claude on this head. Not merging — needs Suraj's explicit squash-merge approval.
|
Claude finished @suraj-ranganath's task in 2m 16s —— View job Code review (re-review at
|
| elif suffix == ".eeg": | ||
| eeg = _read_neuroscan_epochs(path, **options) |
There was a problem hiding this comment.
Important: BrainVision .eeg files are now sent to the Neuroscan reader
On develop, pop_fileio("x.eeg") used mne.io.read_raw_brainvision. This branch removes that path and sends every .eeg file to _read_neuroscan_epochs. BrainVision recordings are almost always saved as x.vhdr + x.eeg + x.vmrk, so a user who picks the .eeg file now gets a Neuroscan header error, or a wrongly shaped dataset if the bytes happen to parse. The error doesn't mention BrainVision or say which file to choose. This can happen from the GUI: the generic File-IO picker lists *.eeg (menu_actions.py#L651-L653) and then calls pop_fileio (L620-L623).
EEGLAB's File-IO (FieldTrip ft_filetype) has the same ambiguity. It reads .eeg as brainvision_eeg when a .vhdr with the same name sits next to it, and as ns_eeg otherwise.
Suggested fix: before the Neuroscan branch, check for a sibling header. pop_loadbv already maps .eeg to .vhdr in _header_path:
elif suffix == ".eeg" and blockrange is None and path.with_suffix(".vhdr").is_file():
eeg = pop_loadbv(path, srange=samples, chans=channels)
channels = None
samples = None
elif suffix == ".eeg":
eeg = _read_neuroscan_epochs(path, **options)Add a test that writes a binary BrainVision triplet (_write_binary_brainvision already exists in tests/test_stream9_dataset_files.py), calls pop_fileio on the .eeg file, and checks the data. Also mention the sibling-.vhdr rule in pop_fileio.md.
There was a problem hiding this comment.
Fixed. .eeg/.EEG now use pop_loadbv when a sibling .vhdr/.ahdr exists (FieldTrip ft_filetype parity) and the Neuroscan epoch reader otherwise. Regression tests cover both paths.
Route .eeg/.EEG through pop_loadbv when a sibling .vhdr/.ahdr exists (FieldTrip ft_filetype parity); otherwise use the Neuroscan epoch reader.
Follow-up on Claude re-review + CI (head will be the latest
|
- Guard math.isnan in pop_importevent history formatting - Accept companion-file wording in missing-.fdt test - Expect two-file resample output in CLI transform manifest
|
Claude finished @suraj-ranganath's task in 1m 3s —— View job Code review (re-review at
|
| eeg = _read_neuroscan_epochs(path, **options) | ||
| elif suffix == ".raw": | ||
| eeg = pop_readegi(path, **options) | ||
| elif suffix in {".vhdr", ".ahdr"} and blockrange is None: |
There was a problem hiding this comment.
Important: one .ahdr recording loads with two different channel layouts, depending on blockrange
Without blockrange, .ahdr goes to pop_loadbv, which reads NumberOfChannels channels. With blockrange, it goes to mne.io.read_raw_brainvision, which expects one extra unlabelled channel in the .eeg data. The new tests show this. test_pop_fileio_detects_brainvision_data_from_sibling_header writes an .ahdr file with 2 channels. test_pop_fileio_brainvision_data_path_retains_blockrange has to rewrite the data with 3 channels before MNE will read it (test_pop_loadbv.py#L469-L473). Because the data is multiplexed, at most one of these readers interleaves a real .ahdr file correctly. The other reader produces scrambled data without raising an error.
That test comment also explains a workaround. AGENTS.md says: "Never use comments to justify workarounds."
Suggested fix: send every .ahdr import through one reader. One option is to convert blockrange (in seconds) to srange and always call pop_loadbv. If MNE handles the extra channel correctly, make pop_loadbv handle it too. Otherwise, keep .ahdr out of the sibling-header detection until pop_loadbv and MNE agree. Then use the same on-disk .ahdr file in both tests and remove the comment.
There was a problem hiding this comment.
Fixed. All .vhdr/.ahdr imports go through pop_loadbv; blockrange is converted to sample indices. The MNE dual path and the fixture workaround comment are gone.
Route all .vhdr/.ahdr imports through pop_loadbv; convert blockrange seconds to sample indices. Remove the MNE dual-path and fixture workaround.
Claude follow-up (
|
|
Claude finished @suraj-ranganath's task in 48s —— View job Code review (re-review at
|
Tip verification (head
|
loadeeg/pop_loadeeg default accepttype='all' and expose accept; FieldTrip remains the differing reader.
Summary
Stream 9 of the release-readiness GUI audit: importer option dialogs, native readers, MATLAB v7.3
.setloading, save-as layout, and safe companion-file paths.Fixes #554
Fixes #497
Fixes #561
Not in this PR: #538 (
pop_load_frombids/ BIDSNonechanlocs) — owned by Stream 10 (fix_streams.md).Findings
.setkeeps full labels, nested refs, empty events, and channel-major datadefusedxmlin themneextrapop_loadbv.set.EEGepoch reader; keep rejected sweeps (EEGLAB parity)pop_loadbv/pop_loadsetreject companion paths that leave the header directoryIntentional differences from EEGLAB
F119 verdict (EEGLAB source)
EEGLAB
loadeeg.m/pop_loadeeg.m(neuroscanio) defaultaccepttype='all'and expose anacceptfield — rejected sweeps are kept. eegprep matches that. The fewer-trial count is a FieldTrip File-IO difference (accepted-count at byte 364), not EEGLAB. Documented indocs/source/user_guide/storage.rst+ changelog (74519da7).Full EEGLAB reference suite (jamming)
74519da7(docs on code tipe3cc265f); EEGLABd0963be9; suitefec88f9f~/eegprep-bench/logs/s9_ref/Failures vs develop
test_matlab_tutorial_figures_retain_their_plot_target_between_callstest_average_reference_matches_matlab_on_64_channel_float32(max_abs≈0.109)test_bids_preproc×2 (…/eegprep-s9/datamissing)test_parity_subcomps_subtractedTimeoutError 900s (suite)74519da7and develop1bdd1a28No new S9 code failures. Tolerances unchanged.
Tests
tests/test_stream9_*.py,tests/test_pop_loadset.pyupdates--timeout=30)Before merge (executor checklist)
flock ~/eegprep-bench/matlab.lock74519da7)e3cc265; docs-only74519da7follows)Notes
menu_actionsimport region, listed popfuncs,pop_savesetF26 only,pyproject.toml/uv.lockfor defusedxml).