- MNE version: 1.3.1
- operating system: macOS 10.14.6
I’m working on permutation t-test on my source-level data and encountering a problem of unequal dimensions between the fsaverage and the estimated source data.
In details, I applied LCMV function to estimate source data and created a SourceMorph object fsaverage-vol-5-src.fif
to morph individual source data into a common space. Following the official tutorial, I arranged each individual source data into a matrix (n_subj*n_time*n_vertices)
and prepared a adjacency matrix of fsaverage. In the end, I ran spatio_temporal_cluster_1samp_test
with the matrix of source data and the adjacency matrix. However, it ended up showing that ValueError: adjacency (len 20484) must be of the correct size, i.e. be equal to or evenly divide the number of tests (307209).
The following is a part of my code:
data_path = os.path.join('/Applications/freesurfer/7.3.2')
megdata_path = '/Users/mymac/MEG/'
subjects_dir = os.path.join(data_path, 'subjects')
# a part of source estimates
for subj_idx in range(1, 25):
data_cov = mne.compute_covariance(erf[cond1], tmin=0.01, tmax=0.4, method='empirical')
noise_cov = mne.compute_covariance(erf[cond1], tmin=-0.2, tmax=0.0, method='empirical')
data_cov.plot(epochs.info)
# loading forward solution of volumetric source spaces
forward = mne.read_forward_solution(input_path+subj+'/epochs_fwd.fif')
# initializing a LCMV filter
filters = make_lcmv(erf[cond1].info, forward, data_cov, reg=0.05,
noise_cov=noise_cov, pick_ori='max-power',
weight_norm='nai', rank=None)
# applying the LCMV filter to ERF data
stc = apply_lcmv(erf[cond1], filters)
stc.save(input_path+subj+'/erf_cond1', ftype='h5', overwrite=True)
# morphing individual source data into a common space
src_fs = mne.read_source_spaces(subjects_dir + '/fsaverage/bem/fsaverage-vol-5-src.fif')
stc_fs = mne.compute_source_morph(
forward['src'], subject_from=subject, subjects_dir=subjects_dir, src_to=src_fs, verbose=True
).apply(stc)
stc_fs.save(input_path+subj+'/erf_cond1_fsaverage', ftype='h5', overwrite=True)
# a part of permutation t-test with spatio-temporal clustering
X = []
for subj_idx in range(1, 25):
subj = 's'+str(subj_idx).zfill(2)
stcs_cond1 = mne.read_source_estimate(megdata_path+subj+'/erf_cond1_fsaverage-stc.h5')
stcs_cond2 = mne.read_source_estimate(megdata_path+subj+'/erf_cond2_fsaverage-stc.h5')
if subj_idx == 1:
X = np.concatenate((stcs_cond1.reshape((stcs_cond1.shape[0], stcs_cond1.shape[1], 1, 1)), stcs_cond2.reshape((stcs_cond1.shape[0], stcs_cond1.shape[1], 1, 1))), axis=3)
else:
temp_X = np.concatenate((stcs_cond1.reshape((stcs_cond1.shape[0], stcs_cond1.shape[1], 1, 1)), stcs_cond2.reshape((stcs_cond1.shape[0], stcs_cond1.shape[1], 1, 1))), axis=3)
X = np.concatenate((X, temp_X), axis=2)
X = X[:, :, :, 0] - X[:, :, :, 1]
X = np.transpose(X, [2, 1, 0])
print(X.shape) # -> (24, 21, 14629)
print("Computing adjacency.")
src = mne.read_source_spaces(subjects_dir + '/fsaverage/bem/fsaverage-vol-5-src.fif')
adjacency = mne.spatial_src_adjacency(src) # -> 20484
p_threshold = 0.001
df = 23
t_threshold = stats.distributions.t.ppf(1 - p_threshold / 2, df=df)
# ERROR HERE.
T_obs, clusters, cluster_p_values, H0 = clu = spatio_temporal_cluster_1samp_test(
X,
adjacency=adjacency,
n_jobs=None,
threshold=t_threshold,
buffer_size=None,
verbose=True,
)
The SourceMorph object indeed morphed source-level data into a common source space and made the morphed n_vertices equal across all participants (14629). However, the n_vertices of morphed data seems different with that of fsaverage data (20484). So, it may result in the error message that the unequal number between adjacency and source data when we do a permutation t-test. Does anyone have any similar experiences or suggests?