示例#1
0
文件: dodo.py 项目: CoastSunny/conpy
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'])
示例#2
0
文件: dodo.py 项目: CoastSunny/conpy
def task_forward():
    """Step 07: Compute forward operators for each subject."""
    for subject in subjects:
        fwd_fname = fname.fwd(subject=subject)
        src_fname = fname.src(subject=subject)

        yield dict(
            name=subject,
            file_dep=[fname.fsaverage_src, '07_forward.py'],
            targets=[fwd_fname, src_fname],
            actions=['python 07_forward.py %s' % subject],
        )
示例#3
0
def task_dipole():
    """Step 5: Dipole source estimate (golden standard)"""
    for subject in subjects:
        yield dict(
            name=str(subject),
            file_dep=[
                fname.epochs(subject=subject),
                fname.fwd(subject=subject), '05_dipole.py'
            ],
            targets=[fname.ecd(subject=subject)],
            actions=[f'ipython 05_dipole.py {subject:d}'],
        )
示例#4
0
def task_forward():
    """Step 1: setup the forward solution"""
    for subject in subjects:
        yield dict(
            name=str(subject),
            file_dep=[
                fname.raw(subject=subject),
                fname.trans(subject=subject), '01_setup_forward_solution.py'
            ],
            targets=[fname.src(subject=subject),
                     fname.fwd(subject=subject)],
            actions=[f'ipython 01_setup_forward_solution.py {subject:d}'],
        )
示例#5
0
文件: dodo.py 项目: u01ai11/conpy
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'],
    )
示例#6
0
def task_dics():
    """Step 7: DICS source estimate"""
    for subject in subjects:
        yield dict(
            name=str(subject),
            file_dep=[
                fname.epochs_long(subject=subject),
                fname.fwd(subject=subject),
                fname.ecd(subject=subject), '07_dics.py'
            ],
            targets=[
                fname.stc_dics(subject=subject),
                fname.nii_dics(subject=subject)
            ],
            actions=[f'ipython 07_dics.py {subject:d}'],
        )
示例#7
0
def task_lcmv():
    """Step 6: LCMV source estimate"""
    for subject in subjects:
        yield dict(
            name=str(subject),
            file_dep=[
                fname.epochs(subject=subject),
                fname.fwd(subject=subject),
                fname.ecd(subject=subject), '06_lcmv.py'
            ],
            targets=[
                fname.stc_lcmv(subject=subject),
                fname.nii_lcmv(subject=subject)
            ],
            actions=[f'ipython 06_lcmv.py {subject:d}'],
        )
示例#8
0
def task_mne():
    """Step 8: MNE source estimate"""
    for subject in subjects:
        yield dict(
            name=str(subject),
            file_dep=[
                fname.epochs(subject=subject),
                fname.fwd(subject=subject),
                fname.ecd(subject=subject), '08_mne.py'
            ],
            targets=[
                fname.stc_mne(subject=subject),
                fname.nii_mne(subject=subject)
            ],
            actions=[f'ipython 08_mne.py {subject:d}'],
        )
                                             n_jobs=n_jobs,
                                             decim=5)
# ERS activity starts at 0.5 seconds after stimulus onset
csd_ers = mne.time_frequency.csd_morlet(epochs,
                                        freqs,
                                        tmin=0.2,
                                        tmax=1.0,
                                        n_jobs=n_jobs,
                                        decim=5)

csd = csd.mean()
csd_baseline = csd_baseline.mean()
csd_ers = csd_ers.mean()

# Compute DICS beamformer to localize ERS
fwd = mne.read_forward_solution(fname.fwd(subject=subject))

info, fwd, csd = mne.channels.equalize_channels([epochs.info, fwd, csd])
inv = mne.beamformer.make_dics(info,
                               fwd,
                               csd,
                               reduce_rank=True,
                               pick_ori='max-power',
                               inversion='matrix',
                               reg=reg[subject]['dics'])

# Compute source power
stc_baseline, _ = mne.beamformer.apply_dics_csd(csd_baseline, inv)
stc_ers, _ = mne.beamformer.apply_dics_csd(csd_ers, inv)
stc_baseline.subject = fname.subject_id(subject=subject)
stc_ers.subject = fname.subject_id(subject=subject)
from config import fname

# Handle command line arguments
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('subject', metavar='sub###', type=int, help='The subject to process')
args = parser.parse_args()
subject = args.subject
print('Processing subject:', subject)

info = mne.io.read_info(fname.raw(subject=subject, run=1))

bem = mne.make_bem_model(fname.subject_id(subject=subject), ico=4, subjects_dir=fname.subjects_dir,
                         conductivity=[0.3, 0.006, 0.3])
bem_sol = mne.make_bem_solution(bem)
mne.write_bem_solution(fname.bem(subject=subject), bem_sol)
src = mne.setup_volume_source_space(subject=fname.subject_id(subject=subject), bem=bem_sol, subjects_dir=fname.subjects_dir)
fwd = mne.make_forward_solution(info=info, trans=fname.trans(subject=subject), src=src, bem=bem_sol, eeg=True)

# Save things
src.save(fname.src(subject=subject), overwrite=True)
mne.write_forward_solution(fname.fwd(subject=subject), fwd, overwrite=True)

# Visualize source space and MEG sensors
fig = mne.viz.plot_alignment(info=info, trans=fname.trans(subject=subject), subject=fname.subject_id(subject=subject),
                             subjects_dir=fname.subjects_dir, meg='sensors',
                             src=src, bem=bem_sol)
mlab.view(138, 73, 0.6, [0.02, 0.01, 0.03])
with mne.open_report(fname.report(subject=subject)) as report:
    report.add_figs_to_section(fig, 'Source space and MEG sensors', 'Source level', replace=True)
    report.save(fname.report_html(subject=subject), overwrite=True, open_browser=False)
示例#11
0
import numpy as np
import mne
import conpy
from mayavi import mlab
mlab.options.offscreen = True  # Don't open a window when rendering figure

from config import fname, subjects, max_sensor_dist, min_pair_dist

# Be verbose
mne.set_log_level('INFO')

print('Restricting source spaces...')
# Restrict the forward operator of the first subject to vertices that are close
# to the sensors.
fwd1 = mne.read_forward_solution(fname.fwd(subject=subjects[0]))
fwd1 = conpy.restrict_forward_to_sensor_range(fwd1, max_sensor_dist)

# Load the rest of the forward operators
fwds = [fwd1]
for subject in subjects[1:]:
    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,