From 07439200737d41ef8904153fd9a0f0b665e33511 Mon Sep 17 00:00:00 2001 From: Famous Date: Sun, 15 Mar 2026 01:55:54 +0530 Subject: [PATCH 1/4] FIX: correct mode parameter mapping in get_point_spread and get_cross_talk --- doc/changes/dev/13128.bugfix.rst | 1 + mne/minimum_norm/resolution_matrix.py | 19 +++++++++++++++---- .../tests/test_resolution_matrix.py | 12 ++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 doc/changes/dev/13128.bugfix.rst diff --git a/doc/changes/dev/13128.bugfix.rst b/doc/changes/dev/13128.bugfix.rst new file mode 100644 index 00000000000..158a19dfd1e --- /dev/null +++ b/doc/changes/dev/13128.bugfix.rst @@ -0,0 +1 @@ +Fix ``mode`` parameter in :func:`~mne.minimum_norm.get_point_spread` and :func:`~mne.minimum_norm.get_cross_talk` to correctly map public mode names (``'max'``, ``'svd'``) to internal names, and raise :class:`ValueError` for invalid mode values, by :newcontrib:`Famous077`. \ No newline at end of file diff --git a/mne/minimum_norm/resolution_matrix.py b/mne/minimum_norm/resolution_matrix.py index 10a7b160371..301c4e23df5 100644 --- a/mne/minimum_norm/resolution_matrix.py +++ b/mne/minimum_norm/resolution_matrix.py @@ -155,8 +155,14 @@ def _get_psf_ctf( # summarise PSFs/CTFs across vertices if requested pca_var = None # variances computed only if return_pca_vars=True if mode is not None: + #mapping public mode names to internal names + _mode_map = { + "max": "maxnorm", + "svd": "pca", + "mean": "mean", + } funcs, pca_var = _summarise_psf_ctf( - funcs, mode, n_comp, return_pca_vars, nn + funcs, _mode_map[mode], n_comp, return_pca_vars, nn ) if not vector: # if one value per vertex requested @@ -193,11 +199,16 @@ def _get_psf_ctf( def _check_get_psf_ctf_params(mode, n_comp, return_pca_vars): """Check input parameters of _get_psf_ctf() for consistency.""" - if mode in [None, "sum", "mean"] and n_comp > 1: + valid_modes = (None, "mean", "max", "svd") + if mode not in valid_modes: + raise ValueError( + f"mode must be one of {valid_modes}, got {mode!r} instead." + ) + if mode in [None, "mean"] and n_comp > 1: msg = f"n_comp must be 1 for mode={mode}." raise ValueError(msg) - if mode != "pca" and return_pca_vars: - msg = "SVD variances can only be returned if mode=pca." + if mode != "svd" and return_pca_vars: + msg = "SVD variances can only be returned if mode='svd'." raise ValueError(msg) diff --git a/mne/minimum_norm/tests/test_resolution_matrix.py b/mne/minimum_norm/tests/test_resolution_matrix.py index b5b41e2611d..a3469705188 100644 --- a/mne/minimum_norm/tests/test_resolution_matrix.py +++ b/mne/minimum_norm/tests/test_resolution_matrix.py @@ -68,7 +68,7 @@ def test_resolution_matrix_free(src_type, fwd_volume_small): ) assert_array_almost_equal(rm_mne_free, rm_mne_free.T) # check various summary and normalisation options - for mode in [None, "sum", "mean", "maxval", "maxnorm", "pca"]: + for mode in [None, "mean", "max", "svd"]: n_comps = [1, 3] if mode in [None, "sum", "mean"]: n_comps = [1] @@ -114,7 +114,7 @@ def test_resolution_matrix_free(src_type, fwd_volume_small): # There is an ambiguity in the sign flip from the PCA here. # Ideally we would use the normals to fix it, but it's not # trivial. - if mode == "pca" and n_comp == 3: + if mode == "svd" and n_comp == 3: stc_psf_free = abs(stc_psf_free) stc_ctf_free = abs(stc_psf_free) assert_array_almost_equal( @@ -184,9 +184,9 @@ def test_resolution_matrix_fixed(): # Some arbitrary vertex numbers idx = [1, 100, 400] # check various summary and normalisation options - for mode in [None, "sum", "mean", "maxval", "maxnorm", "pca"]: + for mode in [None, "mean", "max", "svd"]: n_comps = [1, 3] - if mode in [None, "sum", "mean"]: + if mode in [None, "mean"]: n_comps = [1] for n_comp in n_comps: for norm in [None, "max", "norm", True]: @@ -217,7 +217,7 @@ def test_resolution_matrix_fixed(): rm_mne, forward_fxd["src"], idx, - mode=mode, + mode="svd", n_comp=n_comp, norm="norm", return_pca_vars=True, @@ -226,7 +226,7 @@ def test_resolution_matrix_fixed(): rm_mne, forward_fxd["src"], idx, - mode=mode, + mode="svd", n_comp=n_comp, norm="norm", return_pca_vars=True, From feeffc04b204561b0c6ee987ac85f483a38d771b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:34:46 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/minimum_norm/resolution_matrix.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mne/minimum_norm/resolution_matrix.py b/mne/minimum_norm/resolution_matrix.py index 301c4e23df5..c1b2187b591 100644 --- a/mne/minimum_norm/resolution_matrix.py +++ b/mne/minimum_norm/resolution_matrix.py @@ -155,7 +155,7 @@ def _get_psf_ctf( # summarise PSFs/CTFs across vertices if requested pca_var = None # variances computed only if return_pca_vars=True if mode is not None: - #mapping public mode names to internal names + # mapping public mode names to internal names _mode_map = { "max": "maxnorm", "svd": "pca", @@ -201,9 +201,7 @@ def _check_get_psf_ctf_params(mode, n_comp, return_pca_vars): """Check input parameters of _get_psf_ctf() for consistency.""" valid_modes = (None, "mean", "max", "svd") if mode not in valid_modes: - raise ValueError( - f"mode must be one of {valid_modes}, got {mode!r} instead." - ) + raise ValueError(f"mode must be one of {valid_modes}, got {mode!r} instead.") if mode in [None, "mean"] and n_comp > 1: msg = f"n_comp must be 1 for mode={mode}." raise ValueError(msg) From b2b5faa3410b4ebb08b20f6316e2a81c0a28e6d3 Mon Sep 17 00:00:00 2001 From: Famous Date: Sun, 15 Mar 2026 02:19:43 +0530 Subject: [PATCH 3/4] DOC: rename changelog to match PR number --- doc/changes/dev/{13128.bugfix.rst => 13754.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/changes/dev/{13128.bugfix.rst => 13754.bugfix.rst} (100%) diff --git a/doc/changes/dev/13128.bugfix.rst b/doc/changes/dev/13754.bugfix.rst similarity index 100% rename from doc/changes/dev/13128.bugfix.rst rename to doc/changes/dev/13754.bugfix.rst From 343cd7d463721130874fc0bcfbb04456f0c03ca1 Mon Sep 17 00:00:00 2001 From: Famous Date: Mon, 23 Mar 2026 12:48:21 +0530 Subject: [PATCH 4/4] FIX: expose sum and maxval modes in public API per reviewer feedback --- doc/changes/dev/13754.bugfix.rst | 2 +- mne/minimum_norm/resolution_matrix.py | 6 ++++-- mne/minimum_norm/tests/test_resolution_matrix.py | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/changes/dev/13754.bugfix.rst b/doc/changes/dev/13754.bugfix.rst index 158a19dfd1e..af3a76c458b 100644 --- a/doc/changes/dev/13754.bugfix.rst +++ b/doc/changes/dev/13754.bugfix.rst @@ -1 +1 @@ -Fix ``mode`` parameter in :func:`~mne.minimum_norm.get_point_spread` and :func:`~mne.minimum_norm.get_cross_talk` to correctly map public mode names (``'max'``, ``'svd'``) to internal names, and raise :class:`ValueError` for invalid mode values, by :newcontrib:`Famous077`. \ No newline at end of file +Fix ``mode`` parameter in :func:`~mne.minimum_norm.get_point_spread` and :func:`~mne.minimum_norm.get_cross_talk` to correctly map public mode names (``'max'``, ``'svd'``) to internal names, expose previously hidden modes ``'sum'`` and ``'maxval'`` in the public API, and raise :class:`ValueError` for invalid mode values, by :newcontrib:`Famous077`. \ No newline at end of file diff --git a/mne/minimum_norm/resolution_matrix.py b/mne/minimum_norm/resolution_matrix.py index c1b2187b591..ffab84c3b65 100644 --- a/mne/minimum_norm/resolution_matrix.py +++ b/mne/minimum_norm/resolution_matrix.py @@ -160,6 +160,8 @@ def _get_psf_ctf( "max": "maxnorm", "svd": "pca", "mean": "mean", + "sum": "sum", + "maxval": "maxval", } funcs, pca_var = _summarise_psf_ctf( funcs, _mode_map[mode], n_comp, return_pca_vars, nn @@ -199,10 +201,10 @@ def _get_psf_ctf( def _check_get_psf_ctf_params(mode, n_comp, return_pca_vars): """Check input parameters of _get_psf_ctf() for consistency.""" - valid_modes = (None, "mean", "max", "svd") + valid_modes = (None, "mean", "max", "svd", "sum", "maxval") if mode not in valid_modes: raise ValueError(f"mode must be one of {valid_modes}, got {mode!r} instead.") - if mode in [None, "mean"] and n_comp > 1: + if mode in [None, "mean", "sum"] and n_comp > 1: msg = f"n_comp must be 1 for mode={mode}." raise ValueError(msg) if mode != "svd" and return_pca_vars: diff --git a/mne/minimum_norm/tests/test_resolution_matrix.py b/mne/minimum_norm/tests/test_resolution_matrix.py index a3469705188..eadaf6f1d94 100644 --- a/mne/minimum_norm/tests/test_resolution_matrix.py +++ b/mne/minimum_norm/tests/test_resolution_matrix.py @@ -68,9 +68,9 @@ def test_resolution_matrix_free(src_type, fwd_volume_small): ) assert_array_almost_equal(rm_mne_free, rm_mne_free.T) # check various summary and normalisation options - for mode in [None, "mean", "max", "svd"]: + for mode in [None, "mean", "max", "svd", "sum", "maxval"]: n_comps = [1, 3] - if mode in [None, "sum", "mean"]: + if mode in [None, "mean", "sum"]: n_comps = [1] for n_comp in n_comps: for norm in [None, "max", "norm", True]: @@ -184,9 +184,9 @@ def test_resolution_matrix_fixed(): # Some arbitrary vertex numbers idx = [1, 100, 400] # check various summary and normalisation options - for mode in [None, "mean", "max", "svd"]: + for mode in [None, "mean", "max", "svd", "sum", "maxval"]: n_comps = [1, 3] - if mode in [None, "mean"]: + if mode in [None, "mean", "sum"]: n_comps = [1] for n_comp in n_comps: for norm in [None, "max", "norm", True]: