Skip to content

Commit e7340a6

Browse files
committed
FIX: correct mode parameter mapping in get_point_spread and get_cross_talk
1 parent 9b14298 commit e7340a6

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

doc/changes/dev/13128.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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`.

mne/minimum_norm/resolution_matrix.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ def _get_psf_ctf(
155155
# summarise PSFs/CTFs across vertices if requested
156156
pca_var = None # variances computed only if return_pca_vars=True
157157
if mode is not None:
158+
#mapping public mode names to internal names
159+
_mode_map = {
160+
"max": "maxnorm",
161+
"svd": "pca",
162+
"mean": "mean",
163+
}
158164
funcs, pca_var = _summarise_psf_ctf(
159-
funcs, mode, n_comp, return_pca_vars, nn
165+
funcs, _mode_map[mode], n_comp, return_pca_vars, nn
160166
)
161167

162168
if not vector: # if one value per vertex requested
@@ -193,11 +199,16 @@ def _get_psf_ctf(
193199

194200
def _check_get_psf_ctf_params(mode, n_comp, return_pca_vars):
195201
"""Check input parameters of _get_psf_ctf() for consistency."""
196-
if mode in [None, "sum", "mean"] and n_comp > 1:
202+
valid_modes = (None, "mean", "max", "svd")
203+
if mode not in valid_modes:
204+
raise ValueError(
205+
f"mode must be one of {valid_modes}, got {mode!r} instead."
206+
)
207+
if mode in [None, "mean"] and n_comp > 1:
197208
msg = f"n_comp must be 1 for mode={mode}."
198209
raise ValueError(msg)
199-
if mode != "pca" and return_pca_vars:
200-
msg = "SVD variances can only be returned if mode=pca."
210+
if mode != "svd" and return_pca_vars:
211+
msg = "SVD variances can only be returned if mode='svd'."
201212
raise ValueError(msg)
202213

203214

mne/minimum_norm/tests/test_resolution_matrix.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_resolution_matrix_free(src_type, fwd_volume_small):
6868
)
6969
assert_array_almost_equal(rm_mne_free, rm_mne_free.T)
7070
# check various summary and normalisation options
71-
for mode in [None, "sum", "mean", "maxval", "maxnorm", "pca"]:
71+
for mode in [None, "mean", "max", "svd"]:
7272
n_comps = [1, 3]
7373
if mode in [None, "sum", "mean"]:
7474
n_comps = [1]
@@ -114,7 +114,7 @@ def test_resolution_matrix_free(src_type, fwd_volume_small):
114114
# There is an ambiguity in the sign flip from the PCA here.
115115
# Ideally we would use the normals to fix it, but it's not
116116
# trivial.
117-
if mode == "pca" and n_comp == 3:
117+
if mode == "svd" and n_comp == 3:
118118
stc_psf_free = abs(stc_psf_free)
119119
stc_ctf_free = abs(stc_psf_free)
120120
assert_array_almost_equal(
@@ -184,9 +184,9 @@ def test_resolution_matrix_fixed():
184184
# Some arbitrary vertex numbers
185185
idx = [1, 100, 400]
186186
# check various summary and normalisation options
187-
for mode in [None, "sum", "mean", "maxval", "maxnorm", "pca"]:
187+
for mode in [None, "mean", "max", "svd"]:
188188
n_comps = [1, 3]
189-
if mode in [None, "sum", "mean"]:
189+
if mode in [None, "mean"]:
190190
n_comps = [1]
191191
for n_comp in n_comps:
192192
for norm in [None, "max", "norm", True]:
@@ -217,7 +217,7 @@ def test_resolution_matrix_fixed():
217217
rm_mne,
218218
forward_fxd["src"],
219219
idx,
220-
mode=mode,
220+
mode="svd",
221221
n_comp=n_comp,
222222
norm="norm",
223223
return_pca_vars=True,
@@ -226,7 +226,7 @@ def test_resolution_matrix_fixed():
226226
rm_mne,
227227
forward_fxd["src"],
228228
idx,
229-
mode=mode,
229+
mode="svd",
230230
n_comp=n_comp,
231231
norm="norm",
232232
return_pca_vars=True,

0 commit comments

Comments
 (0)