コード例 #1
0
ファイル: test_bem.py プロジェクト: Eric89GXL/mne-python
def test_make_flash_bem():
    """Test computing bem from flash images."""
    tmp = _TempDir()
    bemdir = op.join(subjects_dir, 'sample', 'bem')
    flash_path = op.join(subjects_dir, 'sample', 'mri', 'flash')

    for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
        copy(op.join(bemdir, surf + '.surf'), tmp)
        copy(op.join(bemdir, surf + '.tri'), tmp)
    copy(op.join(bemdir, 'inner_skull_tmp.tri'), tmp)
    copy(op.join(bemdir, 'outer_skin_from_testing.surf'), tmp)

    # This function deletes the tri files at the end.
    try:
        make_flash_bem('sample', overwrite=True, subjects_dir=subjects_dir,
                       flash_path=flash_path)
        for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
            coords, faces = read_surface(op.join(bemdir, surf + '.surf'))
            surf = 'outer_skin_from_testing' if surf == 'outer_skin' else surf
            coords_c, faces_c = read_surface(op.join(tmp, surf + '.surf'))
            assert_equal(0, faces.min())
            assert_equal(coords.shape[0], faces.max() + 1)
            assert_allclose(coords, coords_c)
            assert_allclose(faces, faces_c)
    finally:
        for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
            remove(op.join(bemdir, surf + '.surf'))  # delete symlinks
            copy(op.join(tmp, surf + '.tri'), bemdir)  # return deleted tri
            copy(op.join(tmp, surf + '.surf'), bemdir)  # return moved surf
        copy(op.join(tmp, 'inner_skull_tmp.tri'), bemdir)
        copy(op.join(tmp, 'outer_skin_from_testing.surf'), bemdir)
    plt.close('all')
コード例 #2
0
ファイル: test_bem.py プロジェクト: yu2shi4/mne-python
def test_make_flash_bem(tmpdir):
    """Test computing bem from flash images."""
    tmp = str(tmpdir)
    bemdir = op.join(subjects_dir, 'sample', 'bem')
    flash_path = op.join(subjects_dir, 'sample', 'mri', 'flash')

    for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
        copy(op.join(bemdir, surf + '.surf'), tmp)
        copy(op.join(bemdir, surf + '.tri'), tmp)
    copy(op.join(bemdir, 'inner_skull_tmp.tri'), tmp)
    copy(op.join(bemdir, 'outer_skin_from_testing.surf'), tmp)

    # This function deletes the tri files at the end.
    try:
        make_flash_bem('sample', overwrite=True, subjects_dir=subjects_dir,
                       flash_path=flash_path)
        for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
            coords, faces = read_surface(op.join(bemdir, surf + '.surf'))
            surf = 'outer_skin_from_testing' if surf == 'outer_skin' else surf
            coords_c, faces_c = read_surface(op.join(tmp, surf + '.surf'))
            assert_equal(0, faces.min())
            assert_equal(coords.shape[0], faces.max() + 1)
            assert_allclose(coords, coords_c)
            assert_allclose(faces, faces_c)
    finally:
        for surf in ('inner_skull', 'outer_skull', 'outer_skin'):
            remove(op.join(bemdir, surf + '.surf'))  # delete symlinks
            copy(op.join(tmp, surf + '.tri'), bemdir)  # return deleted tri
            copy(op.join(tmp, surf + '.surf'), bemdir)  # return moved surf
        copy(op.join(tmp, 'inner_skull_tmp.tri'), bemdir)
        copy(op.join(tmp, 'outer_skin_from_testing.surf'), bemdir)
    plt.close('all')
