Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/14320.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with :func:`mne.preprocessing.interpolate_bridged_electrodes` where ``inst.info["bads"]`` was cleared and not restored when too many electrodes were bridged together and a :class:`RuntimeError` was raised, by `Carina Forster`_.
7 changes: 4 additions & 3 deletions mne/preprocessing/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ def interpolate_bridged_electrodes(inst, bridged_idx, bad_limit=4):
raise RuntimeError(
f"Montage channel positions must be in ``head`` got {pos['coord_frame']}"
)
# store bads orig to put back at the end
bads_orig = inst.info["bads"]
inst.info["bads"] = list()

# look for group of bad channels
nodes = sorted(set(chain(*bridged_idx)))
Expand All @@ -153,6 +150,10 @@ def interpolate_bridged_electrodes(inst, bridged_idx, bad_limit=4):
"might be inaccurate."
)

# store bads orig to put back at the end
bads_orig = inst.info["bads"]
inst.info["bads"] = list()

# make virtual channels
virtual_chs = dict()
bads = set()
Expand Down
3 changes: 3 additions & 0 deletions mne/preprocessing/tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ def test_interpolate_bridged_electrodes():
data[:5, :] = np.ones((5, 1024))
raw = io.RawArray(data, info)
raw.set_montage("spherical_1005")
raw.info["bads"] = [ch_names[10]] # a bad channel outside the bridged group
bridged_idx = list(itertools.combinations(range(5), 2))
with pytest.raises(
RuntimeError,
match="The channels AF1, AF10, AF10h, AF1h, AF2 are bridged "
"together and form a large area of bridged electrodes.",
):
interpolate_bridged_electrodes(raw, bridged_idx, bad_limit=4)
# bads must be preserved when the error is raised
assert raw.info["bads"] == [ch_names[10]]
# increase the limit to prevent raising
interpolate_bridged_electrodes(raw, bridged_idx, bad_limit=5)
# invalid argument
Expand Down
Loading