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/14457.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in :func:`mne.preprocessing.regress_artifact` where passing ``betas`` caused the ``picks_artifact`` value to be passed as ``exclude`` and the default ``picks_artifact="eog"`` to be used instead, by `Johannes Herforth`_.
4 changes: 3 additions & 1 deletion mne/preprocessing/_regress.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def regress_artifact(
picks_artifact = _picks_to_idx(inst.info, picks_artifact)
want_betas_shape = (len(picks), len(picks_artifact))
_check_option("betas.shape", betas.shape, (want_betas_shape,))
model = EOGRegression(picks, picks_artifact, proj=proj)
model = EOGRegression(
picks=picks, exclude=exclude, picks_artifact=picks_artifact, proj=proj
)
model.info_ = inst.info.copy()
model.coef_ = betas
return model.apply(inst, copy=copy), model.coef_
Expand Down
5 changes: 5 additions & 0 deletions mne/preprocessing/tests/test_regress.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def test_regress_artifact():
assert orig_norm / 2 > clean_norm > orig_norm / 10
with pytest.raises(ValueError, match=r"Invalid value.*betas\.shape.*"):
regress_artifact(epochs, betas=betas[:-1])
# Non-default picks_artifact must be honored when betas are given
kwargs = dict(picks="eeg", picks_artifact=["EEG 001"])
epochs_clean, betas = regress_artifact(epochs, **kwargs)
epochs_betas, _ = regress_artifact(epochs, betas=betas, **kwargs)
assert_allclose(epochs_betas.get_data(), epochs_clean.get_data())
# Regressing channels onto themselves should work
epochs, betas = regress_artifact(epochs, picks="eog", picks_artifact="eog")
assert np.ptp(epochs.get_data("eog")) < 1e-15 # constant value
Expand Down
Loading