Skip to content
Closed
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/devel/bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in :func:`~mne.preprocessing.maxwell_filter_prepare_emptyroom` where a difference in sampling frequencies between data and emptyroom files was ignored, by `Daniel McCloy`_.
3 changes: 2 additions & 1 deletion mne/preprocessing/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def maxwell_filter_prepare_emptyroom(

# handle first_samp
raw_er_prepared.annotations.onset += raw.first_time - raw_er_prepared.first_time
raw_er_prepared._cropped_samp = raw._cropped_samp
# don't copy _cropped_samp directly, as sfreqs may differ
raw_er_prepared._cropped_samp = raw_er_prepared.time_as_index(raw.first_time).item()

# handle annotations
if annotations != "keep":
Expand Down
17 changes: 11 additions & 6 deletions mne/preprocessing/tests/test_maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,9 @@ def test_prepare_emptyroom_bads(bads):
@pytest.mark.parametrize("set_annot_when", ("before", "after"))
@pytest.mark.parametrize("raw_meas_date", ("orig", None))
@pytest.mark.parametrize("raw_er_meas_date", ("orig", None))
@pytest.mark.parametrize("equal_sfreq", (False, True))
def test_prepare_emptyroom_annot_first_samp(
set_annot_when, raw_meas_date, raw_er_meas_date
set_annot_when, raw_meas_date, raw_er_meas_date, equal_sfreq
):
"""Test prepare_emptyroom."""
raw = read_raw_fif(raw_fname, allow_maxshield="yes", verbose=False)
Expand Down Expand Up @@ -1861,12 +1862,15 @@ def test_prepare_emptyroom_annot_first_samp(
assert set_annot_when == "after"
meas_date = "from_raw"
want_date = raw.info["meas_date"]
if not equal_sfreq:
with raw_er.info._unlock():
raw_er.info["sfreq"] -= 100
raw_er_prepared = maxwell_filter_prepare_emptyroom(
raw_er=raw_er, raw=raw, meas_date=meas_date, emit_warning=True
)
assert raw_er.first_samp == raw_er_first_samp_orig
assert raw_er_prepared.info["meas_date"] == want_date
assert raw_er_prepared.first_samp == raw.first_samp
assert raw_er_prepared.first_time == raw.first_time

# Ensure (movement) annotations carry over regardless of whether they're
# set before or after preparation
Expand All @@ -1878,7 +1882,8 @@ def test_prepare_emptyroom_annot_first_samp(
prop_bad = np.isnan(raw.get_data([0], reject_by_annotation="nan")).mean()
assert 0.3 < prop_bad < 0.4
assert len(raw_er_prepared.annotations) == want_annot
prop_bad_er = np.isnan(
raw_er_prepared.get_data([0], reject_by_annotation="nan")
).mean()
assert_allclose(prop_bad, prop_bad_er)
if equal_sfreq:
prop_bad_er = np.isnan(
raw_er_prepared.get_data([0], reject_by_annotation="nan")
).mean()
assert_allclose(prop_bad, prop_bad_er)