From 65b48d012da4d40e761d04c2fea031e4c1c95741 Mon Sep 17 00:00:00 2001 From: Hamza Abdelhedi Date: Wed, 14 Oct 2026 18:15:49 -0400 Subject: [PATCH 1/2] BUG: Exclude bad channels in annotate_muscle_zscore --- mne/preprocessing/artifact_detection.py | 2 +- mne/preprocessing/tests/test_artifact_detection.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mne/preprocessing/artifact_detection.py b/mne/preprocessing/artifact_detection.py index b8786c765b2..ad8e69688f1 100644 --- a/mne/preprocessing/artifact_detection.py +++ b/mne/preprocessing/artifact_detection.py @@ -117,7 +117,7 @@ def annotate_muscle_zscore( logger.info("Using %s sensors for muscle artifact detection", ch_type) else: _check_option("ch_type", ch_type, ["mag", "grad", "eeg"]) - raw_copy.pick(ch_type) + raw_copy.pick(ch_type, exclude="bads") raw_copy.filter( filter_freq[0], diff --git a/mne/preprocessing/tests/test_artifact_detection.py b/mne/preprocessing/tests/test_artifact_detection.py index d3f6e8f75fa..fe91f965b85 100644 --- a/mne/preprocessing/tests/test_artifact_detection.py +++ b/mne/preprocessing/tests/test_artifact_detection.py @@ -174,6 +174,12 @@ def test_muscle_annotation(meas_date, events): onset = onset.astype(int) assert_array_equal(scores[onset].astype(int), np.array([23, 10])) assert annot_muscle.duration.size == 2 + # Bad channels are excluded + raw.info["bads"] = ["MEG0111"] + _, scores_bads = annotate_muscle_zscore(raw, ch_type="mag", threshold=10) + raw_drop = raw.copy().drop_channels(raw.info["bads"]) + _, scores_drop = annotate_muscle_zscore(raw_drop, ch_type="mag", threshold=10) + assert_allclose(scores_bads, scores_drop) raw.set_annotations(annot_muscle) From 463bbe745c81527589c217864eac17390d83913a Mon Sep 17 00:00:00 2001 From: Hamza Abdelhedi Date: Wed, 14 Oct 2026 18:16:52 -0400 Subject: [PATCH 2/2] Add changelog entry --- doc/changes/dev/14418.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/dev/14418.bugfix.rst diff --git a/doc/changes/dev/14418.bugfix.rst b/doc/changes/dev/14418.bugfix.rst new file mode 100644 index 00000000000..093e0141592 --- /dev/null +++ b/doc/changes/dev/14418.bugfix.rst @@ -0,0 +1 @@ +Fix bug with :func:`mne.preprocessing.annotate_muscle_zscore` where channels in ``raw.info["bads"]`` were included in the computation of the muscle artifact scores, by `Hamza Abdelhedi`_.