File: test_what.py

package info (click to toggle)
python-mne 1.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 131,492 kB
  • sloc: python: 213,302; javascript: 12,910; sh: 447; makefile: 144
file content (67 lines) | stat: -rw-r--r-- 1,887 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
# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

import glob
from pathlib import Path

import numpy as np
import pytest

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

data_path = testing.data_path(download=False)


@pytest.mark.slowtest
@testing.requires_testing_data
def test_what(tmp_path, verbose_debug):
    """Test mne.what."""
    pytest.importorskip("sklearn")
    # ICA
    ica = ICA(max_iter=1, random_state=0)
    raw = RawArray(np.random.RandomState(0).randn(3, 10), create_info(3, 1000.0, "eeg"))
    with _record_warnings():  # convergence sometimes
        ica.fit(raw)
    fname = tmp_path / "x-ica.fif"
    ica.save(fname)
    assert what(fname) == "ica"
    # test files
    fnames = glob.glob(str(data_path / "MEG" / "sample" / "*.fif"))
    fnames += glob.glob(str(data_path / "subjects" / "sample" / "bem" / "*.fif"))
    fnames += [str(fname)]
    fnames = sorted(fnames)
    want_dict = dict(
        eve="events",
        ave="evoked",
        cov="cov",
        ica="ica",
        inv="inverse",
        fwd="forward",
        trans="transform",
        proj="proj",
        raw="raw",
        sol="bem solution",
        bem="bem surfaces",
        src="src",
        dense="bem surfaces",
        head="bem surfaces",
        fiducials="fiducials",
    )
    got = set()
    for fname in fnames:
        print(fname)
        kind = Path(fname).stem.split("-")[-1]
        if len(kind) > 5:
            kind = kind.split("_")[-1]
        this = what(fname)
        assert this == want_dict[kind], fname
        print()
        got.add(kind)
    assert set(want_dict) == got
    fname = data_path / "MEG" / "sample" / "sample_audvis-ave_xfit.dip"
    assert what(fname) == "unknown"