Ejemplo n.º 1
0
def map_ch_coords_to_mne(inst):
    """Transform sensors to MNE coordinates

    .. note::
        operates in place

    .. warning::
        For several reasons we do not use the MNE coordinates for the inverse
        modeling. This however won't always play nicely with visualization.

    Parameters
    ----------
    inst :  MNE data containers
        Raw, Epochs, Evoked.
    """
    bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t())
    dev_ctf_t = inst.info['dev_ctf_t']
    for ch in inst.info['chs']:
        loc = ch['loc'][:]
        if loc is not None:
            logger.debug('converting %s' % ch['ch_name'])
            t = _loc_to_coil_trans(loc)
            t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)
            loc = _coil_trans_to_loc(t)
            ch['loc'] = loc
Ejemplo n.º 2
0
def test_transforms():
    """ Test transformations """
    bti_trans = (0.0, 0.02, 0.11)
    bti_dev_t = Transform("ctf_meg", "meg", _get_bti_dev_t(0.0, bti_trans))
    for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
        raw = read_raw_bti(pdf, config, hs)
        dev_ctf_t = raw.info["dev_ctf_t"]
        dev_head_t_old = raw.info["dev_head_t"]
        ctf_head_t = raw.info["ctf_head_t"]

        # 1) get BTI->Neuromag
        bti_dev_t = Transform("ctf_meg", "meg", _get_bti_dev_t(0.0, bti_trans))

        # 2) get Neuromag->BTI head
        t = combine_transforms(invert_transform(bti_dev_t), dev_ctf_t, "meg", "ctf_head")
        # 3) get Neuromag->head
        dev_head_t_new = combine_transforms(t, ctf_head_t, "meg", "head")

        assert_array_equal(dev_head_t_new["trans"], dev_head_t_old["trans"])
Ejemplo n.º 3
0
def test_transforms():
    """Test transformations."""
    bti_trans = (0.0, 0.02, 0.11)
    bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))
    for pdf, config, hs, in zip(pdf_fnames, config_fnames, hs_fnames):
        raw = read_raw_bti(pdf, config, hs, preload=False)
        dev_ctf_t = raw.info['dev_ctf_t']
        dev_head_t_old = raw.info['dev_head_t']
        ctf_head_t = raw.info['ctf_head_t']

        # 1) get BTI->Neuromag
        bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))

        # 2) get Neuromag->BTI head
        t = combine_transforms(invert_transform(bti_dev_t), dev_ctf_t, 'meg',
                               'ctf_head')
        # 3) get Neuromag->head
        dev_head_t_new = combine_transforms(t, ctf_head_t, 'meg', 'head')

        assert_array_equal(dev_head_t_new['trans'], dev_head_t_old['trans'])
Ejemplo n.º 4
0
def test_transforms():
    """Test transformations."""
    bti_trans = (0.0, 0.02, 0.11)
    bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))
    for pdf, config, hs, in zip(pdf_fnames, config_fnames, hs_fnames):
        raw = read_raw_bti(pdf, config, hs, preload=False)
        dev_ctf_t = raw.info['dev_ctf_t']
        dev_head_t_old = raw.info['dev_head_t']
        ctf_head_t = raw.info['ctf_head_t']

        # 1) get BTI->Neuromag
        bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))

        # 2) get Neuromag->BTI head
        t = combine_transforms(invert_transform(bti_dev_t), dev_ctf_t,
                               'meg', 'ctf_head')
        # 3) get Neuromag->head
        dev_head_t_new = combine_transforms(t, ctf_head_t, 'meg', 'head')

        assert_array_equal(dev_head_t_new['trans'], dev_head_t_old['trans'])
Ejemplo n.º 5
0
def transform_sensors_to_mne(inst):
    """ Transform sensors to MNE coordinates

    For several reasons we do not use the MNE coordinates for the inverse
    modeling. This however won't always play nicely with visualization.

    """
    bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t())
    dev_ctf_t = inst.info['dev_ctf_t']
    for ch in inst.info['chs']:
        loc = ch['loc'][:]
        if loc is not None:
            logger.debug('converting %s' % ch['ch_name'])
            t = _loc_to_coil_trans(loc)
            t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)
            loc = _coil_trans_to_loc(t)
            ch['loc'] = loc
