Skip to content

Commit aeb7f80

Browse files
matthew-bretteffigies
authored andcommitted
RF+DOC: more cleanup of docs, some refactoring
Renamed a constant CIFTI_BrainStructures. Fixed up a few edit errors in the docs.
1 parent 7ca5338 commit aeb7f80

File tree

3 files changed

+53
-93
lines changed

3 files changed

+53
-93
lines changed

nibabel/cifti2/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Cifti2LabelTable, Cifti2VertexIndices,
2222
Cifti2VoxelIndicesIJK, Cifti2BrainModel, Cifti2Matrix,
2323
Cifti2MatrixIndicesMap, Cifti2NamedMap, Cifti2Parcel,
24-
Cifti2Surface, Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ,
25-
Cifti2Vertices, Cifti2Volume, CIFTI_BrainStructures, CIFTI2HeaderError,
26-
CIFTI_MODEL_TYPES, load, save)
24+
Cifti2Surface,
25+
Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ,
26+
Cifti2Vertices, Cifti2Volume, CIFTI_BRAIN_STRUCTURES,
27+
CIFTI2HeaderError, CIFTI_MODEL_TYPES, load, save)

nibabel/cifti2/cifti2.py

Lines changed: 46 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,48 @@ class CIFTI2HeaderError(Exception):
4848
'CIFTI_INDEX_TYPE_SCALARS',
4949
'CIFTI_INDEX_TYPE_LABELS')
5050

51-
CIFTI_MODEL_TYPES = ('CIFTI_MODEL_TYPE_SURFACE',
52-
'CIFTI_MODEL_TYPE_VOXELS')
51+
CIFTI_MODEL_TYPES = (
52+
'CIFTI_MODEL_TYPE_SURFACE', # Modeled using surface vertices
53+
'CIFTI_MODEL_TYPE_VOXELS' # Modeled using voxels.
54+
)
5355

5456
CIFTI_SERIESUNIT_TYPES = ('SECOND',
5557
'HERTZ',
5658
'METER',
5759
'RADIAN')
5860

59-
CIFTI_BrainStructures = ('CIFTI_STRUCTURE_ACCUMBENS_LEFT',
60-
'CIFTI_STRUCTURE_ACCUMBENS_RIGHT',
61-
'CIFTI_STRUCTURE_ALL_WHITE_MATTER',
62-
'CIFTI_STRUCTURE_ALL_GREY_MATTER',
63-
'CIFTI_STRUCTURE_AMYGDALA_LEFT',
64-
'CIFTI_STRUCTURE_AMYGDALA_RIGHT',
65-
'CIFTI_STRUCTURE_BRAIN_STEM',
66-
'CIFTI_STRUCTURE_CAUDATE_LEFT',
67-
'CIFTI_STRUCTURE_CAUDATE_RIGHT',
68-
'CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_LEFT',
69-
'CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_RIGHT',
70-
'CIFTI_STRUCTURE_CEREBELLUM',
71-
'CIFTI_STRUCTURE_CEREBELLUM_LEFT',
72-
'CIFTI_STRUCTURE_CEREBELLUM_RIGHT',
73-
'CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_LEFT',
74-
'CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_RIGHT',
75-
'CIFTI_STRUCTURE_CORTEX',
76-
'CIFTI_STRUCTURE_CORTEX_LEFT',
77-
'CIFTI_STRUCTURE_CORTEX_RIGHT',
78-
'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_LEFT',
79-
'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_RIGHT',
80-
'CIFTI_STRUCTURE_HIPPOCAMPUS_LEFT',
81-
'CIFTI_STRUCTURE_HIPPOCAMPUS_RIGHT',
82-
'CIFTI_STRUCTURE_OTHER',
83-
'CIFTI_STRUCTURE_OTHER_GREY_MATTER',
84-
'CIFTI_STRUCTURE_OTHER_WHITE_MATTER',
85-
'CIFTI_STRUCTURE_PALLIDUM_LEFT',
86-
'CIFTI_STRUCTURE_PALLIDUM_RIGHT',
87-
'CIFTI_STRUCTURE_PUTAMEN_LEFT',
88-
'CIFTI_STRUCTURE_PUTAMEN_RIGHT',
89-
'CIFTI_STRUCTURE_THALAMUS_LEFT',
90-
'CIFTI_STRUCTURE_THALAMUS_RIGHT')
61+
CIFTI_BRAIN_STRUCTURES = ('CIFTI_STRUCTURE_ACCUMBENS_LEFT',
62+
'CIFTI_STRUCTURE_ACCUMBENS_RIGHT',
63+
'CIFTI_STRUCTURE_ALL_WHITE_MATTER',
64+
'CIFTI_STRUCTURE_ALL_GREY_MATTER',
65+
'CIFTI_STRUCTURE_AMYGDALA_LEFT',
66+
'CIFTI_STRUCTURE_AMYGDALA_RIGHT',
67+
'CIFTI_STRUCTURE_BRAIN_STEM',
68+
'CIFTI_STRUCTURE_CAUDATE_LEFT',
69+
'CIFTI_STRUCTURE_CAUDATE_RIGHT',
70+
'CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_LEFT',
71+
'CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_RIGHT',
72+
'CIFTI_STRUCTURE_CEREBELLUM',
73+
'CIFTI_STRUCTURE_CEREBELLUM_LEFT',
74+
'CIFTI_STRUCTURE_CEREBELLUM_RIGHT',
75+
'CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_LEFT',
76+
'CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_RIGHT',
77+
'CIFTI_STRUCTURE_CORTEX',
78+
'CIFTI_STRUCTURE_CORTEX_LEFT',
79+
'CIFTI_STRUCTURE_CORTEX_RIGHT',
80+
'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_LEFT',
81+
'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_RIGHT',
82+
'CIFTI_STRUCTURE_HIPPOCAMPUS_LEFT',
83+
'CIFTI_STRUCTURE_HIPPOCAMPUS_RIGHT',
84+
'CIFTI_STRUCTURE_OTHER',
85+
'CIFTI_STRUCTURE_OTHER_GREY_MATTER',
86+
'CIFTI_STRUCTURE_OTHER_WHITE_MATTER',
87+
'CIFTI_STRUCTURE_PALLIDUM_LEFT',
88+
'CIFTI_STRUCTURE_PALLIDUM_RIGHT',
89+
'CIFTI_STRUCTURE_PUTAMEN_LEFT',
90+
'CIFTI_STRUCTURE_PUTAMEN_RIGHT',
91+
'CIFTI_STRUCTURE_THALAMUS_LEFT',
92+
'CIFTI_STRUCTURE_THALAMUS_RIGHT')
9193

