Skip to content

Improve tests of maxwell_filter_prepare_emptyroom #13208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 15, 2025
1 change: 1 addition & 0 deletions doc/changes/devel/13208.bugfix.rst.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle channels with potential electrode location in :func:`~mne.preprocessing.maxwell_filter_prepare_emptyroom`, by `Mathieu Scheltienne`_.
7 changes: 6 additions & 1 deletion mne/preprocessing/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ def maxwell_filter_prepare_emptyroom(
* Set the following properties of the empty-room recording to match the
experimental recording:

* Montage
* Montage (required for the fiducials defining the head coordinate frame)
* ``raw.first_time`` and ``raw.first_samp``

* Adjust annotations according to the ``annotations`` parameter.
* Adjust the measurement date according to the ``meas_date`` parameter.

.. note::

Note that in case of dual MEG/EEG acquisition, EEG channels should not be
included in the empty room recording. If provided, they will be ignored.

.. versionadded:: 1.1
""" # noqa: E501
_validate_type(item=raw_er, types=BaseRaw, item_name="raw_er")
Expand Down
23 changes: 22 additions & 1 deletion mne/preprocessing/tests/test_maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ def test_prepare_emptyroom_bads(bads):
assert raw_er_prepared.info["bads"] == ["MEG0113", "MEG2313"]
assert raw_er_prepared.info["dev_head_t"] == raw.info["dev_head_t"]

montage_expected = raw.copy().pick(picks="meg").get_montage()
montage_expected = raw.pick(picks="meg").get_montage()
assert raw_er_prepared.get_montage() == montage_expected

# Ensure the originals were not modified
Expand All @@ -1906,6 +1906,27 @@ def test_prepare_emptyroom_bads(bads):
assert raw_er.get_montage() is None


@testing.requires_testing_data
def test_prepare_empty_room_with_eeg() -> None:
"""Test preparation of MEG empty-room which was acquired with EEG enabled."""
raw = read_raw_fif(raw_fname, allow_maxshield="yes", verbose=False)
raw_er = read_raw_fif(erm_fname, allow_maxshield="yes", verbose=False)
assert "eeg" in raw
assert "eeg" in raw_er
raw_er_prepared = maxwell_filter_prepare_emptyroom(raw_er=raw_er, raw=raw)
assert raw_er_prepared.info["dev_head_t"] == raw.info["dev_head_t"]
montage_expected = raw.get_montage()
assert raw_er_prepared.get_montage() == montage_expected
Comment on lines +1909 to +1919
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsoner Picking up this PR briefly, something might have changed or I might not be seeing something.. but this test is now passing without changes to maxwell_filter_prepare_emptyroom.


raw_er = raw_er.pick("meg")
assert "eeg" in raw
assert "eeg" not in raw_er
raw_er_prepared = maxwell_filter_prepare_emptyroom(raw_er=raw_er, raw=raw)
assert raw_er_prepared.info["dev_head_t"] == raw.info["dev_head_t"]
montage_expected = raw.pick("meg").get_montage()
assert raw_er_prepared.get_montage() == montage_expected


@testing.requires_testing_data
@pytest.mark.slowtest # lots of params
@pytest.mark.parametrize("set_annot_when", ("before", "after"))
Expand Down