def test_as_meg_type_evoked():
    """Test interpolation of data on to virtual channels."""

    # validation tests
    evoked = read_evokeds(evoked_fname, condition="Left Auditory")
    assert_raises(ValueError, evoked.as_type, "meg")
    assert_raises(ValueError, evoked.copy().pick_types(meg="grad").as_type, "meg")

    # channel names
    ch_names = evoked.info["ch_names"]
    virt_evoked = evoked.pick_channels(ch_names=ch_names[:10:1], copy=True).as_type("mag")
    assert_true(all("_virtual" in ch for ch in virt_evoked.info["ch_names"]))

    # pick from and to channels
    evoked_from = evoked.pick_channels(ch_names=ch_names[2:10:3], copy=True)
    evoked_to = evoked.pick_channels(ch_names=ch_names[0:10:3], copy=True)

    info_from, info_to = evoked_from.info, evoked_to.info

    # set up things
    args1, args2 = _setup_args(info_from), _setup_args(info_to)
    args1.update(coils2=args2["coils1"]), args2.update(coils2=args1["coils1"])

    # test cross dots
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)

    assert_array_almost_equal(cross_dots1, cross_dots2.T)

    # correlation test
    evoked = evoked.pick_channels(ch_names=ch_names[:10:]).copy()
    data1 = evoked.pick_types(meg="grad").data.ravel()
    data2 = evoked.as_type("grad").data.ravel()
    assert_true(np.corrcoef(data1, data2)[0, 1] > 0.95)
def test_as_meg_type_evoked():
    """Test interpolation of data on to virtual channels."""
    # validation tests
    raw = read_raw_fif(raw_fname)
    events = mne.find_events(raw)
    picks = pick_types(raw.info,
                       meg=True,
                       eeg=True,
                       stim=True,
                       ecg=True,
                       eog=True,
                       include=['STI 014'],
                       exclude='bads')
    epochs = mne.Epochs(raw, events, picks=picks)
    evoked = epochs.average()

    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.as_type('meg')
    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.copy().pick_types(meg='grad').as_type('meg')

    # channel names
    ch_names = evoked.info['ch_names']
    virt_evoked = evoked.copy().pick_channels(ch_names=ch_names[:10:1])
    virt_evoked.info.normalize_proj()
    virt_evoked = virt_evoked.as_type('mag')
    assert (all(ch.endswith('_v') for ch in virt_evoked.info['ch_names']))

    # pick from and to channels
    evoked_from = evoked.copy().pick_channels(ch_names=ch_names[2:10:3])
    evoked_to = evoked.copy().pick_channels(ch_names=ch_names[0:10:3])

    info_from, info_to = evoked_from.info, evoked_to.info

    # set up things
    args1, args2 = _setup_args(info_from), _setup_args(info_to)
    args1.update(coils2=args2['coils1'])
    args2.update(coils2=args1['coils1'])

    # test cross dots
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)

    assert_array_almost_equal(cross_dots1, cross_dots2.T)

    # correlation test
    evoked = evoked.pick_channels(ch_names=ch_names[:10:]).copy()
    data1 = evoked.pick_types(meg='grad').data.ravel()
    data2 = evoked.as_type('grad').data.ravel()
    assert (np.corrcoef(data1, data2)[0, 1] > 0.95)

    # Do it with epochs
    virt_epochs = \
        epochs.copy().load_data().pick_channels(ch_names=ch_names[:10:1])
    virt_epochs.info.normalize_proj()
    virt_epochs = virt_epochs.as_type('mag')
    assert (all(ch.endswith('_v') for ch in virt_epochs.info['ch_names']))
    assert_allclose(virt_epochs.get_data().mean(0), virt_evoked.data)
示例#3
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
示例#4
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
示例#5
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
def test_as_meg_type_evoked():
    """Test interpolation of data on to virtual channels."""

    # validation tests
    evoked = read_evokeds(evoked_fname, condition='Left Auditory')
    assert_raises(ValueError, evoked.as_type, 'meg')
    assert_raises(ValueError, evoked.copy().pick_types(meg='grad').as_type,
                  'meg')

    # channel names
    ch_names = evoked.info['ch_names']
    virt_evoked = evoked.copy().pick_channels(ch_names=ch_names[:10:1])
    virt_evoked.info.normalize_proj()
    virt_evoked = virt_evoked.as_type('mag')
    assert_true(all('_virtual' in ch for ch in virt_evoked.info['ch_names']))

    # pick from and to channels
    evoked_from = evoked.copy().pick_channels(ch_names=ch_names[2:10:3])
    evoked_to = evoked.copy().pick_channels(ch_names=ch_names[0:10:3])

    info_from, info_to = evoked_from.info, evoked_to.info

    # set up things
    args1, args2 = _setup_args(info_from), _setup_args(info_to)
    args1.update(coils2=args2['coils1'])
    args2.update(coils2=args1['coils1'])

    # test cross dots
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)

    assert_array_almost_equal(cross_dots1, cross_dots2.T)

    # correlation test
    evoked = evoked.pick_channels(ch_names=ch_names[:10:]).copy()
    data1 = evoked.pick_types(meg='grad').data.ravel()
    data2 = evoked.as_type('grad').data.ravel()
    assert_true(np.corrcoef(data1, data2)[0, 1] > 0.95)
def test_as_meg_type_evoked():
    """Test interpolation of data on to virtual channels."""

    # validation tests
    evoked = read_evokeds(evoked_fname, condition='Left Auditory')
    assert_raises(ValueError, evoked.as_type, 'meg')
    assert_raises(ValueError,
                  evoked.copy().pick_types(meg='grad').as_type, 'meg')

    # channel names
    ch_names = evoked.info['ch_names']
    virt_evoked = evoked.copy().pick_channels(ch_names=ch_names[:10:1])
    virt_evoked.info.normalize_proj()
    virt_evoked = virt_evoked.as_type('mag')
    assert_true(all('_virtual' in ch for ch in virt_evoked.info['ch_names']))

    # pick from and to channels
    evoked_from = evoked.copy().pick_channels(ch_names=ch_names[2:10:3])
    evoked_to = evoked.copy().pick_channels(ch_names=ch_names[0:10:3])

    info_from, info_to = evoked_from.info, evoked_to.info

    # set up things
    args1, args2 = _setup_args(info_from), _setup_args(info_to)
    args1.update(coils2=args2['coils1'])
    args2.update(coils2=args1['coils1'])

    # test cross dots
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)

    assert_array_almost_equal(cross_dots1, cross_dots2.T)

    # correlation test
    evoked = evoked.pick_channels(ch_names=ch_names[:10:]).copy()
    data1 = evoked.pick_types(meg='grad').data.ravel()
    data2 = evoked.as_type('grad').data.ravel()
    assert_true(np.corrcoef(data1, data2)[0, 1] > 0.95)
示例#8
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
示例#9
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
示例#10
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