Skip to content

pop_load_frombids turns CTF, 4DBti and KitYokogawa electrode positions by 90 degrees #692

Done

Description

@neuromechanist

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_system is ALS only when 'EEGLAB' in coord_system.upper() or when EEGCoordinateSystemDescription is exactly EEGLAB; every other value becomes RAS;
  • 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: CapTrak and 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 moves theta and radius without 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

  1. added a commit that references this issue on Nov 25, 2026
  2. claude commented on Nov 25, 2026

    @claude
    Contributor

    🤖 Plan:

    Research

    pop_load_frombids maps EEGCoordinateSystem to ALS only when the name contains EEGLAB (or the description is EEGLAB); every other name becomes RAS and goes through coords_RAS_to_ALS, which rotates ALS frames by 90 degrees.

    Relevant code

    Fix (#693)

    BIDS_ALS_SYSTEMS / BIDS_RAS_SYSTEMS added to plugins/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 in report["Warnings"] and leaves chanlocs unset. Kept: the EEGCoordinateSystemDescription == "EEGLAB" rule, and the RAS assumption when the coordsystem has no EEGCoordinateSystem key 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.

  3. added a commit that references this issue on Nov 25, 2026
    ee3d384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions