From 3b79971c47cf27981817ba839bd851ea82bca29b Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Fri, 3 Nov 2023 09:54:14 +0100 Subject: [PATCH 1/4] Fix inferring fiducials from EEGLAB --- mne/io/eeglab/eeglab.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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")) From a110316ddd175920203e7a1a44c1ff45ecb3914d Mon Sep 17 00:00:00 2001 From: Clemens Brunner Date: Fri, 3 Nov 2023 10:08:15 +0100 Subject: [PATCH 2/4] Add changelog entry --- doc/changes/devel.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index 57a9b1fcb41..b8ec11f60f4 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.io.read_epochs_eeglab` where automatic fiducial detection would fail for certain files (:gh:`12165` by `Clemens Brunner`_) API changes ~~~~~~~~~~~ From 11d9ebe16ca9435d585766d9fec9cc82746ed789 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 3 Nov 2023 09:06:30 -0400 Subject: [PATCH 3/4] Update doc/changes/devel.rst --- doc/changes/devel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index b8ec11f60f4..a82cda9e40f 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -83,7 +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.io.read_epochs_eeglab` where automatic fiducial detection would fail for certain files (:gh:`12165` by `Clemens Brunner`_) +- Fix bug with :func:`mne.read_raw_eeglab` and :func:`mne.io.read_epochs_eeglab` where automatic fiducial detection would fail for certain files (:gh:`12165` by `Clemens Brunner`_) API changes ~~~~~~~~~~~ From 6a646ad5d05929fccb7ffcf6a8cdfc25b5a7fdfa Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 3 Nov 2023 09:36:38 -0400 Subject: [PATCH 4/4] Update doc/changes/devel.rst --- doc/changes/devel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index a82cda9e40f..6e494f58a30 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -83,7 +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.read_raw_eeglab` and :func:`mne.io.read_epochs_eeglab` where automatic fiducial detection would fail for certain files (:gh:`12165` by `Clemens Brunner`_) +- 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 ~~~~~~~~~~~