def task_select_vertices(): """Step 08: Select the vertices for which to do the analyses.""" fwd_fnames = [fname.fwd(subject=subject) for subject in subjects] fwd_r_fnames = [fname.fwd_r(subject=subject) for subject in subjects] src_fnames = [fname.src(subject=subject) for subject in subjects] pairs_fname = fname.pairs return dict(file_dep=['08_select_vertices.py'] + fwd_fnames + src_fnames, targets=fwd_r_fnames + [pairs_fname], actions=['python 08_select_vertices.py'])
def task_figures(): """Make all figures. Each figure is a sub-task.""" # Make figure 1: plot of the CSD matrices. yield dict( name='csd', task_dep=['connectivity_stats'], file_dep=[fname.epo(subject=subjects[0]), fname.csd(subject=subjects[0], condition='face')], targets=['../paper/figures/csd.pdf'], actions=['python figure_csd.py'], ) # Make figure 2: plot of the source space and forward model. yield dict( name='forward', file_dep=[fname.fwd(subject=subjects[0]), fname.fwd_r(subject=subjects[0]), fname.trans(subject=subjects[0])], targets=['../paper/figures/forward1.png', '../paper/figures/forward2.png'], actions=['python figure_forward.py'], ) # Make figure 3: grand average power maps. file_dep = [fname.ga_power_hemi(condition=cond, hemi='lh') for cond in conditions] file_dep += [fname.ga_power_hemi(condition=cond, hemi='rh') for cond in conditions] targets = ['../paper/figures/power_face_lh.png', '../paper/figures/power_face_rh.png', '../paper/figures/power_scrambled_lh.png', '../paper/figures/power_scrambled_rh.png'] targets += ['../paper/figures/power_contrast_%s-%s-lh.png' % (freq[0], freq[1]) for freq in freq_bands] yield dict( name='power', file_dep=file_dep, targets=targets, actions=['python figure_power.py'], ) # Make figure 4: plot of the functional connectivity. yield dict( name='connectivity', file_dep=[fname.ga_con(condition='pruned'), fname.ga_con(condition='parcelled')], targets=['../paper/figures/degree_lh.png', '../paper/figures/degree_rh.png', '../paper/figures/squircle.pdf'], actions=['python figure_connectivity.py'], )
def task_connectivity(): """Step 10: Compute DICS connectivity.""" for subject in subjects: fwd_r_fname = fname.fwd_r(subject=subject) csd_fnames = [] con_fnames = [] for cond in conditions: csd_fnames.append(fname.csd(subject=subject, condition=cond)) con_fnames.append(fname.con(subject=subject, condition=cond)) yield dict( name=subject, task_dep=['power'], file_dep=[fwd_r_fname, fname.pairs, '10_connectivity.py'] + csd_fnames, targets=con_fnames, actions=['python 10_connectivity.py %s' % subject], )
def task_power(): """Step 09: Compute DICS power maps.""" for subject in subjects: fwd_r_fname = fname.fwd_r(subject=subject) csd_fnames = [] stc_fnames = [] for cond in conditions + ['baseline']: csd_fnames.append(fname.csd(subject=subject, condition=cond)) stc_fnames.append(fname.power_hemi(subject=subject, condition=cond, hemi='lh')) stc_fnames.append(fname.power_hemi(subject=subject, condition=cond, hemi='rh')) yield dict( name=subject, task_dep=['select_vertices'], file_dep=[fwd_r_fname, '09_power.py'] + csd_fnames, targets=stc_fnames, actions=['python 09_power.py %s' % subject], )
from mayavi import mlab import mne from mne.bem import _fit_sphere import conpy from config import fname, subjects mne.set_log_level('ERROR') fwd = mne.read_forward_solution(fname.fwd(subject=subjects[0])) fwd_r = mne.read_forward_solution(fname.fwd_r(subject=subjects[0])) trans = fname.trans(subject=subjects[0]) fig1 = mne.viz.plot_alignment(fwd['info'], trans=trans, src=fwd_r['src'], meg='sensors', surfaces='white') fig1.scene.background = (1, 1, 1) # white fig1.children[-1].children[0].children[0].glyph.glyph.scale_factor = 0.008 mlab.view(135, 120, 0.3, [0.01, 0.015, 0.058]) mlab.savefig('../paper/figures/forward1.png', magnification=4, figure=fig1) radius, center = _fit_sphere(fwd_r['source_rr']) rad, tan1, tan2 = conpy.forward._make_radial_coord_system( fwd_r['source_rr'], center) fig2 = conpy.forward._plot_coord_system(fwd_r['source_rr'], rad, tan1, tan2, scale=0.003,
fwds.append(mne.read_forward_solution(fname.fwd(subject=subject))) # Compute the vertices that are shared across the forward operators for all # subjects. The first one we restricted ourselves, the other ones may have # dropped vertices which were too close to the inner skull surface. We use the # fsaverage brain as a reference to determine corresponding vertices across # subjects. fsaverage = mne.read_source_spaces(fname.fsaverage_src) vert_inds = conpy.select_shared_vertices(fwds, ref_src=fsaverage, subjects_dir=fname.subjects_dir) # Restrict all forward operators to the same vertices and save them. for fwd, vert_ind, subject in zip(fwds, vert_inds, subjects): fwd_r = conpy.restrict_forward_to_vertices(fwd, vert_ind) mne.write_forward_solution(fname.fwd_r(subject=subject), fwd_r, overwrite=True) # Update the forward operator of the first subject if subject == subjects[0]: fwd1 = fwd_r # Save a visualization of the restricted forward operator to the subject's # HTML report with mne.open_report(fname.report(subject=subject)) as report: fig = mne.viz.plot_alignment(fwd['info'], trans=fname.trans(subject=subject), src=fwd_r['src'], meg='sensors', surfaces='white')