Skip to content

Commit 97e16d3

Browse files
Merge pull request #3 from effigies/enh/cifti2_axes
DOC: Mostly documentation updates
2 parents d825a3c + 4aa3609 commit 97e16d3

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

nibabel/cifti2/cifti2_axes.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@
6767
These can be concatenated in a single brain model covering the left cortex and thalamus by
6868
simply adding them together
6969
70-
>>> bm_full = bm_cortex + bm_thal # doctest: +SKIP
70+
>>> bm_full = bm_cortex + bm_thal
7171
7272
Brain models covering the full HCP grayordinate space can be constructed by adding all the
7373
volumetric and surface brain models together like this (or by reading one from an already
7474
existing HCP file).
7575
7676
Getting a specific brain region from the full brain model is as simple as:
7777
78-
>>> assert bm_full[bm_full.name == 'CIFTI_STRUCTURE_CORTEX_LEFT'] == bm_cortex # doctest: +SKIP
79-
>>> assert bm_full[bm_full.name == 'CIFTI_STRUCTURE_THALAMUS_LEFT'] == bm_thal # doctest: +SKIP
78+
>>> assert bm_full[bm_full.name == 'CIFTI_STRUCTURE_CORTEX_LEFT'] == bm_cortex
79+
>>> assert bm_full[bm_full.name == 'CIFTI_STRUCTURE_THALAMUS_LEFT'] == bm_thal
8080
8181
You can also iterate over all brain structures in a brain model:
8282
83-
>>> for name, slc, bm in bm_full.iter_structures(): ... # doctest: +SKIP
83+
>>> for name, slc, bm in bm_full.iter_structures(): ...
8484
8585
In this case there will be two iterations, namely:
8686
('CIFTI_STRUCTURE_CORTEX_LEFT', slice(0, <size of cortex mask>), bm_cortex)
@@ -93,23 +93,23 @@
9393
... ('surface_parcel', bm_cortex[:100]), # contains first 100 cortical vertices
9494
... ('volume_parcel', bm_thal), # contains thalamus
9595
... ('combined_parcel', bm_full[[1, 8, 10, 120, 127]) # contains selected voxels/vertices
96-
... ]) # doctest: +SKIP
96+
... ])
9797
9898
Time series are represented by their starting time (typically 0), step size
9999
(i.e. sampling time or TR), and number of elements:
100100
101-
>>> series = cifti2.SeriesAxis(start=0, step=100, size=5000) # doctest: +SKIP
101+
>>> series = cifti2.SeriesAxis(start=0, step=100, size=5000)
102102
103103
So a header for fMRI data with a TR of 100 ms covering the left cortex and thalamus with
104104
5000 timepoints could be created with
105105
106-
>>> cifti2.Cifti2Header.from_axes((series, bm_cortex + bm_thal)) # doctest: +SKIP
106+
>>> cifti2.Cifti2Header.from_axes((series, bm_cortex + bm_thal))
107107
108108
Similarly the curvature and cortical thickness on the left cortex could be stored using a header
109109
like:
110110
111111
>>> cifti2.Cifti2Header.from_axes((cifti.ScalarAxis(['curvature', 'thickness'],
112-
... bm_cortex)) # doctest: +SKIP
112+
... bm_cortex))
113113
"""
114114
import numpy as np
115115
from . import cifti2
@@ -252,20 +252,20 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
252252
253253
Parameters
254254
----------
255-
name : str or np.ndarray
255+
name : array_like
256256
brain structure name or (N, ) string array with the brain structure names
257-
voxel : np.ndarray
257+
voxel : array_like, optional
258258
(N, 3) array with the voxel indices (can be omitted for CIFTI-2 files only
259259
covering the surface)
260-
vertex : np.ndarray
260+
vertex : array_like, optional
261261
(N, ) array with the vertex indices (can be omitted for volumetric CIFTI-2 files)
262-
affine : np.ndarray
262+
affine : array_like, optional
263263
(4, 4) array mapping voxel indices to mm space (not needed for CIFTI-2 files only
264264
covering the surface)
265-
volume_shape : tuple of three integers
265+
volume_shape : tuple of three integers, optional
266266
shape of the volume in which the voxels were defined (not needed for CIFTI-2 files only
267267
covering the surface)
268-
nvertices : dict from string to integer
268+
nvertices : dict from string to integer, optional
269269
maps names of surface elements to integers (not needed for volumetric CIFTI-2 files)
270270
"""
271271
if voxel is None:
@@ -304,7 +304,7 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
304304
if affine is None or volume_shape is None:
305305
raise ValueError("Affine and volume shape should be defined "
306306
"for BrainModelAxis containing voxels")
307-
self.affine = affine
307+
self.affine = np.asanyarray(affine)
308308
self.volume_shape = volume_shape
309309

