# # We need a matching forward solution and inverse operator to compute # resolution matrices for different methods. data_path = sample.data_path() subjects_dir = data_path + '/subjects' fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif' fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-fixed-inv.fif' forward = mne.read_forward_solution(fname_fwd) # Convert forward solution to fixed source orientations mne.convert_forward_solution( forward, surf_ori=True, force_fixed=True, copy=False) inverse_operator = read_inverse_operator(fname_inv) # Compute resolution matrices for MNE rm_mne = make_inverse_resolution_matrix(forward, inverse_operator, method='MNE', lambda2=1. / 3.**2) src = inverse_operator['src'] del forward, inverse_operator # save memory # %% # Read and organise labels for cortical parcellation # -------------------------------------------------- # # Get labels for FreeSurfer 'aparc' cortical parcellation with 34 labels/hemi labels = mne.read_labels_from_annot('sample', parc='aparc', subjects_dir=subjects_dir) n_labels = len(labels) label_colors = [label.color for label in labels] # First, we reorder the labels based on their location in the left hemi label_names = [label.name for label in labels] lh_labels = [name for name in label_names if name.endswith('lh')]
# 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., depth=None) # regularisation parameter snr = 3.0 lambda2 = 1.0 / snr**2 method = 'MNE' # can be 'MNE' or 'sLORETA' # compute resolution matrix for sLORETA rm_lor = make_inverse_resolution_matrix(forward, inverse_operator, method='sLORETA', lambda2=lambda2) # get PSF and CTF for sLORETA at one vertex sources = [1000] stc_psf = get_point_spread(rm_lor, forward['src'], sources, norm=True) stc_ctf = get_cross_talk(rm_lor, forward['src'], sources, norm=True) del rm_lor ############################################################################## # Visualize # --------- # PSF:
noise_cov=noise_cov, loose=0., depth=None) # regularisation parameter snr = 3.0 lambda2 = 1.0 / snr**2 # %% # MNE # --- # Compute resolution matrices, peak localisation error (PLE) for point spread # functions (PSFs), spatial deviation (SD) for PSFs: rm_mne = make_inverse_resolution_matrix(forward, inverse_operator, method='MNE', lambda2=lambda2) ple_mne_psf = resolution_metrics(rm_mne, inverse_operator['src'], function='psf', metric='peak_err') sd_mne_psf = resolution_metrics(rm_mne, inverse_operator['src'], function='psf', metric='sd_ext') del rm_mne # %% # dSPM # ---- # Do the same for dSPM:
# Read forward solution forward = mne.read_forward_solution(fname_fwd) # Convert to fixed source orientations forward = mne.convert_forward_solution(forward, surf_ori=True, force_fixed=True) # Read inverse operator inverse_operator = read_inverse_operator(fname_inv) # Compute resolution matrices for MNE and sLORETA lambda2 = 1. / 3.**2 method = 'MNE' rm_mne = make_inverse_resolution_matrix(forward, inverse_operator, method=method, lambda2=lambda2) method = 'sLORETA' rm_lor = make_inverse_resolution_matrix(forward, inverse_operator, method=method, lambda2=lambda2) ############################################################################### # Read and organise labels for cortical parcellation # -------------------------------------------------- # # Get labels for FreeSurfer 'aparc' cortical parcellation with 34 labels/hemi labels = mne.read_labels_from_annot('sample', parc='aparc', subjects_dir=subjects_dir)
meth_str = '%s_%s' % ('LCMV', cov_lat_str) functions_and_metrics(resmat, fwd_use['src'], functions, metrics, subject, meth_str) # Save some PSFs filetext = meth_str + '_PSFs' fname = fname_stc = C.fname_STC(C, C.resolution_subdir, subject, filetext) save_resolution_matrix(fname, resmat, invop['src'], gap=10) else: # for MNE-type estimators # Compute resolution matrix resmat = make_inverse_resolution_matrix(fwd_use, invop, method=method, lambda2=lambda2) functions_and_metrics(resmat, fwd_use['src'], functions, metrics, subject, meth_name) # Save some PSFs filetext = meth_name + '_PSFs' fname = fname_stc = C.fname_STC(C, C.resolution_subdir, subject, filetext) save_resolution_matrix(fname, resmat, invop['src'], gap=10)
raw_fname = data_path + meg + 'block_SD_tsss_raw.fif' info = mne.io.read_info(raw_fname) # make an inverse operator inv_op = make_inverse_operator(info, fwd, noise_cov=cov, fixed=True, loose=0., depth=None, verbose=None) # # Reading inverse operator (from one task) # inv_fname = data_path + meg + inv_op_name[0] # inv_op = read_inverse_operator(inv_fname) # Compute resolution matrix for MNE lambda2 = 1. / 3.**2 method = 'MNE' rm = make_inverse_resolution_matrix(fwd, inv_op, method=method, lambda2=lambda2) # Source space used for inverse operator src = inv_op['src'] # Compute first SVD component across PSFs within labels # Note the differences in explained variance, probably due to different # spatial extents of labels n_comp = 5 stcs_psf, pca_vars = get_point_spread( rm, src, labels, mode='pca', n_comp=n_comp, norm=None, return_pca_vars=True) morph = mne.compute_source_morph( src=inv_op['src'], subject_from\ = stcs_psf[0].subject , subject_to = C.subject_to , spacing = \