Skip to content
Open
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/14287.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warn when :func:`mne.preprocessing.interpolate_bridged_electrodes` ignores bad channels during interpolation, by `Deepesh Sonar`_.
11 changes: 10 additions & 1 deletion mne/preprocessing/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..evoked import Evoked, EvokedArray
from ..io import BaseRaw, RawArray
from ..transforms import _cart_to_sph, _sph_to_cart
from ..utils import _ensure_int, _validate_type
from ..utils import _ensure_int, _validate_type, warn


def equalize_bads(insts, interp_thresh=1.0, copy=True):
Expand Down Expand Up @@ -84,6 +84,9 @@ def interpolate_bridged_electrodes(inst, bridged_idx, bad_limit=4):
that to aid in interpolation rather than completely discarding the
data from the two channels.

Channels listed in ``inst.info["bads"]`` are ignored for exclusion and
may influence the interpolation result.

Parameters
----------
inst : instance of Epochs, Evoked, or Raw
Expand Down Expand Up @@ -126,6 +129,12 @@ def interpolate_bridged_electrodes(inst, bridged_idx, bad_limit=4):
)
# store bads orig to put back at the end
bads_orig = inst.info["bads"]
if bads_orig:
warn(
f"The channels {', '.join(bads_orig)} are marked as bad but will not "
"be excluded from bridged-electrode interpolation and may influence "
"the result."
)
inst.info["bads"] = list()

# look for group of bad channels
Expand Down
5 changes: 4 additions & 1 deletion mne/preprocessing/tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ def test_interpolate_bridged_electrodes():
idx0 = inst.ch_names.index("EEG 001")
idx1 = inst.ch_names.index("EEG 002")
ch_names_orig = inst.ch_names.copy()
inst.info["bads"] = ["EEG 003"]
bads_orig = inst.info["bads"].copy()
inst2 = inst.copy()
inst2.info["bads"] = ["EEG 001", "EEG 002"]
inst2.interpolate_bads()
data_interp_reg = inst2.get_data(picks=["EEG 001", "EEG 002"])
inst = interpolate_bridged_electrodes(inst, [(idx0, idx1)])
with pytest.warns(RuntimeWarning, match="EEG 003.*not.*excluded"):
inst = interpolate_bridged_electrodes(inst, [(idx0, idx1)])
data_interp = inst.get_data(picks=["EEG 001", "EEG 002"])
assert not any(["virtual" in ch for ch in inst.ch_names])
assert inst.ch_names == ch_names_orig
assert inst.info["bads"] == bads_orig
inst.info["bads"] = []
# check closer to regular interpolation than original data
assert 1e-6 < np.mean(np.abs(data_interp - data_interp_reg)) < 5.4e-5

Expand Down
Loading