File: test_what.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 (55 lines) | stat: -rw-r--r-- 1,751 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
# Authors: Eric Larson <larson.eric.d@gmail.com>
# License: BSD

import glob
import os.path as op

import numpy as np
import pytest

from mne import what, create_info
from mne.datasets import testing
from mne.io import RawArray
from mne.preprocessing import ICA
from mne.utils import run_tests_if_main, requires_sklearn

data_path = testing.data_path(download=False)


@pytest.mark.slowtest
@requires_sklearn
@testing.requires_testing_data
def test_what(tmpdir):
    """Test mne.what."""
    # ICA
    ica = ICA(max_iter=1)
    raw = RawArray(np.random.RandomState(0).randn(3, 10),
                   create_info(3, 1000., 'eeg'))
    with pytest.warns(None):  # convergence sometimes
        ica.fit(raw)
    fname = op.join(str(tmpdir), 'x-ica.fif')
    ica.save(fname)
    assert what(fname) == 'ica'
    # test files
    fnames = glob.glob(
        op.join(data_path, 'MEG', 'sample', '*.fif'))
    fnames += glob.glob(
        op.join(data_path, 'subjects', 'sample', 'bem', '*.fif'))
    fnames = sorted(fnames)
    want_dict = dict(eve='events', ave='evoked', cov='cov', inv='inverse',
                     fwd='forward', trans='transform', proj='proj',
                     raw='raw', meg='raw', sol='bem solution',
                     bem='bem surfaces', src='src', dense='bem surfaces',
                     sparse='bem surfaces', head='bem surfaces',
                     fiducials='fiducials')
    for fname in fnames:
        kind = op.splitext(fname)[0].split('-')[-1]
        if len(kind) > 5:
            kind = kind.split('_')[-1]
        this = what(fname)
        assert this == want_dict[kind]
    fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave_xfit.dip')
    assert what(fname) == 'unknown'


run_tests_if_main()