mne-tools / mne-tools/mne-python
mode parameter in get_cross_talk and get_point_spread does not work as intended
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The relevant entry points are get_cross_talk, get_point_spread, and _summarise_psf_ctf in mne/minimum_norm/resolution_matrix.py. Start by comparing the documented mode values with the summarizer's accepted values and reproduce the supplied loop; done means valid modes summarize correctly and invalid values raise ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100