CIfTI format IO
cifti2 |
Read / write access to CIfTI2 image format
Format of the NIFTI2 container format described here:
Definition of the CIFTI2 header format and file extensions attached to this email:
Filename is CIFTI-2_Main_FINAL_1March2014.pdf.
Cifti2BrainModel([index_offset, ...]) | Element representing a mapping of the dimension to vertex or voxels. |
Cifti2Header([matrix, version]) | Class for CIFTI2 header extension |
Cifti2HeaderError | Error in CIFTI2 header |
Cifti2Image([dataobj, header, nifti_header, ...]) | Class for single file CIFTI2 format image |
Cifti2Label([key, label, red, green, blue, ...]) | CIFTI2 label: association of integer key with a name and RGBA values |
Cifti2LabelTable() | CIFTI2 label table: a sequence of ``Cifti2Label``s |
Cifti2Matrix() | CIFTI2 Matrix object |
Cifti2MatrixIndicesMap(...[, ...]) | Class for Matrix Indices Map |
Cifti2MetaData([metadata]) | A list of name-value pairs |
Cifti2NamedMap([map_name, metadata, label_table]) | CIFTI2 named map: association of name and optional data with a map index |
Cifti2Parcel([name, voxel_indices_ijk, vertices]) | CIFTI2 parcel: association of a name with vertices and/or voxels |
Cifti2Surface([brain_structure, ...]) | Cifti surface: association of brain structure and number of vertices |
Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ([...]) | Matrix that translates voxel indices to spatial coordinates |
Cifti2VertexIndices([indices]) | CIFTI2 vertex indices: vertex indices for an associated brain model |
Cifti2Vertices([brain_structure, vertices]) | CIFTI2 vertices - association of brain structure and a list of vertices |
Cifti2Volume([volume_dimensions, ...]) | CIFTI2 volume: information about a volume for mappings that use voxels |
Cifti2VoxelIndicesIJK([indices]) | CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure |
load(filename) | Load cifti2 from filename |
save(img, filename) | Save cifti to filename |
Cifti2Extension([code, content]) | |
Cifti2Parser([encoding, buffer_size, verbose]) | Class to parse an XML string into a CIFTI2 header object |
Bases: nibabel.xmlutils.XmlSerializable
Element representing a mapping of the dimension to vertex or voxels.
Mapping to vertices of voxels must be specified.
Description - Maps a range of indices to surface vertices or voxels when IndicesMapToDataType is “CIFTI_INDEX_TYPE_BRAIN_MODELS.”
Attributes
- IndexOffset - The matrix index of the first brainordinate of this BrainModel. Note that matrix indices are zero-based.
- IndexCount - Number of surface vertices or voxels in this brain model, must be positive.
- ModelType - Type of model representing the brain structure (surface or voxels). Valid values are listed in the table below.
- BrainStructure - Identifies the brain structure. Valid values for BrainStructure are listed in the table below. However, if the needed structure is not listed in the table, a message should be posted to the CIFTI Forum so that a standardized name can be created for the structure and added to the table.
- SurfaceNumberOfVertices - When ModelType is CIFTI_MODEL_TYPE_SURFACE this attribute contains the actual (or true) number of vertices in the surface that is associated with this BrainModel. When this BrainModel represents all vertices in the surface, this value is the same as IndexCount. When this BrainModel represents only a subset of the surface’s vertices, IndexCount will be less than this value.
Child Elements
- VertexIndices (0...1)
- VoxelIndicesIJK (0...1)
Text Content: [NA]
Parent Element - MatrixIndicesMap
For ModelType values, see CIFTI_MODEL_TYPES module attribute.
For BrainStructure values, see CIFTI_BRAIN_STRUCTURES model attribute.
Attributes
voxel_indices_ijk | |
vertex_indices |
index_offset | int | Start of the mapping |
index_count | int | Number of elements in the array to be mapped |
model_type | str | One of CIFTI_MODEL_TYPES |
brain_structure | str | One of CIFTI_BRAIN_STRUCTURES |
surface_number_of_vertices | int | Number of vertices in the surface. Use only for surface-type structure |
Bases: nibabel.filebasedimages.FileBasedHeader, nibabel.xmlutils.XmlSerializable
Class for CIFTI2 header extension
Cifti2 Mapping class for a given index
Parameters: | index : int
|
---|---|
Returns: | cifti2_map : Cifti2MatrixIndicesMap
|
List of matrix indices that are mapped
Number of mapped indices
Bases: nibabel.dataobj_images.DataobjImage
Class for single file CIFTI2 format image
Initialize image
The image is a combination of (dataobj, header), with optional metadata in nifti_header (a NIfTI2 header). There may be more metadata in the mapping extra. Filename / file-like objects can also go in the file_map mapping.
Parameters: | dataobj : object
header : Cifti2Header instance
nifti_header : None or mapping or NIfTI2 header instance, optional
extra : None or mapping
file_map : mapping, optional
|
---|
Initialize image
The image is a combination of (dataobj, header), with optional metadata in nifti_header (a NIfTI2 header). There may be more metadata in the mapping extra. Filename / file-like objects can also go in the file_map mapping.
Parameters: | dataobj : object
header : Cifti2Header instance
nifti_header : None or mapping or NIfTI2 header instance, optional
extra : None or mapping
file_map : mapping, optional
|
---|
Load a CIFTI2 image from a file_map
Parameters: | file_map : file_map |
---|---|
Returns: | img : Cifti2Image
|
Class method to create new instance of own class from img
Parameters: | img : instance
|
---|---|
Returns: | cimg : instance
|
alias of Cifti2Header
Write image to file_map or contained self.file_map
Parameters: | file_map : None or mapping, optional
|
---|---|
Returns: | None : |
Harmonize CIFTI2 and NIfTI headers with image data
>>> import numpy as np
>>> data = np.zeros((2,3,4))
>>> img = Cifti2Image(data)
>>> img.shape == (2, 3, 4)
True
>>> img.update_headers()
>>> img.nifti_header.get_data_shape() == (2, 3, 4)
True
Bases: nibabel.xmlutils.XmlSerializable
CIFTI2 label: association of integer key with a name and RGBA values
For all color components, value is floating point with range 0.0 to 1.0.
Description - Associates a label key value with a name and a display color.
Attributes
- Key - Integer, data value which is assigned this name and color.
- Red - Red color component for label. Value is floating point with range 0.0 to 1.0.
- Green - Green color component for label. Value is floating point with range 0.0 to 1.0.
- Blue - Blue color component for label. Value is floating point with range 0.0 to 1.0.
- Alpha - Alpha color component for label. Value is floating point with range 0.0 to 1.0.
Child Elements: [NA]
Text Content - Name of the label.
Parent Element - LabelTable
Attributes
key | int, optional | Integer, data value which is assigned this name and color. |
label | str, optional | Name of the label. |
red | float, optional | Red color component for label (between 0 and 1). |
green | float, optional | Green color component for label (between 0 and 1). |
blue | float, optional | Blue color component for label (between 0 and 1). |
alpha | float, optional | Alpha color component for label (between 0 and 1). |
Returns RGBA as tuple
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableMapping
CIFTI2 label table: a sequence of ``Cifti2Label``s
Description - Used by NamedMap when IndicesMapToDataType is “CIFTI_INDEX_TYPE_LABELS” in order to associate names and display colors with label keys. Note that LABELS is the only mapping type that uses a LabelTable. Display coloring of continuous-valued data is not specified by CIFTI-2.
Attributes: [NA]
Child Elements
- Label (0...N)
Text Content: [NA]
Parent Element - NamedMap
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableSequence
CIFTI2 Matrix object
This is a list-like container where the elements are instances of Cifti2MatrixIndicesMap.
Description: contains child elements that describe the meaning of the values in the matrix.
Attributes: [NA]
Child Elements
- MetaData (0 .. 1)
- MatrixIndicesMap (1 .. N)
Text Content: [NA]
Parent Element: CIFTI
For each matrix (data) dimension, exactly one MatrixIndicesMap element must list it in the AppliesToMatrixDimension attribute.
Cifti2 Mapping class for a given index
Parameters: | index : int
|
---|---|
Returns: | cifti2_map : Cifti2MatrixIndicesMap
|
List of matrix indices that are mapped
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableSequence
Class for Matrix Indices Map
Description - Provides a mapping between matrix indices and their interpretation.
Attributes
- AppliesToMatrixDimension - Lists the dimension(s) of the matrix to which this MatrixIndicesMap applies. The dimensions of the matrix start at zero (dimension 0 describes the indices along the first dimension, dimension 1 describes the indices along the second dimension, etc.). If this MatrixIndicesMap applies to more than one matrix dimension, the values are separated by a comma.
- IndicesMapToDataType - Type of data to which the MatrixIndicesMap applies.
- NumberOfSeriesPoints - Indicates how many samples there are in a series mapping type. For example, this could be the number of timepoints in a timeseries.
- SeriesExponent - Integer, SeriesStart and SeriesStep must be multiplied by 10 raised to the power of the value of this attribute to give the actual values assigned to indices (e.g., if SeriesStart is “5” and SeriesExponent is “-3”, the value of the first series point is 0.005).
- SeriesStart - Indicates what quantity should be assigned to the first series point.
- SeriesStep - Indicates amount of change between each series point.
- SeriesUnit - Indicates the unit of the result of multiplying SeriesStart and SeriesStep by 10 to the power of SeriesExponent.
Child Elements
- BrainModel (0...N)
- NamedMap (0...N)
- Parcel (0...N)
- Surface (0...N)
- Volume (0...1)
Text Content: [NA]
Parent Element - Matrix
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableMapping
A list of name-value pairs
Description - Provides a simple method for user-supplied metadata that associates names with values.
Attributes: [NA]
Child Elements
- MD (0...N)
Text Content: [NA]
Parent Elements - Matrix, NamedMap
MD elements are a single metadata entry consisting of a name and a value.
Attributes
data | list of (name, value) tuples |
Remove metadata key-value pairs
Parameters: | metadata : dict-like datatype |
---|---|
Returns: | None : |
Bases: nibabel.xmlutils.XmlSerializable
CIFTI2 named map: association of name and optional data with a map index
Associates a name, optional metadata, and possibly a LabelTable with an index in a map.
Description - Associates a name, optional metadata, and possibly a LabelTable with an index in a map.
Attributes: [NA]
Child Elements
- MapName (1)
- LabelTable (0...1)
- MetaData (0...1)
Text Content: [NA]
Parent Element - MatrixIndicesMap
Attributes
metadata | |
label_table |
map_name | str | Name of map |
Bases: nibabel.xmlutils.XmlSerializable
CIFTI2 parcel: association of a name with vertices and/or voxels
Description - Associates a name, plus vertices and/or voxels, with an index.
Attributes
- Name - The name of the parcel
Child Elements
- Vertices (0...N)
- VoxelIndicesIJK (0...1)
Text Content: [NA]
Parent Element - MatrixIndicesMap
Attributes
voxel_indices_ijk |
name | str | Name of parcel |
vertices | list of Cifti2Vertices | Vertices associated with parcel |
Appends a Cifti2Vertices element to the Cifti2Parcel
Parameters: | vertices : Cifti2Vertices |
---|
Pops the ith vertices element from the Cifti2Parcel
Bases: nibabel.xmlutils.XmlSerializable
Cifti surface: association of brain structure and number of vertices
Description - Specifies the number of vertices for a surface, when IndicesMapToDataType is “CIFTI_INDEX_TYPE_PARCELS.” This is separate from the Parcel element because there can be multiple parcels on one surface, and one parcel may involve multiple surfaces.
Attributes
- BrainStructure - A string from the BrainStructure list to identify what surface structure this element refers to (usually left cortex, right cortex, or cerebellum).
- SurfaceNumberOfVertices - The number of vertices that this structure’s surface contains.
Child Elements: [NA]
Text Content: [NA]
Parent Element - MatrixIndicesMap
Attributes
brain_structure | str | Name of brain structure |
surface_number_of_vertices | int | Number of vertices on surface |
Bases: nibabel.xmlutils.XmlSerializable
Matrix that translates voxel indices to spatial coordinates
Description - Contains a matrix that translates Voxel IJK Indices to spatial XYZ coordinates (+X=>right, +Y=>anterior, +Z=> superior). The resulting coordinate is the center of the voxel.
Attributes
- MeterExponent - Integer, specifies that the coordinate result from the transformation matrix should be multiplied by 10 to this power to get the spatial coordinates in meters (e.g., if this is “-3”, then the transformation matrix is in millimeters).
Child Elements: [NA]
Text Content - Sixteen floating-point values, in row-major order, that form a 4x4 homogeneous transformation matrix.
Parent Element - Volume
Attributes
meter_exponent | int | See attribute description above. |
matrix | array-like shape (4, 4) | Affine transformation matrix from voxel indices to RAS space. |
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableSequence
CIFTI2 vertex indices: vertex indices for an associated brain model
The vertex indices (which are independent for each surface, and zero-based) that are used in this brain model[.] The parent BrainModel’s index_count indicates the number of indices.
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableSequence
CIFTI2 vertices - association of brain structure and a list of vertices
Description - Contains a BrainStructure type and a list of vertex indices within a Parcel.
Attributes
- BrainStructure - A string from the BrainStructure list to identify what surface this vertex list is from (usually left cortex, right cortex, or cerebellum).
Child Elements: [NA]
Text Content - Vertex indices (which are independent for each surface, and zero-based) separated by whitespace characters.
Parent Element - Parcel
The class behaves like a list of Vertex indices (which are independent for each surface, and zero-based)
Attributes
brain_structure | str | A string from the BrainStructure list to identify what surface this vertex list is from (usually left cortex, right cortex, or cerebellum). |
Bases: nibabel.xmlutils.XmlSerializable
CIFTI2 volume: information about a volume for mappings that use voxels
Description - Provides information about the volume for any mappings that use voxels.
Attributes
- VolumeDimensions - Three integer values separated by commas, the lengths of the three volume file dimensions that are related to spatial coordinates, in number of voxels. Voxel indices (which are zero-based) that are used in the mapping that this element applies to must be within these dimensions.
Child Elements
- TransformationMatrixVoxelIndicesIJKtoXYZ (1)
Text Content: [NA]
Parent Element - MatrixIndicesMap
Attributes
volume_dimensions | array-like shape (3,) | See attribute description above. |
transformation_matrix_voxel_indices_ijk_to_xyz | Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ | Matrix that translates voxel indices to spatial coordinates |
Bases: nibabel.xmlutils.XmlSerializable, _abcoll.MutableSequence
CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure
Each element of this sequence is a triple of integers.
Load cifti2 from filename
Parameters: | filename : str
|
---|---|
Returns: | img : Cifti2Image
|
Raises: | ImageFileError: if `filename` doesn’t look like cifti : IOError : if filename does not exist |
Save cifti to filename
Parameters: | filename : str
|
---|
Bases: nibabel.nifti1.Nifti1Extension
Bases: nibabel.xmlutils.XmlParser
Class to parse an XML string into a CIFTI2 header object
Parameters: | encoding : str
buffer_size: None or int, optional :
verbose : int, optional
|
---|
Parameters: | encoding : str
buffer_size: None or int, optional :
verbose : int, optional
|
---|
Collect character data chunks pending collation
The parser breaks the data up into chunks of size depending on the buffer_size of the parser. A large bit of character data, with standard parser buffer_size (such as 8K) can easily span many calls to this function. We thus collect the chunks and process them when we hit start or end tags.
Collate and process collected character data
True if there is character data pending for processing