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/14266.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where :meth:`mne.io.Raw.interpolate_to` and related methods with ``method="spline"`` did not center the target sensor positions on the fitted sphere origin, by `Eric Larson`_.
4 changes: 3 additions & 1 deletion mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ def _interpolate_to_eeg(inst, sensors, origin, method, reg):
if method == "spline":
origin_val = _check_origin(origin, inst.info)
pos_from = inst.info._get_channel_positions(picks_good_eeg) - origin_val
pos_to = np.stack(list(ch_pos.values()), axis=0)
# Use info_to (rather than ch_pos directly) so that the target positions
# are in the head frame, and center both sets on the fitted origin
pos_to = info_to._get_channel_positions() - origin_val

def _check_pos_sphere(pos):
d = np.linalg.norm(pos, axis=-1)
Expand Down
12 changes: 12 additions & 0 deletions mne/channels/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,18 @@ def test_interpolate_to_eeg(montage_name, method, data_type):
assert inst_interp.info["bads"] == bads


def test_interpolate_to_eeg_same_positions():
"""Test that spline interpolate_to onto src pos is a no-op (gh-14153)."""
raw = read_raw_fif(raw_fname).pick("eeg").crop(0, 1).load_data()
montage = make_dig_montage(
ch_pos=dict(zip(raw.ch_names, raw.info._get_channel_positions())),
coord_frame="head",
)
raw_interp = raw.copy().interpolate_to(montage, method="spline")
assert raw_interp.ch_names == raw.ch_names
assert_allclose(raw_interp.get_data(), raw.get_data(), rtol=1e-5, atol=1e-12)


@pytest.mark.slowtest # ~5s locally
@pytest.mark.filterwarnings("ignore:Projection vector.* reduced .*:RuntimeWarning")
def test_interpolate_to_meg(monkeypatch):
Expand Down
Loading