diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index 57a9b1fcb41..6e494f58a30 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -83,6 +83,7 @@ Bugs - Fix bug with :func:`~mne.viz.plot_raw` where changing ``MNE_BROWSER_BACKEND`` via :func:`~mne.set_config` would have no effect within a Python session (:gh:`12078` by `Santeri Ruuskanen`_) - Improve handling of ``method`` argument in the channel interpolation function to support :class:`str` and raise helpful error messages (:gh:`12113` by `Mathieu Scheltienne`_) - Fix combination of ``DIN`` event channels into a single synthetic trigger channel ``STI 014`` by the MFF reader of :func:`mne.io.read_raw_egi` (:gh:`12122` by `Mathieu Scheltienne`_) +- Fix bug with :func:`mne.io.read_raw_eeglab` and :func:`mne.read_epochs_eeglab` where automatic fiducial detection would fail for certain files (:gh:`12165` by `Clemens Brunner`_) API changes ~~~~~~~~~~~ diff --git a/mne/io/eeglab/eeglab.py b/mne/io/eeglab/eeglab.py index 9e08807db49..6cf92bfd7bf 100644 --- a/mne/io/eeglab/eeglab.py +++ b/mne/io/eeglab/eeglab.py @@ -165,17 +165,23 @@ def _get_montage_information(eeg, get_pos, *, montage_units): ) lpa, rpa, nasion = None, None, None - if hasattr(eeg, "chaninfo") and len(eeg.chaninfo.get("nodatchans", [])): - for item in list(zip(*eeg.chaninfo["nodatchans"].values())): - d = dict(zip(eeg.chaninfo["nodatchans"].keys(), item)) - if d.get("type", None) != "FID": + if hasattr(eeg, "chaninfo") and isinstance(eeg.chaninfo["nodatchans"], dict): + nodatchans = eeg.chaninfo["nodatchans"] + types = nodatchans.get("type", []) + descriptions = nodatchans.get("description", []) + xs = nodatchans.get("X", []) + ys = nodatchans.get("Y", []) + zs = nodatchans.get("Z", []) + + for type_, description, x, y, z in zip(types, descriptions, xs, ys, zs): + if type_ != "FID": continue - elif d.get("description", None) == "Nasion": - nasion = np.array([d["X"], d["Y"], d["Z"]]) - elif d.get("description", None) == "Right periauricular point": - rpa = np.array([d["X"], d["Y"], d["Z"]]) - elif d.get("description", None) == "Left periauricular point": - lpa = np.array([d["X"], d["Y"], d["Z"]]) + if description == "Nasion": + nasion = np.array([x, y, z]) + elif description == "Right periauricular point": + rpa = np.array([x, y, z]) + elif description == "Left periauricular point": + lpa = np.array([x, y, z]) # Always check this even if it's not used _check_option("montage_units", montage_units, ("m", "dm", "cm", "mm", "auto"))