Ejemplo n.º 6
0
def transform_sensors_to_mne(inst):
    """ Transform sensors to MNE coordinates

    For several reasons we do not use the MNE coordinates for the inverse
    modeling. This however won't always play nicely with visualization.

    """
    bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t())
    dev_ctf_t = inst.info['dev_ctf_t']
    for ch in inst.info['chs']:
        loc = ch['loc'][:]
        if loc is not None:
            print('converting %s' % ch['ch_name'])
            t = _loc_to_coil_trans(loc)
            t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)
            loc = _coil_trans_to_loc(t)
            ch['loc'] = loc
Ejemplo n.º 7
0
def test_nan_trans():
    """Test unlikely case that the device to head transform is empty."""
    for ii, pdf_fname in enumerate(pdf_fnames):
        bti_info = _read_bti_header(pdf_fname,
                                    config_fnames[ii],
                                    sort_by_ch_name=True)

        dev_ctf_t = Transform('ctf_meg', 'ctf_head',
                              _correct_trans(bti_info['bti_transform'][0]))

        # reading params
        convert = True
        rotation_x = 0.
        translation = (0.0, 0.02, 0.11)
        bti_dev_t = _get_bti_dev_t(rotation_x, translation)
        bti_dev_t = Transform('ctf_meg', 'meg', bti_dev_t)
        ecg_ch = 'E31'
        eog_ch = ('E63', 'E64')

        # read parts of info to get trans
        bti_ch_names = list()
        for ch in bti_info['chs']:
            ch_name = ch['name']
            if not ch_name.startswith('A'):
                ch_name = ch.get('chan_label', ch_name)
            bti_ch_names.append(ch_name)

        neuromag_ch_names = _rename_channels(bti_ch_names,
                                             ecg_ch=ecg_ch,
                                             eog_ch=eog_ch)
        ch_mapping = zip(bti_ch_names, neuromag_ch_names)

        # add some nan in some locations!
        dev_ctf_t['trans'][:, 3] = np.nan
        _check_nan_dev_head_t(dev_ctf_t)
        for idx, (chan_4d, chan_neuromag) in enumerate(ch_mapping):
            loc = bti_info['chs'][idx]['loc']
            if loc is not None:
                if convert:
                    t = _loc_to_coil_trans(bti_info['chs'][idx]['loc'])
                    t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)
Ejemplo n.º 8
0
def test_nan_trans():
    """Test unlikely case that the device to head transform is empty."""
    for ii, pdf_fname in enumerate(pdf_fnames):
        bti_info = _read_bti_header(
            pdf_fname, config_fnames[ii], sort_by_ch_name=True)

        dev_ctf_t = Transform('ctf_meg', 'ctf_head',
                              _correct_trans(bti_info['bti_transform'][0]))

        # reading params
        convert = True
        rotation_x = 0.
        translation = (0.0, 0.02, 0.11)
        bti_dev_t = _get_bti_dev_t(rotation_x, translation)
        bti_dev_t = Transform('ctf_meg', 'meg', bti_dev_t)
        ecg_ch = 'E31'
        eog_ch = ('E63', 'E64')

        # read parts of info to get trans
        bti_ch_names = list()
        for ch in bti_info['chs']:
            ch_name = ch['name']
            if not ch_name.startswith('A'):
                ch_name = ch.get('chan_label', ch_name)
            bti_ch_names.append(ch_name)

        neuromag_ch_names = _rename_channels(
            bti_ch_names, ecg_ch=ecg_ch, eog_ch=eog_ch)
        ch_mapping = zip(bti_ch_names, neuromag_ch_names)

        # add some nan in some locations!
        dev_ctf_t['trans'][:, 3] = np.nan
        _check_nan_dev_head_t(dev_ctf_t)
        for idx, (chan_4d, chan_neuromag) in enumerate(ch_mapping):
            loc = bti_info['chs'][idx]['loc']
            if loc is not None:
                if convert:
                    t = _loc_to_coil_trans(bti_info['chs'][idx]['loc'])
                    t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)