Example #1
0
def test_dig_mri_distances(dig_kinds, exclude, count, bounds, outliers):
    """Test the trans obtained by coregistration."""
    info = read_info(fname_raw)
    dists = dig_mri_distances(info, fname_trans, 'sample', subjects_dir,
                              dig_kinds=dig_kinds, exclude_frontal=exclude)
    assert dists.shape == (count,)
    assert bounds[0] < np.mean(dists) < bounds[1]
    assert np.sum(dists > 0.03) == outliers
                             trans=trans_fname,
                             subject='sample',
                             subjects_dir=subjects_dir,
                             surfaces='head-dense',
                             show_axes=True,
                             dig=True,
                             eeg=[],
                             meg='sensors',
                             coord_frame='meg')
mne.viz.set_3d_view(fig, 45, 90, distance=0.6, focalpoint=(0., 0., 0.))
print('Distance from head origin to MEG origin: %0.1f mm' %
      (1000 * np.linalg.norm(raw.info['dev_head_t']['trans'][:3, 3])))
print('Distance from head origin to MRI origin: %0.1f mm' %
      (1000 * np.linalg.norm(trans['trans'][:3, 3])))
dists = mne.dig_mri_distances(raw.info,
                              trans,
                              'sample',
                              subjects_dir=subjects_dir)
print('Distance from %s digitized points to head surface: %0.1f mm' %
      (len(dists), 1000 * np.mean(dists)))

###############################################################################
# Coordinate frame definitions
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# .. raw:: html
#
#    <style>
#    .pink {color:DarkSalmon; font-weight:bold}
#    .blue {color:DeepSkyBlue; font-weight:bold}
#    .gray {color:Gray; font-weight:bold}
#    .magenta {color:Magenta; font-weight:bold}
#    .purple {color:Indigo; font-weight:bold}
Example #3
0
def gen_forwards(p, subjects, structurals, run_indices):
    """Generate forward solutions

    Can only complete successfully once coregistration is performed
    (usually in mne_analyze).

    Parameters
    ----------
    p : instance of Parameters
        Analysis parameters.
    subjects : list of str
        Subject names to analyze (e.g., ['Eric_SoP_001', ...]).
    structurals : list (of str or None)
        The structural data names for each subject (e.g., ['AKCLEE_101', ...]).
        If None, a spherical BEM and volume grid space will be used.
    run_indices : array-like | None
        Run indices to include.
    """
    for si, subj in enumerate(subjects):
        struc = structurals[si]
        fwd_dir = op.join(p.work_dir, subj, p.forward_dir)
        if not op.isdir(fwd_dir):
            os.mkdir(fwd_dir)
        raw_fname = get_raw_fnames(p, subj, 'sss', False, False,
                                   run_indices[si])[0]
        info = read_info(raw_fname)
        bem, src, trans, bem_type = _get_bem_src_trans(p, info, subj, struc)
        if not getattr(p, 'translate_positions', True):
            raise RuntimeError('Not translating positions is no longer '
                               'supported')
        print('  Creating forward solution(s) using a %s for %s...' %
              (bem_type, subj),
              end='')
        # XXX Don't actually need to generate a different fwd for each inv
        # anymore, since all runs are included, but changing the filename
        # would break a lot of existing pipelines :(
        try:
            subjects_dir = get_subjects_dir(p.subjects_dir, raise_error=True)
            subject = src[0]['subject_his_id']
            dist = dig_mri_distances(info,
                                     trans,
                                     subject,
                                     subjects_dir=subjects_dir)
        except Exception as exp:
            # old MNE or bad args
            print(' (dig<->MRI unknown: %s)' % (str(exp)[:20] + '...', ))
        else:
            dist = np.median(dist)
            print(' (dig<->MRI %0.1f mm)' % (1000 * dist, ))
            if dist > 5:
                warnings.warn(
                    '%s dig<->MRI distance %0.1f mm could indicate a problem '
                    'with coregistration, check coreg' %
                    (subject, 1000 * dist))
        fwd_name = get_cov_fwd_inv_fnames(p, subj, run_indices[si])[1][0]
        fwd = make_forward_solution(info,
                                    trans,
                                    src,
                                    bem,
                                    n_jobs=p.n_jobs,
                                    mindist=p.fwd_mindist)
        write_forward_solution(fwd_name, fwd, overwrite=True)