def task_forward(): """Step 07: Compute forward operators for each subject.""" for subject in subjects: epo_fname = fname.epo(subject=subject) fwd_fname = fname.fwd(subject=subject) src_fname = fname.src(subject=subject) yield dict( name=subject, task_dep=['fsaverage_src'], file_dep=[fname.fsaverage_src, epo_fname, '07_forward.py'], targets=[fwd_fname, src_fname], actions=['python 07_forward.py %s' % subject], )
def task_csd(): """Step 05: Compute cross-spectral density (CSD) matrices""" for subject in subjects: epo_fname = fname.epo(subject=subject) csd_fnames = [fname.csd(subject=subject, condition=cond) for cond in conditions + ['baseline']] yield dict( name=subject, task_dep=['epochs'], file_dep=[epo_fname, '05_csd.py'], targets=csd_fnames, actions=['python 05_csd.py %s' % subject], )
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_epochs(): """Step 04: Cut the data into epochs""" for subject in subjects: filt_fnames = [fname.filt(subject=subject, run=run, fmin=bandpass_fmin, fmax=bandpass_fmax) for run in range(1, 7)] ica_fname = fname.ica(subject=subject) epo_fname = fname.epo(subject=subject) yield dict( name=subject, task_dep=['ica'], file_dep=filt_fnames + [ica_fname, '04_epochs.py'], targets=[epo_fname], actions=['python 04_epochs.py %s' % subject], )
from config import (fname, n_jobs, csd_tmin, csd_tmax, freq_bands, conditions, get_report, save_report) # Be verbose mne.set_log_level('INFO') # Handle command line arguments parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('subject', metavar='sub###', help='The subject to process') args = parser.parse_args() subject = args.subject print('Processing subject:', subject) # Read the epochs print('Reading epochs...') epochs = mne.read_epochs(fname.epo(subject=subject)) report = get_report(subject) # Suppress warning about wavelet length. warnings.simplefilter('ignore') # Individual frequencies to estimate the CSD for fmin = freq_bands[0][0] fmax = freq_bands[-1][1] frequencies = np.arange(fmin, fmax + 1, 2) # Compute CSD matrices for each frequency and each condition. for condition in conditions: print('Condition:', condition) # Remove the mean during the time interval for which we compute the CSD
preload=True) # Save evoked plot to the report with mne.open_report(fname.report(subject=subject)) as report: report.add_figs_to_section([epochs.average().plot(show=False)], ['Evoked without ICA'], section='Sensor-level', replace=True) report.save(fname.report_html(subject=subject), overwrite=True) # Apply ICA to the epochs, dropping components that correlate with ECG and EOG ica.apply(epochs) # Drop epochs that have too large signals (most likely due to the subject # moving or muscle artifacts) epochs.drop_bad(reject) print(' Dropped %0.1f%% of epochs' % (epochs.drop_log_stats(), )) print(' Writing to disk') epochs.save(fname.epo(subject=subject)) # Save evoked plot to report with mne.open_report(fname.report(subject=subject)) as report: report.add_figs_to_section([epochs.average().plot(show=False)], ['Evoked with ICA'], section='Sensor-level', replace=True) report.save(fname.report_html(subject=subject), overwrite=True, open_browser=False)
from matplotlib import pyplot as plt import mne from mne.time_frequency import read_csd, pick_channels_csd from config import fname, subjects, freq_bands info = mne.io.read_info(fname.epo(subject=subjects[0])) grads = [info['ch_names'][ch] for ch in mne.pick_types(info, meg='grad')] csd = read_csd(fname.csd(subject=subjects[0], condition='face')) csd = pick_channels_csd(csd, grads) csd = csd.mean([f[0] for f in freq_bands], [f[1] for f in freq_bands]) # Plot theta, alpha, low beta csd[:3].plot(info, n_cols=3, show=False) plt.savefig('../paper/figures/csd1.pdf', bbox_inches='tight') # Plot high beta 1, high beta 2 and low gamma csd[3:].plot(info, n_cols=3, show=False) plt.savefig('../paper/figures/csd2.pdf', bbox_inches='tight')