From 0c1e10310ac7e01f126f0d18e6b3ecd1e9d43684 Mon Sep 17 00:00:00 2001 From: DarkStar1709 Date: Fri, 9 Jan 2026 14:24:41 +0000 Subject: [PATCH 1/4] FIX: Handle diagonal covariances in plot_cov --- mne/viz/misc.py | 2 +- mne/viz/tests/test_misc.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mne/viz/misc.py b/mne/viz/misc.py index a62833d7f81..0b71673f3ad 100644 --- a/mne/viz/misc.py +++ b/mne/viz/misc.py @@ -83,7 +83,7 @@ def _index_info_cov(info, cov, exclude): for key in _DATA_CH_TYPES_SPLIT if len(idx_by_type[key]) > 0 ] - C = cov.data[ch_idx][:, ch_idx] + C = cov._get_square()[ch_idx][:, ch_idx] return info, C, ch_names, idx_names diff --git a/mne/viz/tests/test_misc.py b/mne/viz/tests/test_misc.py index 7e4a3b2d806..e727b16b495 100644 --- a/mne/viz/tests/test_misc.py +++ b/mne/viz/tests/test_misc.py @@ -11,6 +11,7 @@ from mne import ( SourceEstimate, + create_info, pick_events, read_cov, read_dipole, @@ -19,6 +20,7 @@ read_source_spaces, ) from mne.chpi import compute_chpi_snr +from mne.cov import make_ad_hoc_cov from mne.datasets import testing from mne.filter import create_filter from mne.io import read_raw_fif @@ -136,6 +138,19 @@ def test_plot_cov(): fig1, fig2 = cov.plot(raw.info) +def test_plot_cov_diagonal(): + """Test plotting of diagonal covariances (e.g., from make_ad_hoc_cov).""" + n_channels = 10 + sfreq = 100 + info = create_info( + [f"EEG{i:03d}" for i in range(n_channels)], sfreq, ch_types="eeg" + ) + cov = make_ad_hoc_cov(info, std={"eeg": 1}) + # This should not raise an IndexError + fig1, fig2 = cov.plot(info) + plt.close("all") + + @testing.requires_testing_data def test_plot_bem(): """Test plotting of BEM contours.""" From 5de117ea887023b325d188f988a830ebad7a9a70 Mon Sep 17 00:00:00 2001 From: DarkStar1709 Date: Fri, 9 Jan 2026 14:47:54 +0000 Subject: [PATCH 2/4] DOC: Add changelog entry for diagonal covariance plot fix --- doc/changes/dev/13582.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/dev/13582.bugfix.rst diff --git a/doc/changes/dev/13582.bugfix.rst b/doc/changes/dev/13582.bugfix.rst new file mode 100644 index 00000000000..516587d447a --- /dev/null +++ b/doc/changes/dev/13582.bugfix.rst @@ -0,0 +1 @@ +Fix bug where plotting covariance matrices created by :func:`mne.cov.make_ad_hoc_cov` would raise an IndexError, by :newcontrib:`DarkStar1709`. From 9d9f2d2cd173ba091c607b2793042914101a9e7c Mon Sep 17 00:00:00 2001 From: DarkStar1709 Date: Fri, 9 Jan 2026 14:51:18 +0000 Subject: [PATCH 3/4] DOC: Fix changelog entry - correct function reference and add author to names.inc --- doc/changes/dev/13582.bugfix.rst | 2 +- doc/changes/names.inc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/changes/dev/13582.bugfix.rst b/doc/changes/dev/13582.bugfix.rst index 516587d447a..dc41a2c6c27 100644 --- a/doc/changes/dev/13582.bugfix.rst +++ b/doc/changes/dev/13582.bugfix.rst @@ -1 +1 @@ -Fix bug where plotting covariance matrices created by :func:`mne.cov.make_ad_hoc_cov` would raise an IndexError, by :newcontrib:`DarkStar1709`. +Fix bug where plotting covariance matrices created by :func:`mne.cov.make_ad_hoc_cov` would raise an IndexError, by :newcontrib:`DarkStar1709` (:gh:`13582`). diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 1a9c62b9bea..78dabe32c71 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -62,6 +62,7 @@ .. _Daniel Strohmeier: https://github.com/joewalter .. _Daniel Tse: https://github.com/Xiezhibin .. _Darin Erat Sleiter: https://github.com/dsleiter +.. _DarkStar1709: https://github.com/DarkStar1709 .. _David Haslacher: https://github.com/davidhaslacher .. _David Julien: https://github.com/Swy7ch .. _David Sabbagh: https://github.com/DavidSabbagh From e3b1a4bc52273acf774ce927467c7344dc1a786f Mon Sep 17 00:00:00 2001 From: Arnav1709 Date: Fri, 9 Jan 2026 16:11:31 +0000 Subject: [PATCH 4/4] DOC: Update author credit in changelog for covariance plotting bug fix --- doc/changes/dev/13582.bugfix.rst | 2 +- doc/changes/names.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/changes/dev/13582.bugfix.rst b/doc/changes/dev/13582.bugfix.rst index dc41a2c6c27..3484e817660 100644 --- a/doc/changes/dev/13582.bugfix.rst +++ b/doc/changes/dev/13582.bugfix.rst @@ -1 +1 @@ -Fix bug where plotting covariance matrices created by :func:`mne.cov.make_ad_hoc_cov` would raise an IndexError, by :newcontrib:`DarkStar1709` (:gh:`13582`). +Fix bug where plotting covariance matrices created by :func:`mne.cov.make_ad_hoc_cov` would raise an IndexError, by :newcontrib:`Arnav Kumar` (:gh:`13582`). diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 78dabe32c71..65cd2c498dd 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -29,6 +29,7 @@ .. _Antti Rantala: https://github.com/Odingod .. _Apoorva Karekal: https://github.com/apoorva6262 .. _Archit Singhal: https://github.com/architsinghal-mriirs +.. _Arnav Kumar: https://github.com/Arnav1709 .. _Arne Pelzer: https://github.com/aplzr .. _Ashley Drew: https://github.com/ashdrew .. _Asish Panda: https://github.com/kaichogami @@ -62,7 +63,6 @@ .. _Daniel Strohmeier: https://github.com/joewalter .. _Daniel Tse: https://github.com/Xiezhibin .. _Darin Erat Sleiter: https://github.com/dsleiter -.. _DarkStar1709: https://github.com/DarkStar1709 .. _David Haslacher: https://github.com/davidhaslacher .. _David Julien: https://github.com/Swy7ch .. _David Sabbagh: https://github.com/DavidSabbagh