55
55
class SourceSpaces (list ):
56
56
"""Represent a list of source space.
57
57
58
- Currently implemented as a list of dictionaries containing the source
59
- space information
58
+ This class acts like a list of dictionaries containing the source
59
+ space information, one entry in the list per source space type. See
60
+ Notes for details.
61
+
62
+ .. warning::
63
+ This class should not be created or modified by the end user. Use
64
+ :func:`mne.setup_source_space`, :func:`mne.setup_volume_source_space`,
65
+ or :func:`mne.read_source_spaces` to create :class:`SourceSpaces`.
60
66
61
67
Parameters
62
68
----------
@@ -68,9 +74,126 @@ class SourceSpaces(list):
68
74
69
75
Attributes
70
76
----------
77
+ kind : str
78
+ The kind of source space, one of
79
+ ``{'surface', 'volume', 'discrete', 'mixed'}``.
71
80
info : dict
72
81
Dictionary with information about the creation of the source space
73
82
file. Has keys 'working_dir' and 'command_line'.
83
+
84
+ See Also
85
+ --------
86
+ mne.setup_source_space : Setup a surface source space.
87
+ mne.setup_volume_source_space : Setup a volume source space.
88
+ mne.read_source_spaces : Read source spaces from a file.
89
+
90
+ Notes
91
+ -----
92
+ Each element in SourceSpaces (e.g., ``src[0]``) is a dictionary. For
93
+ example, a surface source space will have ``len(src) == 2``, one entry for
94
+ each hemisphere. A volume source space will have ``len(src) == 1`` if it
95
+ uses a single monolithic grid, or ``len(src) == len(volume_label)`` when
96
+ created with a list-of-atlas-labels. A mixed source space consists of both
97
+ surface and volumetric source spaces in a single SourceSpaces object.
98
+
99
+ Each of those dictionaries can be accessed using standard Python
100
+ :class:`python:dict` access using the string keys listed below (e.g.,
101
+ ``src[0]['type'] == 'surf'``). The relevant key/value pairs depend on
102
+ the source space type:
103
+
104
+ **Relevant to all source spaces**
105
+
106
+ The following are always present:
107
+
108
+ id : int
109
+ The FIF ID, either ``FIFF.FIFFV_MNE_SURF_LEFT_HEMI`` or
110
+ ``FIFF.FIFFV_MNE_SURF_RIGHT_HEMI`` for surfaces, or
111
+ ``FIFF.FIFFV_MNE_SURF_UNKNOWN`` for volume source spaces.
112
+ type : str
113
+ The type of source space, one of ``{'surf', 'vol', 'discrete'}``.
114
+ np : int
115
+ Number of vertices in the dense surface or complete volume.
116
+ coord_frame : int
117
+ The coordinate frame, usually ``FIFF.FIFFV_COORD_MRI``.
118
+ rr : ndarray, shape (np, 3)
119
+ The dense surface or complete volume vertex locations.
120
+ nn : ndarray, shape (np, 3)
121
+ The dense surface or complete volume normals.
122
+ nuse : int
123
+ The number of points in the subsampled surface.
124
+ inuse : ndarray, shape (np,)
125
+ An integer array defining whether each dense surface vertex is used
126
+ (``1``) or unused (``0``).
127
+ vertno : ndarray, shape (n_src,)
128
+ The vertex numbers of the dense surface or complete volume that are
129
+ used (i.e., ``np.where(src[0]['inuse'])[0]``).
130
+ subject_his_id : str
131
+ The FreeSurfer subject name.
132
+
133
+ **Surface source spaces**
134
+
135
+ Surface source spaces created using :func:`mne.setup_source_space` can have
136
+ the following additional entries (which will be missing, or have values of
137
+ ``None`` or ``0`` for volumetric source spaces):
138
+
139
+ ntri : int
140
+ Number of triangles in the dense surface triangulation.
141
+ tris : ndarray, shape (ntri, 3)
142
+ The dense surface triangulation.
143
+ nuse_tri : int
144
+ The number of triangles in the subsampled surface.
145
+ use_tris : ndarray, shape (nuse_tri, 3)
146
+ The subsampled surface triangulation.
147
+ dist : scipy.sparse.csr_matrix, shape (n_src, n_src) | None
148
+ The distances (euclidean for volume, along the cortical surface for
149
+ surfaces) between source points.
150
+ dist_limit : float
151
+ The maximum distance allowed for inclusion in ``nearest``.
152
+ pinfo : dict
153
+ Information about the patch of cortex represented by a vertex in
154
+ the subsampled surface.
155
+ patch_inds : list of ndarray
156
+ For each vertex in the subsampled surface, the indices of the
157
+ vertices in the dense surface that it represents (i.e., is closest
158
+ to of all subsampled indices).
159
+ nearest : ndarray, shape (np,)
160
+ For each vertex on the dense surface, this gives the vertex index
161
+ on the subsampled surface that it's closest to.
162
+ nearest_dist : ndarray, shape (np,)
163
+ The distances corresponding to ``nearest``.
164
+
165
+ **Volume source spaces**
166
+
167
+ Volume source spaces created using :func:`mne.setup_volume_source_space`
168
+ can have the following additional entries (which will be missing, or
169
+ have values of ``None`` or ``0`` for surface source spaces):
170
+
171
+ mri_width, mri_height, mri_depth : int
172
+ The MRI dimensions (in voxels).
173
+ neighbor_vert : ndarray
174
+ The 26-neighborhood information for each vertex.
175
+ interpolator : scipy.sparse.csr_matrix | None
176
+ The linear interpolator to go from the subsampled volume vertices
177
+ to the high-resolution volume.
178
+ shape : tuple of int
179
+ The shape of the subsampled grid.
180
+ mri_ras_t : instance of :class:`~mne.transforms.Transform`
181
+ The transformation from MRI surface RAS (``FIFF.FIFFV_COORD_MRI``)
182
+ to MRI scanner RAS (``FIFF.FIFFV_MNE_COORD_RAS``).
183
+ src_mri_t : instance of :class:`~mne.transforms.Transform`
184
+ The transformation from subsampled source space voxel to MRI
185
+ surface RAS.
186
+ vox_mri_t : instance of :class:`~mne.transforms.Transform`
187
+ The transformation from the original MRI voxel
188
+ (``FIFF.FIFFV_MNE_COORD_MRI_VOXEL``) space to MRI surface RAS.
189
+ mri_volume_name : str
190
+ The MRI volume name, e.g. ``'subjects_dir/subject/mri/T1.mgz'``.
191
+ seg_name : str
192
+ The MRI atlas segmentation name (e.g., ``'Left-Cerebellum-Cortex'``
193
+ from the parameter ``volume_label``).
194
+
195
+ Source spaces also have some attributes that are accessible via ``.``
196
+ access, like ``src.kind``.
74
197
"""
75
198
76
199
def __init__ (self , source_spaces , info = None ): # noqa: D102
@@ -709,9 +832,9 @@ def _read_one_source_space(fid, this):
709
832
tag = read_tag (fid , d .pos )
710
833
trans = tag .data
711
834
if trans ['from' ] == FIFF .FIFFV_MNE_COORD_MRI_VOXEL :
712
- res ['vox_mri_t' ] = tag . data
835
+ res ['vox_mri_t' ] = trans
713
836
if trans ['to' ] == FIFF .FIFFV_MNE_COORD_RAS :
714
- res ['mri_ras_t' ] = tag . data
837
+ res ['mri_ras_t' ] = trans
715
838
716
839
tag = find_tag (fid , mri , FIFF .FIFF_MNE_SOURCE_SPACE_INTERPOLATOR )
717
840
if tag is not None :
@@ -1669,7 +1792,7 @@ def _make_discrete_source_space(pos, coord_frame='mri'):
1669
1792
# Ready to make the source space
1670
1793
sp = dict (coord_frame = coord_frame , type = 'discrete' , nuse = npts , np = npts ,
1671
1794
inuse = np .ones (npts , int ), vertno = np .arange (npts ), rr = rr , nn = nn ,
1672
- id = - 1 )
1795
+ id = FIFF . FIFFV_MNE_SURF_UNKNOWN )
1673
1796
return sp
1674
1797
1675
1798
@@ -1721,7 +1844,8 @@ def _make_volume_source_space(surf, grid, exclude, mindist, mri=None,
1721
1844
rr = np .array ([x * grid , y * grid , z * grid ]).T
1722
1845
sp = dict (np = npts , nn = np .zeros ((npts , 3 )), rr = rr ,
1723
1846
inuse = np .ones (npts , bool ), type = 'vol' , nuse = npts ,
1724
- coord_frame = FIFF .FIFFV_COORD_MRI , id = - 1 , shape = ns )
1847
+ coord_frame = FIFF .FIFFV_COORD_MRI , id = FIFF .FIFFV_MNE_SURF_UNKNOWN ,
1848
+ shape = ns )
1725
1849
sp ['nn' ][:, 2 ] = 1.0
1726
1850
assert sp ['rr' ].shape [0 ] == npts
1727
1851
0 commit comments