Skip to content

Commit 7c531e4

Browse files
FIX: Missing coordinates.xml in MFF file (#13148)
1 parent a5073bf commit 7c531e4

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

mne/io/egi/egimff.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def _read_mff_header(filepath):
122122
# Add the sensor info.
123123
sensor_layout_file = op.join(filepath, "sensorLayout.xml")
124124
sensor_layout_obj = parse(sensor_layout_file)
125+
125126
summaryinfo["device"] = sensor_layout_obj.getElementsByTagName("name")[
126127
0
127128
].firstChild.data
@@ -279,7 +280,7 @@ def _read_locs(filepath, egi_info, channel_naming):
279280

280281
fname = op.join(filepath, "coordinates.xml")
281282
if not op.exists(fname):
282-
logger.warn("File coordinates.xml not found, not setting channel locations")
283+
warn("File coordinates.xml not found, not setting channel locations")
283284
ch_names = [channel_naming % (i + 1) for i in range(egi_info["n_channels"])]
284285
return ch_names, None
285286
dig_ident_map = {
@@ -487,14 +488,13 @@ def __init__(
487488

488489
if mon is not None:
489490
info.set_montage(mon, on_missing="ignore")
490-
491-
ref_idx = np.flatnonzero(np.isin(mon.ch_names, REFERENCE_NAMES))
492-
if len(ref_idx):
493-
ref_idx = ref_idx.item()
494-
ref_coords = info["chs"][int(ref_idx)]["loc"][:3]
495-
for chan in info["chs"]:
496-
if chan["kind"] == FIFF.FIFFV_EEG_CH:
497-
chan["loc"][3:6] = ref_coords
491+
ref_idx = np.flatnonzero(np.isin(mon.ch_names, REFERENCE_NAMES))
492+
if len(ref_idx):
493+
ref_idx = ref_idx.item()
494+
ref_coords = info["chs"][int(ref_idx)]["loc"][:3]
495+
for chan in info["chs"]:
496+
if chan["kind"] == FIFF.FIFFV_EEG_CH:
497+
chan["loc"][3:6] = ref_coords
498498

499499
file_bin = op.join(input_fname, egi_info["eeg_fname"])
500500
egi_info["egi_events"] = egi_events

mne/io/egi/tests/test_egi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,10 @@ def test_egi_mff_bad_xml(tmp_path):
595595
mff_fname = shutil.copytree(egi_mff_fname, tmp_path / "test_egi_bad_xml.mff")
596596
bad_xml = mff_fname / "bad.xml"
597597
bad_xml.write_text("<foo>", encoding="utf-8")
598+
# Missing coordinate file
599+
(mff_fname / "coordinates.xml").unlink()
598600
with pytest.warns(RuntimeWarning, match="Could not parse the XML"):
599-
raw = read_raw_egi(mff_fname)
601+
with pytest.warns(RuntimeWarning, match="File coordinates.xml not found"):
602+
raw = read_raw_egi(mff_fname)
600603
# little check that the bad XML doesn't affect the parsing of other xml files
601604
assert "DIN1" in raw.annotations.description

0 commit comments

Comments
 (0)