コード例 #3
0
ファイル: mne_flash_bem.py プロジェクト: Eric89GXL/mne-python
def run():
    """Run command."""
    from mne.commands.utils import get_optparser

    parser = get_optparser(__file__)

    parser.add_option("-s", "--subject", dest="subject",
                      help="Subject name", default=None)
    parser.add_option("-d", "--subjects-dir", dest="subjects_dir",
                      help="Subjects directory", default=None)
    parser.add_option("-3", "--noflash30", dest="noflash30",
                      action="store_true", default=False,
                      help=("Skip the 30-degree flip angle data"),)
    parser.add_option("-n", "--noconvert", dest="noconvert",
                      action="store_true", default=False,
                      help=("Assume that the Flash MRI images have already "
                            "been converted to mgz files"))
    parser.add_option("-u", "--unwarp", dest="unwarp",
                      action="store_true", default=False,
                      help=("Run grad_unwarp with -unwarp <type> option on "
                            "each of the converted data sets"))
    parser.add_option("-o", "--overwrite", dest="overwrite",
                      action="store_true", default=False,
                      help="Write over existing .surf files in bem folder")
    parser.add_option("-v", "--view", dest="show", action="store_true",
                      help="Show BEM model in 3D for visual inspection",
                      default=False)
    parser.add_option("--copy", dest="copy",
                      help="Use copies instead of symlinks for surfaces",
                      action="store_true")
    parser.add_option("-p", "--flash-path", dest="flash_path",
                      default=None,
                      help="The directory containing flash05.mgz and "
                      "flash30.mgz files (defaults to "
                      "$SUBJECTS_DIR/$SUBJECT/mri/flash/parameter_maps")

    options, args = parser.parse_args()

    subject = options.subject
    subjects_dir = options.subjects_dir
    flash30 = not options.noflash30
    convert = not options.noconvert
    unwarp = options.unwarp
    overwrite = options.overwrite
    show = options.show
    flash_path = options.flash_path
    copy = options.copy

    if options.subject is None:
        parser.print_help()
        raise RuntimeError('The subject argument must be set')

    convert_flash_mris(subject=subject, subjects_dir=subjects_dir,
                       flash30=flash30, convert=convert, unwarp=unwarp,
                       verbose=True)
    make_flash_bem(subject=subject, subjects_dir=subjects_dir,
                   overwrite=overwrite, show=show, flash_path=flash_path,
                   copy=copy, verbose=True)
コード例 #4
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser

    parser = get_optparser(__file__)

    parser.add_option("-s", "--subject", dest="subject",
                      help="Subject name", default=None)
    parser.add_option("-d", "--subjects-dir", dest="subjects_dir",
                      help="Subjects directory", default=None)
    parser.add_option("-3", "--noflash30", dest="noflash30",
                      action="store_true", default=False,
                      help=("Skip the 30-degree flip angle data"),)
    parser.add_option("-n", "--noconvert", dest="noconvert",
                      action="store_true", default=False,
                      help=("Assume that the Flash MRI images have already "
                            "been converted to mgz files"))
    parser.add_option("-u", "--unwarp", dest="unwarp",
                      action="store_true", default=False,
                      help=("Run grad_unwarp with -unwarp <type> option on "
                            "each of the converted data sets"))
    parser.add_option("-o", "--overwrite", dest="overwrite",
                      action="store_true", default=False,
                      help="Write over existing .surf files in bem folder")
    parser.add_option("-v", "--view", dest="show", action="store_true",
                      help="Show BEM model in 3D for visual inspection",
                      default=False)
    parser.add_option("-p", "--flash-path", dest="flash_path",
                      default=None,
                      help="The directory containing flash05.mgz and "
                      "flash30.mgz files (defaults to "
                      "$SUBJECTS_DIR/$SUBJECT/mri/flash/parameter_maps")

    options, args = parser.parse_args()

    subject = options.subject
    subjects_dir = options.subjects_dir
    flash30 = not options.noflash30
    convert = not options.noconvert
    unwarp = options.unwarp
    overwrite = options.overwrite
    show = options.show
    flash_path = options.flash_path

    if options.subject is None:
        parser.print_help()
        raise RuntimeError('The subject argument must be set')

    convert_flash_mris(subject=subject, subjects_dir=subjects_dir,
                       flash30=flash30, convert=convert, unwarp=unwarp,
                       verbose=True)
    make_flash_bem(subject=subject, subjects_dir=subjects_dir,
                   overwrite=overwrite, show=show, flash_path=flash_path,
                   verbose=True)
