Example #1
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    import matplotlib.pyplot as plt
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    with warnings.catch_warnings(record=True):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos, mode='field')
        else:
            assert_raises(RuntimeError, plot_head_positions, pos, mode='field')
    assert_raises(ValueError, plot_head_positions, pos, 'foo')
    plt.close('all')
Example #2
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    import matplotlib.pyplot as plt
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    with warnings.catch_warnings(record=True):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos, mode='field')
        else:
            assert_raises(RuntimeError, plot_head_positions, pos, mode='field')
    assert_raises(ValueError, plot_head_positions, pos, 'foo')
    plt.close('all')
Example #3
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    info = read_info(evoked_fname)
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    destination = (0., 0., 0.04)
    with pytest.warns(None):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos,
                                mode='field',
                                info=info,
                                destination=destination)
        else:
            pytest.raises(RuntimeError,
                          plot_head_positions,
                          pos,
                          mode='field',
                          info=info,
                          destination=destination)
        plot_head_positions([pos, pos])  # list support
        pytest.raises(ValueError, plot_head_positions, ['pos'])
        pytest.raises(ValueError, plot_head_positions, pos[:, :9])
    pytest.raises(ValueError, plot_head_positions, pos, 'foo')
    with pytest.raises(ValueError, match='shape'):
        with pytest.warns(None):  # old mpl no viridis warning
            plot_head_positions(pos, axes=1.)
    plt.close('all')
Example #4
0
def test_calculate_head_pos_ctf():
    """Test extracting of cHPI positions from CTF data."""
    raw = read_raw_ctf(ctf_chpi_fname)
    chpi_locs = extract_chpi_locs_ctf(raw)
    quats = compute_head_pos(raw.info, chpi_locs)
    mc_quats = read_head_pos(ctf_chpi_pos_fname)
    mc_quats[:, 9] /= 10000  # had old factor in there twice somehow...
    _assert_quats(quats, mc_quats, dist_tol=0.004, angle_tol=2.5, err_rtol=1.,
                  vel_atol=7e-3)  # 7 mm/s
    plot_head_positions(quats, info=raw.info)

    raw = read_raw_fif(ctf_fname)
    with pytest.raises(RuntimeError, match='Could not find'):
        extract_chpi_locs_ctf(raw)
Example #5
0
def test_calculate_head_pos_kit():
    """Test calculation of head position using KIT data."""
    raw = read_raw_kit(con_fname, mrk_fname, elp_fname, hsp_fname)
    assert len(raw.info['hpi_results']) == 1
    chpi_locs = extract_chpi_locs_kit(raw)
    assert chpi_locs['rrs'].shape == (2, 5, 3)
    assert_array_less(chpi_locs['gofs'], 1.)
    assert_array_less(0.98, chpi_locs['gofs'])
    quats = compute_head_pos(raw.info, chpi_locs)
    assert quats.shape == (2, 10)
    # plotting works
    plot_head_positions(quats, info=raw.info)
    raw_berlin = read_raw_kit(berlin_fname)
    assert_allclose(raw_berlin.info['dev_head_t']['trans'], np.eye(4))
    assert len(raw_berlin.info['hpi_results']) == 0
    with pytest.raises(ValueError, match='Invalid value'):
        extract_chpi_locs_kit(raw_berlin)
    with pytest.raises(RuntimeError, match='not find appropriate'):
        extract_chpi_locs_kit(raw_berlin, 'STI 014')
    with pytest.raises(RuntimeError, match='no initial cHPI'):
        compute_head_pos(raw_berlin.info, chpi_locs)
Example #6
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    import matplotlib.pyplot as plt
    info = read_info(evoked_fname)
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    destination = (0., 0., 0.04)
    with warnings.catch_warnings(record=True):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos,
                                mode='field',
                                info=info,
                                destination=destination)
        else:
            assert_raises(RuntimeError,
                          plot_head_positions,
                          pos,
                          mode='field',
                          info=info,
                          destination=destination)
        plot_head_positions([pos, pos])  # list support
        assert_raises(ValueError, plot_head_positions, ['pos'])
        assert_raises(ValueError, plot_head_positions, pos[:, :9])
    assert_raises(ValueError, plot_head_positions, pos, 'foo')
    plt.close('all')
Example #7
0
def add_head_postions(subj, report):
    hp_files = list((dirs.hp / subj.name).glob("*_hp.pos"))
    hp_files = sorted(hp_files, key=attrgetter("name"))

    figs = list()
    captions = list()
    for f in hp_files:
        captions.append(str(f.relative_to(dirs.bids_root.parent)))
        pos = read_head_pos(f)
        fig = plot_head_positions(pos, show=False)
        figs.append(fig)
    report.add_figs_to_section(figs, captions, section="Head position")
    return report
Example #8
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    info = read_info(evoked_fname)
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    destination = (0., 0., 0.04)
    with pytest.warns(None):  # old MPL will cause a warning
        plot_head_positions(pos)
        plot_head_positions(pos, mode='field', info=info,
                            destination=destination)
        plot_head_positions([pos, pos])  # list support
        pytest.raises(ValueError, plot_head_positions, ['pos'])
        pytest.raises(ValueError, plot_head_positions, pos[:, :9])
    pytest.raises(ValueError, plot_head_positions, pos, 'foo')
    with pytest.raises(ValueError, match='shape'):
        plot_head_positions(pos, axes=1.)
Example #9
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    info = read_info(evoked_fname)
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    destination = (0., 0., 0.04)
    with pytest.warns(None):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos, mode='field', info=info,
                                destination=destination)
        else:
            pytest.raises(RuntimeError, plot_head_positions, pos, mode='field',
                          info=info, destination=destination)
        plot_head_positions([pos, pos])  # list support
        pytest.raises(ValueError, plot_head_positions, ['pos'])
        pytest.raises(ValueError, plot_head_positions, pos[:, :9])
    pytest.raises(ValueError, plot_head_positions, pos, 'foo')
    with pytest.raises(ValueError, match='shape'):
        with pytest.warns(None):  # old mpl no viridis warning
            plot_head_positions(pos, axes=1.)
    plt.close('all')
Example #10
0
def test_plot_head_positions():
    """Test plotting of head positions."""
    import matplotlib.pyplot as plt
    info = read_info(evoked_fname)
    pos = np.random.RandomState(0).randn(4, 10)
    pos[:, 0] = np.arange(len(pos))
    destination = (0., 0., 0.04)
    with warnings.catch_warnings(record=True):  # old MPL will cause a warning
        plot_head_positions(pos)
        if check_version('matplotlib', '1.4'):
            plot_head_positions(pos, mode='field', info=info,
                                destination=destination)
        else:
            assert_raises(RuntimeError, plot_head_positions, pos, mode='field',
                          info=info, destination=destination)
        plot_head_positions([pos, pos])  # list support
        assert_raises(ValueError, plot_head_positions, ['pos'])
        assert_raises(ValueError, plot_head_positions, pos[:, :9])
    assert_raises(ValueError, plot_head_positions, pos, 'foo')
    plt.close('all')