/
__init__.py
213 lines (184 loc) · 7.89 KB
/
__init__.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"""Convenience functions for opening GUIs."""
# Authors: Christian Brodbeck <christianbrodbeck@nyu.edu>
#
# License: BSD (3-clause)
import os
from ..utils import _check_mayavi_version, verbose, get_config
from ._backend import _testing_mode
def _initialize_gui(frame, view=None):
"""Initialize GUI depending on testing mode."""
if _testing_mode(): # open without entering mainloop
return frame.edit_traits(view=view), frame
else:
frame.configure_traits(view=view)
return frame
@verbose
def coregistration(tabbed=False, split=True, width=None, inst=None,
subject=None, subjects_dir=None, guess_mri_subject=None,
height=None, head_opacity=None, head_high_res=None,
trans=None, scrollable=True, project_eeg=None,
orient_to_surface=None, scale_by_distance=None,
mark_inside=None, interaction=None, scale=None,
verbose=None):
"""Coregister an MRI with a subject's head shape.
The recommended way to use the GUI is through bash with:
.. code-block:: bash
$ mne coreg
Parameters
----------
tabbed : bool
Combine the data source panel and the coregistration panel into a
single panel with tabs.
split : bool
Split the main panels with a movable splitter (good for QT4 but
unnecessary for wx backend).
width : int | None
Specify the width for window (in logical pixels).
Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value
(which defaults to 800).
inst : None | str
Path to an instance file containing the digitizer data. Compatible for
Raw, Epochs, and Evoked files.
subject : None | str
Name of the mri subject.
subjects_dir : None | path
Override the SUBJECTS_DIR environment variable
(sys.environ['SUBJECTS_DIR'])
guess_mri_subject : bool
When selecting a new head shape file, guess the subject's name based
on the filename and change the MRI subject accordingly (default True).
height : int | None
Specify a height for window (in logical pixels).
Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value
(which defaults to 400).
head_opacity : float | None
The opacity of the head surface in the range [0., 1.].
Default is None, which uses ``MNE_COREG_HEAD_OPACITY`` config value
(which defaults to 1.).
head_high_res : bool | None
Use a high resolution head surface.
Default is None, which uses ``MNE_COREG_HEAD_HIGH_RES`` config value
(which defaults to True).
trans : str | None
The transform file to use.
scrollable : bool
Make the coregistration panel vertically scrollable (default True).
project_eeg : bool | None
If True (default None), project EEG electrodes to the head surface.
This is only for visualization purposes and does not affect fitting.
.. versionadded:: 0.16
orient_to_surface : bool | None
If True (default None), orient EEG electrode and head shape points
to the head surface.
.. versionadded:: 0.16
scale_by_distance : bool | None
If True (default None), scale the digitization points by their
distance from the scalp surface.
.. versionadded:: 0.16
mark_inside : bool | None
If True (default None), mark points inside the head surface in a
different color.
.. versionadded:: 0.16
interaction : str | None
Can be 'terrain' (default None), use terrain-style interaction (where
"up" is the Z/superior direction), or 'trackball' to use
orientationless interactions.
.. versionadded:: 0.16
scale : float | None
The scaling for the scene.
..versionadded:: 0.16
verbose : bool, str, int, or None
If not None, override default verbose level (see :func:`mne.verbose`
and :ref:`Logging documentation <tut_logging>` for more).
Notes
-----
Many parameters (e.g., ``project_eeg``) take None as a parameter,
which means that the default will be read from the MNE-Python
configuration file (which gets saved when exiting).
Step by step instructions for the coregistrations can be accessed as
slides, `for subjects with structural MRI
<http://www.slideshare.net/mne-python/mnepython-coregistration>`_ and `for
subjects for which no MRI is available
<http://www.slideshare.net/mne-python/mnepython-scale-mri>`_.
"""
config = get_config(home_dir=os.environ.get('_MNE_FAKE_HOME_DIR'))
if guess_mri_subject is None:
guess_mri_subject = config.get(
'MNE_COREG_GUESS_MRI_SUBJECT', 'true') == 'true'
if head_high_res is None:
head_high_res = config.get('MNE_COREG_HEAD_HIGH_RES', 'true') == 'true'
if head_opacity is None:
head_opacity = config.get('MNE_COREG_HEAD_OPACITY', 1.)
if width is None:
width = config.get('MNE_COREG_WINDOW_WIDTH', 800)
if height is None:
height = config.get('MNE_COREG_WINDOW_HEIGHT', 600)
if subjects_dir is None:
if 'SUBJECTS_DIR' in config:
subjects_dir = config['SUBJECTS_DIR']
elif 'MNE_COREG_SUBJECTS_DIR' in config:
subjects_dir = config['MNE_COREG_SUBJECTS_DIR']
if project_eeg is None:
project_eeg = config.get('MNE_COREG_PROJECT_EEG', '') == 'true'
if orient_to_surface is None:
orient_to_surface = (config.get('MNE_COREG_ORIENT_TO_SURFACE', '') ==
'true')
if scale_by_distance is None:
scale_by_distance = (config.get('MNE_COREG_SCALE_BY_DISTANCE', '') ==
'true')
if interaction is None:
interaction = config.get('MNE_COREG_INTERACTION', 'trackball')
if mark_inside is None:
mark_inside = config.get('MNE_COREG_MARK_INSIDE', '') == 'true'
if scale is None:
scale = config.get('MNE_COREG_SCENE_SCALE', 0.16)
head_opacity = float(head_opacity)
width = int(width)
height = int(height)
scale = float(scale)
_check_mayavi_version()
from ._backend import _check_backend
_check_backend()
from ._coreg_gui import CoregFrame, _make_view
view = _make_view(tabbed, split, width, height, scrollable)
frame = CoregFrame(inst, subject, subjects_dir, guess_mri_subject,
head_opacity, head_high_res, trans, config,
project_eeg=project_eeg,
orient_to_surface=orient_to_surface,
scale_by_distance=scale_by_distance,
mark_inside=mark_inside, interaction=interaction,
scale=scale)
return _initialize_gui(frame, view)
def fiducials(subject=None, fid_file=None, subjects_dir=None):
"""Set the fiducials for an MRI subject.
Parameters
----------
subject : str
Name of the mri subject.
fid_file : None | str
Load a fiducials file different form the subject's default
("{subjects_dir}/{subject}/bem/{subject}-fiducials.fif").
subjects_dir : None | str
Overrule the subjects_dir environment variable.
Notes
-----
All parameters are optional, since they can be set through the GUI.
The functionality in this GUI is also part of :func:`coregistration`.
"""
_check_mayavi_version()
from ._backend import _check_backend
_check_backend()
from ._fiducials_gui import FiducialsFrame
frame = FiducialsFrame(subject, subjects_dir, fid_file=fid_file)
return _initialize_gui(frame)
def kit2fiff():
"""Convert KIT files to the fiff format.
The recommended way to use the GUI is through bash with::
$ mne kit2fiff
"""
_check_mayavi_version()
from ._backend import _check_backend
_check_backend()
from ._kit2fiff_gui import Kit2FiffFrame
frame = Kit2FiffFrame()
return _initialize_gui(frame)