Skip to content

Commit d52c89e

Browse files
fixed some info fields in MEG interpolation across sensor types using… (#13759)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 18ffc24 commit d52c89e

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

doc/changes/dev/13759.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
When interpolating from axial to planar gradiometers, set info fields "chs", "ch_names", and "nchan", according to the interpolated data,
2+
reset info fields "device_info", "helium_info", "gantry_angle", "ctf_head_t", "dev_ctf_t", "bads", "projs", and "comps" to [] or None, and
3+
preserve all remaining info fields.
4+
by :newcontrib:`Christoph Huber-Huber`.

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
.. _Chris Mullins: https://crmullins.com
5454
.. _Christian Brodbeck: https://github.com/christianbrodbeck
5555
.. _Christian O'Reilly: https://github.com/christian-oreilly
56+
.. _Christoph Huber-Huber: https://github.com/chsquare
5657
.. _Christopher Dinh: https://github.com/chdinh
5758
.. _Chun-Hui Li: https://github.com/iamsc
5859
.. _Clemens Brunner: https://github.com/cbrnr

mne/channels/interpolation.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,35 @@ def _interpolate_to_meg(inst, sensors, origin, mode):
484484
if len(picks_meg_good) == 0:
485485
raise ValueError("No good MEG channels available for interpolation.")
486486

487-
# Load target sensor configuration
488-
info_to = read_meg_canonical_info(sensors)
489-
info_to["dev_head_t"] = deepcopy(inst.info["dev_head_t"])
487+
# Load target sensor configuration as info file
488+
info_cano = read_meg_canonical_info(sensors)
490489

491490
# Get source MEG info
492491
info_from = pick_info(inst.info, picks_meg_good)
493492

493+
# Update target info to accommodate the desired channel info
494+
# and reset some channel and machine-related fields to avoid
495+
# confusion later on.
496+
# NOTE: We don't change the original 'dev_head_t'.
497+
# Some keys require as default an empty list.
498+
info_to = deepcopy(info_from)
499+
with info_to._unlock():
500+
info_to.update(
501+
{
502+
"chs": info_cano["chs"],
503+
"ch_names": info_cano["ch_names"],
504+
"nchan": info_cano["nchan"],
505+
"device_info": None,
506+
"helium_info": None,
507+
"gantry_angle": None,
508+
"ctf_head_t": None,
509+
"dev_ctf_t": None,
510+
"bads": [],
511+
"projs": [],
512+
"comps": [],
513+
}
514+
)
515+
494516
# Compute field interpolation mapping
495517
origin_val = _check_origin(origin, inst.info)
496518
mapping = _map_meg_or_eeg_channels(info_from, info_to, mode=mode, origin=origin_val)

mne/channels/tests/test_interpolation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,11 @@ def test_interpolate_to_meg(monkeypatch):
556556
monkeypatch.setattr( # for speed
557557
mne.channels.channels, "_ALLOWED_INTERPOLATION_MODES", ("point",)
558558
)
559+
evoked.resample(evoked.info["sfreq"] / 2) # speed up even more
559560
kwargs = dict(mode="point", origin=(0.0, 0.0, 0.04))
560561
evoked_ctf = evoked.interpolate_to("ctf151", **kwargs)
562+
# test whether .info["sfreq"] was preserved across interpolation
563+
assert evoked_ctf.info["sfreq"] == evoked.info["sfreq"]
561564
evoked_ctf.pick(evoked_ctf.ch_names[::4])
562565
evoked_rt = evoked_ctf.interpolate_to("neuromag", **kwargs).pick(evoked.ch_names)
563566
corrcoef = np.corrcoef(evoked.data.ravel(), evoked_rt.data.ravel())[0, 1]

0 commit comments

Comments
 (0)