def to_mapping(self, dim): """ Converts the parcels to a MatrixIndicesMap for storage in CIFTI format Parameters ---------- dim : int which dimension of the CIFTI vector/matrix is described by this dataset (zero-based) Returns ------- cifti2.Cifti2MatrixIndicesMap """ mim = cifti2.Cifti2MatrixIndicesMap([dim], 'CIFTI_INDEX_TYPE_PARCELS') if self.affine is not None: affine = cifti2.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ(-3, matrix=self.affine) mim.volume = cifti2.Cifti2Volume(self.volume_shape, affine) for name, nvertex in self.nvertices.items(): mim.append(cifti2.Cifti2Surface(name, nvertex)) for name, voxels, vertices in self.arr: cifti_voxels = cifti2.Cifti2VoxelIndicesIJK(voxels) element = cifti2.Cifti2Parcel(name, cifti_voxels) for name, idx_vertices in vertices.items(): element.vertices.append(cifti2.Cifti2Vertices(name, idx_vertices)) mim.append(element) return mim
def create_parcel_map(applies_to_matrix_dimension): mapping = ci.Cifti2MatrixIndicesMap(applies_to_matrix_dimension, 'CIFTI_INDEX_TYPE_PARCELS') for name, elements in parcels: surfaces = [] volume = None for element in elements: if isinstance(element[0], str): surfaces.append(ci.Cifti2Vertices(element[0], element[1])) else: volume = ci.Cifti2VoxelIndicesIJK(element) mapping.append(ci.Cifti2Parcel(name, volume, surfaces)) mapping.extend([ ci.Cifti2Surface('CIFTI_STRUCTURE_CORTEX_%s' % orientation, number_of_vertices) for orientation in ['LEFT', 'RIGHT'] ]) mapping.volume = ci.Cifti2Volume( dimensions, ci.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ(-3, affine)) return mapping
def test_cifti2_surface(): s = ci.Cifti2Surface() assert_raises(ci.Cifti2HeaderError, s.to_xml)
def test_cifti2_surface(): s = ci.Cifti2Surface() with pytest.raises(ci.Cifti2HeaderError): s.to_xml()