コード例 #5
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser

    parser = get_optparser(__file__)

    parser.add_option("-s", "--subject", dest="subject",
                      help="Subject name", default=None)
    parser.add_option("-d", "--subjects-dir", dest="subjects_dir",
                      help="Subjects directory", default=None)
    parser.add_option("-3", "--noflash30", dest="noflash30",
                      action="store_true", default=False,
                      help=("Skip the 30-degree flip angle data"),)
    parser.add_option("-n", "--noconvert", dest="noconvert",
                      action="store_true", default=False,
                      help=("Assume that the Flash MRI images have already "
                            "been converted to mgz files"))
    parser.add_option("-u", "--unwarp", dest="unwarp",
                      action="store_true", default=False,
                      help=("Run grad_unwarp with -unwarp <type> option on "
                            "each of the converted data sets"))
    parser.add_option("-o", "--overwrite", dest="overwrite",
                      action="store_true", default=False,
                      help="Write over existing .surf files in bem folder")
    parser.add_option("-v", "--view", dest="show", action="store_true",
                      help="Show BEM model in 3D for visual inspection",
                      default=False)

    options, args = parser.parse_args()

    subject = options.subject
    subjects_dir = options.subjects_dir
    flash30 = not options.noflash30
    convert = not options.noconvert
    unwarp = options.unwarp
    overwrite = options.overwrite
    show = options.show

    if options.subject is None:
        parser.print_help()
        raise RuntimeError('The subject argument must be set')

    convert_flash_mris(subject=subject, subjects_dir=subjects_dir,
                       flash30=flash30, convert=convert, unwarp=unwarp)
    make_flash_bem(subject=subject, subjects_dir=subjects_dir,
                   overwrite=overwrite, show=show, flash_path='.')
def run_forward(subject, session=None):
    print("Processing subject: %s" % subject)

    # Construct the search path for the data file. `sub` is mandatory
    subject_path = op.join('sub-{}'.format(subject))
    # `session` is optional
    if session is not None:
        subject_path = op.join(subject_path, 'ses-{}'.format(session))

    subject_path = op.join(subject_path, config.kind)

    bids_basename = make_bids_basename(subject=subject,
                                       session=session,
                                       task=config.task,
                                       acquisition=config.acq,
                                       run=None,
                                       processing=config.proc,
                                       recording=config.rec,
                                       space=config.space)

    fpath_deriv = op.join(config.bids_root, 'derivatives',
                          config.PIPELINE_NAME, subject_path)
    fname_evoked = \
        op.join(fpath_deriv, bids_basename + '-ave.fif')

    print("Input: ", fname_evoked)

    fname_trans = \
        op.join(fpath_deriv, 'sub-{}'.format(subject) + '-trans.fif')

    fname_fwd = \
        op.join(fpath_deriv, bids_basename + '-fwd.fif')

    print("Output: ", fname_fwd)

    # Find the raw data file
    # XXX : maybe simplify
    bids_basename = make_bids_basename(subject=subject,
                                       session=session,
                                       task=config.task,
                                       acquisition=config.acq,
                                       run=config.runs[0],
                                       processing=config.proc,
                                       recording=config.rec,
                                       space=config.space)

    data_dir = op.join(config.bids_root, subject_path)
    search_str = op.join(data_dir, bids_basename) + '_' + config.kind + '*'
    fnames = sorted(glob.glob(search_str))
    fnames = [f for f in fnames if op.splitext(f)[1] in mne_bids_readers]

    if len(fnames) >= 1:
        bids_fname = fnames[0]
    elif len(fnames) == 0:
        raise ValueError('Could not find input data file matching: '
                         '"{}"'.format(search_str))

    bids_fname = op.basename(bids_fname)

    mne.gui.coregistration()
    trans = get_head_mri_trans(bids_fname=bids_fname,
                               bids_root=config.bids_root)

    mne.write_trans(fname_trans, trans)

    # create the boundary element model (BEM) once
    from mne.bem import make_watershed_bem, make_flash_bem

    if 'eeg' in config.ch_types or config.kind == 'eeg':
        make_flash_bem(subject, subjects_dir=subjects_dir, overwrite=True)
    else:
        mne.bem.make_watershed_bem(subject,
                                   subjects_dir=subjects_dir,
                                   overwrite=True)