File: test_montage.py

package info (click to toggle)
python-mne 0.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100,440 kB
  • sloc: python: 120,243; pascal: 1,861; makefile: 225; sh: 15
file content (77 lines) | stat: -rw-r--r-- 2,598 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Authors: Denis Engemann <denis.engemann@gmail.com>
#          Alexandre Gramfort <alexandre.gramfort@inria.fr>
#          Teon Brooks <teon.brooks@gmail.com>
#
# License: Simplified BSD

# Set our plotters to test mode
import os.path as op
import numpy as np

import pytest
import matplotlib.pyplot as plt

from mne.channels import (read_dig_montage, read_dig_fif,
                          make_dig_montage, make_standard_montage)

p_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'kit', 'tests', 'data')
elp = op.join(p_dir, 'test_elp.txt')
hsp = op.join(p_dir, 'test_hsp.txt')
hpi = op.join(p_dir, 'test_mrk.sqd')
point_names = ['nasion', 'lpa', 'rpa', '1', '2', '3', '4', '5']
io_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'tests', 'data')
fif_fname = op.join(io_dir, 'test_raw.fif')


def test_plot_montage():
    """Test plotting montages."""
    m = make_standard_montage('easycap-M1')
    m.plot()
    plt.close('all')
    m.plot(kind='3d')
    plt.close('all')
    m.plot(kind='3d', show_names=True)
    plt.close('all')
    m.plot(kind='topomap')
    plt.close('all')
    m.plot(kind='topomap', show_names=True)
    plt.close('all')
    with pytest.deprecated_call():
        d = read_dig_montage(hsp, hpi, elp, point_names)
    assert '0 channels' in repr(d)
    with pytest.raises(RuntimeError, match='No valid channel positions'):
        d.plot()
    d = read_dig_fif(fname=fif_fname)
    assert '61 channels' in repr(d)
    # XXX this is broken; dm.point_names is used. Sometimes we say this should
    # Just contain the HPI coils, other times that it's all channels (e.g.,
    # EEG channels). But there is redundancy with this and dm.dig_ch_pos.
    # This should be addressed in the pending big refactoring.
    # d.plot()
    # plt.close('all')


@pytest.mark.parametrize('name, n', [
    ('standard_1005', 342), ('standard_postfixed', 85),
    ('standard_primed', 85), ('standard_1020', 93)
])
def test_plot_defect_montage(name, n):
    """Test plotting defect montages (i.e. with duplicate labels)."""
    # montage name and number of unique labels
    m = make_standard_montage(name)
    n -= 3  # new montage does not have fiducials
    fig = m.plot()
    collection = fig.axes[0].collections[0]
    assert collection._edgecolors.shape[0] == n
    assert collection._facecolors.shape[0] == n
    assert collection._offsets.shape[0] == n


def test_plot_digmontage():
    """Test plot DigMontage."""
    montage = make_dig_montage(
        ch_pos=dict(zip(list('abc'), np.eye(3))),
        coord_frame='head'
    )
    montage.plot()
    plt.close('all')