Repository navigation
Description
pop_load_frombids reads every EEGCoordinateSystem other than EEGLAB's as right-anterior-superior (RAS) and converts it to EEGLAB's anterior-left-superior (ALS) frame with coords_RAS_to_ALS. The BIDS specification's coordinate-systems appendix gives CTF, 4DBti and KitYokogawa the ALS orientation already (x anterior, y left, z superior), so electrode positions in those frames come out turned by 90 degrees about the vertical axis. Nothing warns, and every later use of the positions (scalp maps, ICLabel's topography features, anything that reads theta and radius) inherits the turn.
Where
src/eegprep/functions/popfunc/pop_load_frombids.py at edf694c8344b9c4c68672eac3acf9a819f1462a8:
- lines 312 to 321:
coord_systemisALSonly when'EEGLAB' in coord_system.upper()or whenEEGCoordinateSystemDescriptionis exactlyEEGLAB; every other value becomesRAS; - line 380:
coords = coords_RAS_to_ALS(coords)then swaps x and y and negates the new y (plugins/EEG_BIDS/coords.py, lines 29 to 37), which for positions already in ALS is a rotation of 90 degrees.
EEGLAB-HJ is read correctly (it contains EEGLAB); CTF, 4DBti and KitYokogawa are not.
To reproduce
A BIDS EEG recording whose _electrodes.tsv gives Fp1 at x=77, y=32, z=19 (millimeters, ALS: x toward the nose, y to the left) and whose _coordsystem.json is
{"EEGCoordinateSystem": "CTF", "EEGCoordinateUnits": "mm"}from eegprep import pop_load_frombids
eeg, report = pop_load_frombids("sub-01/eeg/sub-01_task-rest_eeg.edf", return_report=True)
fp1 = next(c for c in eeg["chanlocs"] if c["labels"] == "Fp1")
print(fp1["X"], fp1["Y"], fp1["Z"], fp1["theta"])prints 32.0 -77.0 19.0 67.43...; the expected values are 77.0 32.0 19.0 -22.57... (Fp1 left of the nose, not right of it). Adding "EEGCoordinateSystemDescription": "EEGLAB" to the same file gives the expected values, which shows the positions themselves are fine and only the frame is misread.
Suggested fix
Read the BIDS frames by their orientation instead of assuming RAS:
- ALS, kept as they are:
EEGLAB,EEGLAB-HJ,CTF,4DBti,KitYokogawa; - RAS, converted with
coords_RAS_to_ALS:CapTrakand the other head-based RAS frames, and the standard template spaces (MNI305,MNI152Lin,fsaverage,Talairach, and the rest of the appendix's list); - any other value (
Other, an unknown name, a frame BIDS gives no orientation): leave the channel locations unset and say why in the report, rather than assuming RAS, since a wrong frame movesthetaandradiuswithout raising anything.
The existing EEGCoordinateSystemDescription == "EEGLAB" rule can stay for datasets that rely on it. eegprep-lean's locations.py already uses this table when it reads positions from a Zarr store, so the two readers would then agree on the same coordinates.
A regression test with the recording above in each of CTF, 4DBti and KitYokogawa (expected Fp1 theta -22.57 degrees) and in CapTrak with the same positions given in RAS would pin it.
Context
NEMAR's nemar-ica recipe reads BIDS datasets through pop_load_frombids and, until this is fixed, withholds positions in these three frames instead of drawing scalp maps on them (nemarOrg/nemar-process#94).
Agentic AI tools were used. Workflows follow the Research Skills (doi:10.5281/zenodo.20696515). The author assumes full responsibility for this content and associated changes.
Activity
Cite sccn/eegprep#692 for the turned frames
claude commentedon Nov 25, 2026
🤖 Plan:
Research
pop_load_frombidsmapsEEGCoordinateSystemto ALS only when the name containsEEGLAB(or the description isEEGLAB); every other name becomes RAS and goes throughcoords_RAS_to_ALS, which rotates ALS frames by 90 degrees.Relevant code
src/eegprep/functions/popfunc/pop_load_frombids.py#L312-L321- frame classificationsrc/eegprep/functions/popfunc/pop_load_frombids.py#L378-L386- RAS to ALS conversionpackages/eegprep-lean/src/eegprep_lean/locations.py#L51-L89- appendix ALS/RAS tablesFix (#693)
BIDS_ALS_SYSTEMS/BIDS_RAS_SYSTEMSadded toplugins/EEG_BIDS/coords.py(same table as eegprep-lean, which cannot import eegprep). ALS frames are kept, RAS frames converted, any other named frame warns inreport["Warnings"]and leaves chanlocs unset. Kept: theEEGCoordinateSystemDescription == "EEGLAB"rule, and the RAS assumption when the coordsystem has noEEGCoordinateSystemkey or no coordsystem file exists. Matching is now exact (case-sensitive), as in eegprep-lean. CTF/4DBti/KitYokogawa added to the lean cross-route test, which now passes.This changes core EEGLAB-ported import code, so per AGENTS.md it needs human approval and one EEGLAB reference run before merge.
Read BIDS EEG coordinate systems by their appendix orientation
P5: nemar-ica chanlocs and recipe views (#93)