310310
if np.any(self.vertex[surface_mask] < 0):
@@ -325,12 +325,12 @@ def from_mask(cls, mask, name='other', affine=None):
325325
326326
Parameters
327327
----------
328-
mask : np.ndarray
328+
mask : array_like
329329
all non-zero voxels will be included in the BrainModelAxis axis
330330
should be (Nx, Ny, Nz) array for volume mask or (Nvertex, ) array for surface mask
331-
name : str
331+
name : str, optional
332332
Name of the brain structure (e.g. 'CortexRight', 'thalamus_left' or 'brain_stem')
333-
affine : np.ndarray
333+
affine : array_like, optional
334334
(4, 4) array with the voxel to mm transformation (defaults to identity matrix)
335335
Argument will be ignored for surface masks
336336
@@ -362,7 +362,7 @@ def from_surface(cls, vertices, nvertex, name='Other'):
362362
363363
Parameters
364364
----------
365-
vertices : np.ndarray
365+
vertices : array_like
366366
indices of the vertices on the surface
367367
nvertex : int
368368
total number of vertices on the surface
@@ -384,7 +384,7 @@ def from_index_mapping(cls, mim):
384384
385385
Parameters
386386
----------
387-
mim : cifti2.Cifti2MatrixIndicesMap
387+
mim : :class:`.cifti2.Cifti2MatrixIndicesMap`
388388
389389
Returns
390390
-------
@@ -422,7 +422,7 @@ def to_mapping(self, dim):
422422
423423
Returns
424424
-------
425-
cifti2.Cifti2MatrixIndicesMap
425+
:class:`.cifti2.Cifti2MatrixIndicesMap`
426426
"""
427427
mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_BRAIN_MODELS')
428428
for name, to_slice, bm in self.iter_structures():
@@ -612,7 +612,7 @@ def __eq__(self, other):
612612
self.volume_shape == other.volume_shape) and
613613
self.nvertices == other.nvertices and
614614
np.array_equal(self.name, other.name) and
615-
np.array_equal(self.voxel[self.volume_mask], other.voxel[self.volume_mask]) and
615+
np.array_equal(self.voxel[self.volume_mask], other.voxel[other.volume_mask]) and
616616
np.array_equal(self.vertex[self.surface_mask], other.vertex[other.surface_mask])
617617
)
618618

@@ -720,22 +720,22 @@ def __init__(self, name, voxels, vertices, affine=None, volume_shape=None, nvert
720720
721721
Parameters
722722
----------
723-
name : np.ndarray
723+
name : array_like
724724
(N, ) string array with the parcel names
725-
voxels : np.ndarray
725+
voxels : array_like
726726
(N, ) object array each containing a sequence of voxels.
727727
For each parcel the voxels are represented by a (M, 3) index array
728-
vertices : np.ndarray
728+
vertices : array_like
729729
(N, ) object array each containing a sequence of vertices.
730730
For each parcel the vertices are represented by a mapping from brain structure name to
731731
(M, ) index array
732-
affine : np.ndarray
732+
affine : array_like, optional
733733
(4, 4) array mapping voxel indices to mm space (not needed for CIFTI-2 files only
734734
covering the surface)
735-
volume_shape : tuple of three integers
735+
volume_shape : tuple of three integers, optional
736736
shape of the volume in which the voxels were defined (not needed for CIFTI-2 files only
737737
covering the surface)
738-
nvertices : dict[String -> int]
738+
nvertices : dict from string to integer, optional
739739
maps names of surface elements to integers (not needed for volumetric CIFTI-2 files)
740740
"""
741741
self.name = np.asanyarray(name, dtype='U')
@@ -748,7 +748,7 @@ def __init__(self, name, voxels, vertices, affine=None, volume_shape=None, nvert
748748
voxels[idx] = as_array[idx]
749749
self.voxels = np.asanyarray(voxels, dtype='object')
750750
self.vertices = np.asanyarray(vertices, dtype='object')
751-
self.affine = affine
751+
self.affine = np.asanyarray(affine) if affine is not None else None
752752
self.volume_shape = volume_shape
753753
if nvertices is None:
754754
self.nvertices = {}
@@ -813,7 +813,7 @@ def from_index_mapping(cls, mim):
813813
814814
Parameters
815815
----------
816-
mim : cifti2.Cifti2MatrixIndicesMap
816+
mim : :class:`cifti2.Cifti2MatrixIndicesMap`
817817
818818
Returns
819819
-------
@@ -859,7 +859,7 @@ def to_mapping(self, dim):
859859
860860
Returns
861861
-------
862-
cifti2.Cifti2MatrixIndicesMap
862+
:class:`cifti2.Cifti2MatrixIndicesMap`
863863
"""
864864
mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_PARCELS')
865865
if self.affine is not None:
@@ -1008,7 +1008,8 @@ def get_element(self, index):
10081008
tuple with 3 elements
10091009
- unicode name of the parcel
10101010
- (M, 3) int array with voxel indices
1011-
- Dict[String -> (K, ) int array] with vertex indices for a specific surface brain structure
1011+
- dict from string to (K, ) int array with vertex indices
1012+
for a specific surface brain structure
10121013
"""
10131014
return self.name[index], self.voxels[index], self.vertices[index]
10141015

@@ -1023,9 +1024,9 @@ def __init__(self, name, meta=None):
10231024
"""
10241025
Parameters
10251026
----------
1026-
name : np.ndarray of string
1027+
name : array_like
10271028
(N, ) string array with the parcel names
1028-
meta : np.ndarray of dict
1029+
meta : array_like
10291030
(N, ) object array with a dictionary of metadata for each row/column.
10301031
Defaults to empty dictionary
10311032
"""
@@ -1046,7 +1047,7 @@ def from_index_mapping(cls, mim):
10461047
10471048
Parameters
10481049
----------
1049-
mim : cifti2.Cifti2MatrixIndicesMap
1050+
mim : :class:`.cifti2.Cifti2MatrixIndicesMap`
10501051
10511052
Returns
10521053
-------
@@ -1067,7 +1068,7 @@ def to_mapping(self, dim):
10671068
10681069
Returns
10691070
-------
1070-
cifti2.Cifti2MatrixIndicesMap
1071+
:class:`.cifti2.Cifti2MatrixIndicesMap`
10711072
"""
10721073
mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_SCALARS')
10731074
for name, meta in zip(self.name, self.meta):
@@ -1151,13 +1152,13 @@ def __init__(self, name, label, meta=None):
11511152
"""
11521153
Parameters
11531154
----------
1154-
name : np.ndarray
1155+
name : array_like
11551156
(N, ) string array with the parcel names
1156-
label : np.ndarray
1157+
label : array_like
11571158
single dictionary or (N, ) object array with dictionaries mapping
11581159
from integers to (name, (R, G, B, A)), where name is a string and R, G, B, and A are
11591160
floats between 0 and 1 giving the colour and alpha (i.e., transparency)
1160-
meta : np.ndarray
1161+
meta : array_like, optional
11611162
(N, ) object array with a dictionary of metadata for each row/column
11621163
"""
11631164
self.name = np.asanyarray(name, dtype='U')
@@ -1180,7 +1181,7 @@ def from_index_mapping(cls, mim):
11801181
11811182
Parameters
11821183
----------
1183-
mim : cifti2.Cifti2MatrixIndicesMap
1184+
mim : :class:`.cifti2.Cifti2MatrixIndicesMap`
11841185
11851186
Returns
11861187
-------
@@ -1202,7 +1203,7 @@ def to_mapping(self, dim):
12021203
12031204
Returns
12041205
-------
1205-
cifti2.Cifti2MatrixIndicesMap
1206+
:class:`.cifti2.Cifti2MatrixIndicesMap`
12061207
"""
12071208
mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_LABELS')
12081209
for name, label, meta in zip(self.name, self.label, self.meta):
@@ -1324,7 +1325,7 @@ def from_index_mapping(cls, mim):
13241325
13251326
Parameters
13261327
----------
1327-
mim : cifti2.Cifti2MatrixIndicesMap
1328+
mim : :class:`.cifti2.Cifti2MatrixIndicesMap`
13281329
13291330
Returns
13301331
-------
@@ -1345,7 +1346,7 @@ def to_mapping(self, dim):
13451346
13461347
Returns
13471348
-------
1348-
cifti2.Cifti2MatrixIndicesMap
1349+
:class:`cifti2.Cifti2MatrixIndicesMap`
13491350
"""
13501351
mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_SERIES')
13511352
mim.series_exponent = 0

0 commit comments

Comments
 (0)