mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

mode parameter in get_cross_talk and get_point_spread does not work as intended

Open giulianogiari opened this issue 10 months ago • 2 comments

Description of the problem

Hello, i think i found i bug in the the functions get_cross_talk and get_point_spread. the mode parameter accepts, according to the documentation, one of these options: [None] | ‘mean’ | ‘max’ | ‘svd’. if mode is not None, the function _summarise_psf_ctf is called to compute a summary of the vertices. this function instead seem to accept different values for mode, namely "maxval", "maxnorm", "sum", "mean", "pca". if one uses the function get_cross_talk (or get_point_spread) with e.g., mode="svd" then, no summary across vertices is computed, resulting in an stc object of shape n_source_vertices x n_idx (if vertices are passed) or n_source_vertices x n_label_vertices (if passing a label as idx). no warning or error is raised in case of a wrong mode parameter. let me know what you think. i would be happy to fix this in case is needed.

Steps to reproduce

import mne
import numpy as np
from mne.datasets import sample
from mne.minimum_norm import (
    get_point_spread,
    make_inverse_resolution_matrix,
)

print(__doc__)

data_path = sample.data_path()
subjects_dir = data_path / "subjects"
meg_path = data_path / "MEG" / "sample"
fname_fwd = meg_path / "sample_audvis-meg-eeg-oct-6-fwd.fif"
fname_cov = meg_path / "sample_audvis-cov.fif"
fname_evo = meg_path / "sample_audvis-ave.fif"

# read forward solution
forward = mne.read_forward_solution(fname_fwd)
# forward operator with fixed source orientations
mne.convert_forward_solution(forward, surf_ori=True, force_fixed=True, copy=False)

# noise covariance matrix
noise_cov = mne.read_cov(fname_cov)

# evoked data for info
evoked = mne.read_evokeds(fname_evo, 0)

# make inverse operator from forward solution
# free source orientation
inverse_operator = mne.minimum_norm.make_inverse_operator(
    info=evoked.info, forward=forward, noise_cov=noise_cov, loose=0.0, depth=None
)

# regularisation parameter
snr = 3.0
lambda2 = 1.0 / snr**2

# compute resolution matrix for sLORETA
rm_lor = make_inverse_resolution_matrix(
    forward, inverse_operator, method="sLORETA", lambda2=lambda2
)

# get PSF for sLORETA at multiple source points
sources = np.arange(1, 10)

for mode in ["svd", "pca", "max", "maxval"]:
    stc_psf = get_point_spread(rm_lor, forward["src"], sources, mode=mode)
    print("Using mode", mode, "psf is of shape:", stc_psf.data.shape)

Link to data

No response

Expected results

Only max and svd should work, returning the summarised psf. Other mode values should return a ValueError.

Actual results

All mode values return a psf, but if svd or max all the vertices are returned.

Using mode svd psf is of shape: (7498, 9) Using mode pca psf is of shape: (7498, 1) Using mode max psf is of shape: (7498, 9) Using mode maxval psf is of shape: (7498, 1)

Additional information

reproduced on both mne 1.3.1 and 1.8.0

giulianogiari avatar Feb 25 '25 12:02 giulianogiari

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

welcome[bot] avatar Feb 25 '25 12:02 welcome[bot]

@olafhauk do you have time to look into this one?

drammock avatar Feb 25 '25 13:02 drammock