Hi everyone,
I want to calculate a spatio-temporal permutation cluster test on my data in source space, but struggle to get the necessary adjacency. As far as I can tell, the problem is that we use a source space where the medial wall is excluded, i.e. the source space was restricted to all labels but the “???” label of the Glasser atlas.
The code to get the adjacency is:
import mne
src = mne.read_source_spaces('fsaverage-oct6-restricted-src.fif')
adjacency = mne.spatial_src_adjacency(src)
Which gives me an error “ValueError: zero-size array to reduction operation maximum which has no identity”.
The full traceback is this:
Traceback (most recent call last):
Cell In[3], line 2
adjacency = mne.spatial_src_adjacency(src)
File :12 in spatial_src_adjacency
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/source_estimate.py:3257 in spatial_src_adjacency
return spatio_temporal_src_adjacency(src, 1, dist)
File :12 in spatio_temporal_src_adjacency
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/source_estimate.py:3131 in spatio_temporal_src_adjacency
adjacency = _spatio_temporal_src_adjacency_surf(src, n_times)
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/source_estimate.py:3065 in _spatio_temporal_src_adjacency_surf
adjacency = spatio_temporal_tris_adjacency(tris, n_times)
File :12 in spatio_temporal_tris_adjacency
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/source_estimate.py:3184 in spatio_temporal_tris_adjacency
edges = mesh_edges(tris)
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/surface.py:1713 in mesh_edges
return _mesh_edges(tris=tris)
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/mne/surface.py:1718 in _mesh_edges
if np.max(tris) > len(np.unique(tris)):
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3199 in max
return _wrapreduction(a, np.maximum, ‘max’, axis, None, out,
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:84 in _wrapreduction
return reduction(axis=axis, out=out, **passkwargs)
File ~/miniconda3/envs/mne1.9/lib/python3.12/site-packages/numpy/_core/_methods.py:45 in _amax
return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity
If I use a full, non-restricted source space, it runs without errors.
Any ideas on how to proceed with this without using a full source space?
I am using MNE Version 1.9.0 on Ubuntu 24.03
Thanks in advance!
Laura
In case it’s relevant, here’s the code I used to create the source spaces:
import mne
subjects_dir = 'path/subjects/'
#%% src and bem
# setup source space
src = mne.setup_source_space('fsaverage',spacing='oct6')
mne.write_source_spaces(subjects_dir+'fsaverage/fsaverage-oct6-src.fif', src)
# create bem surfaces
mne.bem.make_scalp_surfaces('fsaverage')
mne.bem.make_watershed_bem('fsaverage')
# bem model for data with eeg
model = mne.make_bem_model('fsaverage', ico=4, conductivity=(0.3, 0.006, 0.3), subjects_dir=None, verbose=None)
bem = mne.make_bem_solution(model)
mne.write_bem_solution(subjects_dir+'fsaverage/fsaverage-bem-sol.fif', bem)
#%% creat fwd solution
# restrict fwd to all labels except medial wall --> save fwd.src as template source space
# use random data set to create source space
src = mne.read_source_spaces(subjects_dir+'fsaverage/fsaverage-oct6-src.fif')
epo = mne.read_epochs(subjects_dir+'/Subj01/Subj01_1-epo.fif')
bem = mne.read_bem_solution(subjects_dir+'fsaverage/fsaverage-bem-sol.fif')
trans = subjects_dir+'/Subj01/Subj01_1-trans.fif'
fwd = mne.make_forward_solution(epo.info, trans, src, bem)
fs_labels = mne.read_labels_from_annot(subject='fsaverage', parc='HCPMMP1', subjects_dir=subjects_dir)
# restrict to all labels apart from the medial walls ('???')
labels = fs_labels[2:] # '???' for lh and rh are the first two ones, so exclude them
fwd = mne.forward.restrict_forward_to_label(fwd, labels)
src_restricted = fwd['src']
mne.write_source_spaces(subjects_dir+'fsaverage/fsaverage-oct6-restricted-src.fif', src_restricted)