def _setup_args(info):
    """Helper to test_as_meg_type_evoked."""
    coils = _create_meg_coils(info['chs'], 'normal', info['dev_head_t'])
    int_rad, noise, lut_fun, n_fact = _setup_dots('fast', coils, 'meg')
    my_origin = np.array([0., 0., 0.04])
    args_dict = dict(intrad=int_rad, volume=False, coils1=coils, r0=my_origin,
                     ch_type='meg', lut=lut_fun, n_fact=n_fact)
    return args_dict
def _setup_args(info):
    """Helper to test_as_meg_type_evoked."""
    coils = _create_coils(info["chs"], FIFF.FWD_COIL_ACCURACY_NORMAL, info["dev_head_t"], "meg")
    my_origin, int_rad, noise, lut_fun, n_fact = _setup_dots("fast", coils, "meg")
    args_dict = dict(
        intrad=int_rad, volume=False, coils1=coils, r0=my_origin, ch_type="meg", lut=lut_fun, n_fact=n_fact
    )
    return args_dict
Example #3
0
 def _compute_dots(info, mode='fast'):
     """Compute all-to-all dots.
     """
     templates = _read_coil_defs()
     coils = _create_meg_coils(info['chs'], 'normal', info['dev_head_t'],
                               templates)
     my_origin = _check_origin((0., 0., 0.04), info_from)
     int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils, 'meg')
     self_dots = _do_self_dots(int_rad, False, coils, my_origin, 'meg',
                               lut_fun, n_fact, n_jobs=1)
     cross_dots = _do_cross_dots(int_rad, False, coils, coils,
                                 my_origin, 'meg', lut_fun, n_fact).T
     return self_dots, cross_dots
Example #4
0
def _fast_map_meg_channels(inst, pick_from, pick_to, mode='fast'):
    from mne.io.pick import pick_info
    from mne.forward._field_interpolation import _setup_dots
    from mne.forward._field_interpolation import _compute_mapping_matrix
    from mne.forward._make_forward import _create_meg_coils, _read_coil_defs
    from mne.forward._lead_dots import _do_self_dots, _do_cross_dots
    from mne.bem import _check_origin

    miss = 1e-4  # Smoothing criterion for MEG

    def _compute_dots(info, mode='fast'):
        """Compute all-to-all dots.
        """
        templates = _read_coil_defs()
        coils = _create_meg_coils(info['chs'], 'normal', info['dev_head_t'],
                                  templates)
        my_origin = _check_origin((0., 0., 0.04), info_from)
        int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils, 'meg')
        self_dots = _do_self_dots(int_rad, False, coils, my_origin, 'meg',
                                  lut_fun, n_fact, n_jobs=1)
        cross_dots = _do_cross_dots(int_rad, False, coils, coils,
                                    my_origin, 'meg', lut_fun, n_fact).T
        return self_dots, cross_dots

    _compute_fast_dots = mem.cache(_compute_dots)
    info = inst.info.copy()
    info['bads'] = []  # if bads is different, hash will be different

    info_from = pick_info(info, pick_from, copy=True)
    templates = _read_coil_defs()
    coils_from = _create_meg_coils(info_from['chs'], 'normal',
                                   info_from['dev_head_t'], templates)
    my_origin = _check_origin((0., 0., 0.04), info_from)
    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils_from, 'meg')

    self_dots, cross_dots = _compute_fast_dots(info, mode=mode)

    cross_dots = cross_dots[pick_to, :][:, pick_from]
    self_dots = self_dots[pick_from, :][:, pick_from]

    ch_names = [c['ch_name'] for c in info_from['chs']]
    fmd = dict(kind='meg', ch_names=ch_names,
               origin=my_origin, noise=noise, self_dots=self_dots,
               surface_dots=cross_dots, int_rad=int_rad, miss=miss)
    fmd['data'] = _compute_mapping_matrix(fmd, info_from)

    return fmd['data']