9294

9395
def _value_if_klass(val, klass):
@@ -180,7 +182,10 @@ class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping):
180182
LabelTable. Display coloring of continuous-valued data is not specified
181183
by CIFTI-2.
182184
* Attributes: [NA]
183-
* Child Elements - Label (0...N)
185+
* Child Elements
186+
187+
* Label (0...N)
188+
184189
* Text Content: [NA]
185190
* Parent Element - NamedMap
186191
"""
@@ -653,7 +658,7 @@ class Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ(xml.XmlSerializable):
653658
* Child Elements: [NA]
654659
* Text Content - Sixteen floating-point values, in row-major order, that
655660
form a 4x4 homogeneous transformation matrix.
656-
* Parent Element - Volume
661+
* Parent Element - Volume
657662
658663
Attributes
659664
----------
@@ -793,7 +798,7 @@ class Cifti2BrainModel(xml.XmlSerializable):
793798
* IndexCount - Number of surface vertices or voxels in this brain
794799
model, must be positive.
795800
* ModelType - Type of model representing the brain structure (surface
796-
* or voxels). Valid values are listed in the table below.
801+
or voxels). Valid values are listed in the table below.
797802
* BrainStructure - Identifies the brain structure. Valid values for
798803
BrainStructure are listed in the table below. However, if the needed
799804
structure is not listed in the table, a message should be posted to
@@ -814,55 +819,9 @@ class Cifti2BrainModel(xml.XmlSerializable):
814819
* Text Content: [NA]
815820
* Parent Element - MatrixIndicesMap
816821
817-
ModelType Values
818-
----------------
819-
820-
========================= ================================
821-
ModelType Description
822-
========================= ================================
823-
CIFTI_MODEL_TYPE_SURFACE Modeled using surface vertices.
824-
CIFTI_MODEL_TYPE_VOXELS Modeled using voxels.
825-
========================= ================================
826-
827-
BrainStructure Values
828-
---------------------
829-
830-
=============================================
831-
BrainStructure
832-
=============================================
833-
CIFTI_STRUCTURE_ACCUMBENS_LEFT
834-
CIFTI_STRUCTURE_ACCUMBENS_RIGHT
835-
CIFTI_STRUCTURE_ALL_WHITE_MATTER
836-
CIFTI_STRUCTURE_ALL_GREY_MATTER
837-
CIFTI_STRUCTURE_AMYGDALA_LEFT
838-
CIFTI_STRUCTURE_AMYGDALA_RIGHT
839-
CIFTI_STRUCTURE_BRAIN_STEM
840-
CIFTI_STRUCTURE_CAUDATE_LEFT
841-
CIFTI_STRUCTURE_CAUDATE_RIGHT
842-
CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_LEFT
843-
CIFTI_STRUCTURE_CEREBELLAR_WHITE_MATTER_RIGHT
844-
CIFTI_STRUCTURE_CEREBELLUM
845-
CIFTI_STRUCTURE_CEREBELLUM_LEFT
846-
CIFTI_STRUCTURE_CEREBELLUM_RIGHT
847-
CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_LEFT
848-
CIFTI_STRUCTURE_CEREBRAL_WHITE_MATTER_RIGHT
849-
CIFTI_STRUCTURE_CORTEX
850-
CIFTI_STRUCTURE_CORTEX_LEFT
851-
CIFTI_STRUCTURE_CORTEX_RIGHT
852-
CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_LEFT
853-
CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_RIGHT
854-
CIFTI_STRUCTURE_HIPPOCAMPUS_LEFT
855-
CIFTI_STRUCTURE_HIPPOCAMPUS_RIGHT
856-
CIFTI_STRUCTURE_OTHER
857-
CIFTI_STRUCTURE_OTHER_GREY_MATTER
858-
CIFTI_STRUCTURE_OTHER_WHITE_MATTER
859-
CIFTI_STRUCTURE_PALLIDUM_LEFT
860-
CIFTI_STRUCTURE_PALLIDUM_RIGHT
861-
CIFTI_STRUCTURE_PUTAMEN_LEFT
862-
CIFTI_STRUCTURE_PUTAMEN_RIGHT
863-
CIFTI_STRUCTURE_THALAMUS_LEFT
864-
CIFTI_STRUCTURE_THALAMUS_RIGHT
865-
=============================================
822+
For ModelType values, see CIFTI_MODEL_TYPES module attribute.
823+
824+
For BrainStructure values, see CIFTI_BRAIN_STRUCTURES model attribute.
866825
867826
Attributes
868827
----------
@@ -873,7 +832,7 @@ class Cifti2BrainModel(xml.XmlSerializable):
873832
model_type : str
874833
One of CIFTI_MODEL_TYPES
875834
brain_structure : str
876-
One of CIFTI_BrainStructures
835+
One of CIFTI_BRAIN_STRUCTURES
877836
surface_number_of_vertices : int
878837
Number of vertices in the surface. Use only for surface-type structure
879838
voxel_indices_ijk : Cifti2VoxelIndicesIJK, optional

nibabel/cifti2/parse_cifti2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Cifti2VoxelIndicesIJK, Cifti2BrainModel, Cifti2Matrix,
1818
Cifti2MatrixIndicesMap, Cifti2NamedMap, Cifti2Parcel,
1919
Cifti2Surface, Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ,
20-
Cifti2Vertices, Cifti2Volume, CIFTI_BrainStructures,
20+
Cifti2Vertices, Cifti2Volume, CIFTI_BRAIN_STRUCTURES,
2121
CIFTI_MODEL_TYPES, _underscore, CIFTI2HeaderError)
2222
from .. import xmlutils as xml
2323
from ..spatialimages import HeaderDataError
@@ -325,7 +325,7 @@ def StartElementHandler(self, name, attrs):
325325
'Vertices element can only be a child of the CIFTI2 Parcel element'
326326
)
327327
vertices.brain_structure = attrs["BrainStructure"]
328-
if vertices.brain_structure not in CIFTI_BrainStructures:
328+
if vertices.brain_structure not in CIFTI_BRAIN_STRUCTURES:
329329
raise CIFTI2HeaderError(
330330
'BrainStructure for this Vertices element is not valid'
331331
)
@@ -391,7 +391,7 @@ def StartElementHandler(self, name, attrs):
391391
("SurfaceNumberOfVertices", int)]:
392392
if key in attrs:
393393
setattr(model, _underscore(key), dtype(attrs[key]))
394-
if model.brain_structure not in CIFTI_BrainStructures:
394+
if model.brain_structure not in CIFTI_BRAIN_STRUCTURES:
395395
raise CIFTI2HeaderError(
396396
'BrainStructure for this BrainModel element is not valid'
397397
)

0 commit comments

Comments
 (0)