File: mne_report_tutorial.rst

package info (click to toggle)
python-mne 0.8.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 87,892 kB
  • ctags: 6,639
  • sloc: python: 54,697; makefile: 165; sh: 15
file content (117 lines) | stat: -rw-r--r-- 4,879 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
.. _mne_report_tutorial:

=================================================
Tutorial: Getting started with MNE report command
=================================================

This quick start will show you how to run the `mne report` command on the
sample data set provided with MNE.

First ensure that the files you want to render follow the filename conventions
defined by MNE:

==================   ====================================================
Data object          Filename convention (ends with)
==================   ====================================================
raw                  -raw.fif(.gz), -raw_sss.fif(.gz), -raw_tsss.fif(.gz)
events               -eve.fif(.gz)
epochs               -epo.fif(.gz)
evoked               -ave.fif(.gz)
covariance           -cov.fif(.gz)
trans                -trans.fif(.gz)
forward              -fwd.fif(.gz)
inverse              -inv.fif(.gz)
==================   ====================================================

The command line interface
--------------------------

To generate a barebones report from all the \*.fif files in the sample dataset,
invoke the following command::

    mne report --path MNE-sample-data/ --verbose

On successful creation of the report, it will open the html in a new tab in the browser.
To disable this, use the `--no-browser` option.

If the report is generated for a single subject, give the SUBJECT name and the
SUBJECTS_DIR and this will generate the MRI slices (with BEM contours overlaid on top
if available)::

    mne report --path MNE-sample-data/ --subject sample --subjects-dir MNE-sample-data/subjects --verbose

To properly render `trans` and `covariance` files, add the measurement information::

    mne report --path MNE-sample-data/ --info MNE-sample-data/MEG/sample/sample_audvis-ave.fif \ 
        --subject sample --subjects_dir MNE-sample-data/subjects --verbose

To generate the report in parallel::

    mne report --path MNE-sample-data/ --info MNE-sample-data/MEG/sample/sample_audvis-ave.fif \ 
        --subject sample --subjects_dir MNE-sample-data/subjects --verbose --jobs 6

The Python interface
--------------------

The same functionality can also be achieved using the Python interface. Import
the required functions:

    >>> from mne.report import Report
    >>> from mne.datasets import sample

Generate the report:

    >>> path = sample.data_path()
    >>> report = Report()
    Embedding : jquery-1.10.2.min.js
    Embedding : jquery-ui.min.js
    Embedding : bootstrap.min.js
    Embedding : jquery-ui.min.css
    Embedding : bootstrap.min.css

Only include \*-eve.fif files in the report:

    >>> report.parse_folder(data_path=path, pattern='*-eve.fif') # doctest: +SKIP
    Rendering : .../MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif
    Rendering : .../MNE-sample-data/MEG/sample/sample_audvis_eog-eve.fif
    Rendering : .../MNE-sample-data/MEG/sample/ernoise_raw-eve.fif
    Rendering : .../MNE-sample-data/MEG/sample/sample_audvis_raw-eve.fif
    Rendering : .../MNE-sample-data/MEG/sample/sample_audvis_ecg-eve.fif

Save the report as an html, but do not open the html in a browser:

    >>> report.save('report.html', overwrite=True, open_browser=False) # doctest:+SKIP
    Rendering : Table of Contents...

There is greater flexibility compared to the command line interface. 
Custom plots can be added to the report. Let us first generate a custom plot:

    >>> from mne import read_evokeds
    >>> fname = path + '/MEG/sample/sample_audvis-ave.fif'
    >>> evoked = read_evokeds(fname, condition='Left Auditory', baseline=(None, 0)) # doctest:+ELLIPSIS
    Reading .../MNE-sample-data/MEG/sample/sample_audvis-ave.fif ...
        Read a total of 4 projection items:
            PCA-v1 (1 x 102) active
            PCA-v2 (1 x 102) active
            PCA-v3 (1 x 102) active
            Average EEG reference (1 x 60) active
        Found the data of interest:
            t =    -199.80 ...     499.49 ms (Left Auditory)
            0 CTF compensation matrices available
            nave = 55 - aspect type = 100
    Projections have already been applied. Doing nothing.
    Applying baseline correction ... (mode: mean)
    >>> fig = evoked.plot() # doctest: +SKIP

To add the custom plot to the report, do:

    >>> report.add_section(fig, captions='Left Auditory', section='evoked') # doctest: +SKIP
    >>> report.save('report.html', overwrite=True) # doctest: +SKIP
    Rendering : Table of Contents...

The MNE report command internally manages the sections so that plots belonging to the same section
are rendered consecutively. Within a section, the plots are ordered in the same order that they were 
added using the `add_section` command. Each section is identified by a toggle button in the navigation 
bar of the report which can be used to show or hide the contents of the section.

That's it!