Example #5
0
def _compute_dots(info, mode='fast'):
    """Compute all-to-all dots."""
    from mne.forward._field_interpolation import _setup_dots
    from mne.forward._lead_dots import _do_self_dots, _do_cross_dots
    from mne.forward._make_forward import _create_meg_coils, _read_coil_defs
    from mne.bem import _check_origin

    templates = _read_coil_defs()
    coils = _create_meg_coils(info['chs'], 'normal', info['dev_head_t'],
                              templates)
    my_origin = _check_origin((0., 0., 0.04), info)
    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils, 'meg')
    self_dots = _do_self_dots(int_rad, False, coils, my_origin, 'meg',
                              lut_fun, n_fact, n_jobs=1)
    cross_dots = _do_cross_dots(int_rad, False, coils, coils,
                                my_origin, 'meg', lut_fun, n_fact).T
    return self_dots, cross_dots
Example #6
0
def map_meg_loocv_channels(inst, pick_from, pick_to, self_dots=None,
                           cross_dots=None, mode='fast'):

    from mne.io.pick import pick_info
    from mne.forward._lead_dots import _do_self_dots, _do_cross_dots
    from mne.forward._make_forward import _create_meg_coils, _read_coil_defs
    from mne.forward._field_interpolation import _setup_dots
    from mne.forward._field_interpolation import _compute_mapping_matrix
    from mne.bem import _check_origin

    info_from = pick_info(inst.info, pick_from, copy=True)
    info_to = pick_info(inst.info, pick_to, copy=True)

    # no need to apply trans because both from and to coils are in device
    # coordinates
    templates = _read_coil_defs(verbose=False)
    coils_from = _create_meg_coils(info_from['chs'], 'normal',
                                   info_from['dev_head_t'], templates)
    coils_to = _create_meg_coils(info_to['chs'], 'normal',
                                 info_to['dev_head_t'], templates)
    miss = 1e-4  # Smoothing criterion for MEG

    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils_from, 'meg')
    my_origin = _check_origin((0., 0., 0.04), info_from)

    if self_dots is None:
        self_dots = _do_self_dots(int_rad, False, coils_from, my_origin, 'meg',
                                  lut_fun, n_fact, n_jobs=1)
    if cross_dots is None:
        cross_dots = _do_cross_dots(int_rad, False, coils_from, coils_to,
                                    my_origin, 'meg', lut_fun, n_fact).T

    ch_names = [c['ch_name'] for c in info_from['chs']]
    fmd = dict(kind='meg', ch_names=ch_names,
               origin=my_origin, noise=noise, self_dots=self_dots,
               surface_dots=cross_dots, int_rad=int_rad, miss=miss)
    fmd['data'] = _compute_mapping_matrix(fmd, info_from)

    return fmd['data'], self_dots, cross_dots
Example #7
0
def _fast_map_meg_channels(info, pick_from, pick_to,
                           dots=None, mode='fast'):
    from mne.io.pick import pick_info
    from mne.forward._field_interpolation import _setup_dots
    from mne.forward._field_interpolation import _compute_mapping_matrix
    from mne.forward._make_forward import _create_meg_coils, _read_coil_defs
    from mne.bem import _check_origin

    miss = 1e-4  # Smoothing criterion for MEG

    # XXX: hack to silence _compute_mapping_matrix
    verbose = mne.get_config('MNE_LOGGING_LEVEL', 'INFO')
    mne.set_log_level('WARNING')

    info_from = pick_info(info, pick_from, copy=True)
    templates = _read_coil_defs()
    coils_from = _create_meg_coils(info_from['chs'], 'normal',
                                   info_from['dev_head_t'], templates)
    my_origin = _check_origin((0., 0., 0.04), info_from)
    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils_from, 'meg')

    # This function needs a clean input. It hates the presence of other
    # channels than MEG channels. Make sure all is picked.
    if dots is None:
        dots = self_dots, cross_dots = _compute_dots(info, mode=mode)
    else:
        self_dots, cross_dots = dots

    self_dots, cross_dots = _pick_dots(dots, pick_from, pick_to)

    ch_names = [c['ch_name'] for c in info_from['chs']]
    fmd = dict(kind='meg', ch_names=ch_names,
               origin=my_origin, noise=noise, self_dots=self_dots,
               surface_dots=cross_dots, int_rad=int_rad, miss=miss)

    fmd['data'] = _compute_mapping_matrix(fmd, info_from)
    mne.set_log_level(verbose)

    return fmd['data']