Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nibabel/cifti2/parse_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def flush_chardata(self):
# conversion to numpy array
c = BytesIO(data.strip().encode('utf-8'))
vertices = self.struct_state[-1]
vertices.extend(np.loadtxt(c, dtype=np.int))
vertices.extend(np.loadtxt(c, dtype=np.int, ndmin=1))
c.close()

elif self.write_to == 'VoxelIndices':
Expand All @@ -531,7 +531,7 @@ def flush_chardata(self):
# conversion to numpy array
c = BytesIO(data.strip().encode('utf-8'))
index = self.struct_state[-1]
index.extend(np.loadtxt(c, dtype=np.int))
index.extend(np.loadtxt(c, dtype=np.int, ndmin=1))
c.close()

elif self.write_to == 'TransformMatrix':
Expand Down
35 changes: 29 additions & 6 deletions nibabel/cifti2/tests/test_new_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
[61, 59, 60],
[61, 60, 59],
[80, 90, 92]]),
('CIFTI_STRUCTURE_CORTEX_LEFT', [0, 1000, 1301, 19972, 27312])]
('CIFTI_STRUCTURE_CORTEX_LEFT', [0, 1000, 1301, 19972, 27312]),
('CIFTI_STRUCTURE_CORTEX_RIGHT', [207])
]


def create_geometry_map(applies_to_matrix_dimension):
Expand All @@ -35,25 +37,34 @@ def create_geometry_map(applies_to_matrix_dimension):
model_type='CIFTI_MODEL_TYPE_VOXELS',
brain_structure=brain_models[0][0],
voxel_indices_ijk=voxels)

vertices = ci.Cifti2VertexIndices(np.array(brain_models[1][1]))
left_cortex = ci.Cifti2BrainModel(index_offset=4, index_count=5,
model_type='CIFTI_MODEL_TYPE_SURFACE',
brain_structure=brain_models[1][0],
vertex_indices=vertices)
left_cortex.surface_number_of_vertices = number_of_vertices

vertices = ci.Cifti2VertexIndices(np.array(brain_models[2][1]))
right_cortex = ci.Cifti2BrainModel(index_offset=9, index_count=1,
model_type='CIFTI_MODEL_TYPE_SURFACE',
brain_structure=brain_models[2][0],
vertex_indices=vertices)
right_cortex.surface_number_of_vertices = number_of_vertices

volume = ci.Cifti2Volume(dimensions,
ci.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ(-3,
affine))
return ci.Cifti2MatrixIndicesMap(applies_to_matrix_dimension,
'CIFTI_INDEX_TYPE_BRAIN_MODELS',
maps=[left_thalamus, left_cortex, volume])
maps=[left_thalamus, left_cortex, right_cortex, volume])


def check_geometry_map(mapping):
assert_equal(mapping.indices_map_to_data_type,
'CIFTI_INDEX_TYPE_BRAIN_MODELS')
assert_equal(len(list(mapping.brain_models)), 2)
left_thalamus, left_cortex = mapping.brain_models
assert_equal(len(list(mapping.brain_models)), 3)
left_thalamus, left_cortex, right_cortex = mapping.brain_models

assert_equal(left_thalamus.index_offset, 0)
assert_equal(left_thalamus.index_count, 4)
Expand All @@ -71,9 +82,18 @@ def check_geometry_map(mapping):
assert_equal(left_cortex.vertex_indices._indices, brain_models[1][1])
assert_equal(left_cortex.surface_number_of_vertices, number_of_vertices)

assert_equal(right_cortex.index_offset, 9)
assert_equal(right_cortex.index_count, 1)
assert_equal(right_cortex.model_type, 'CIFTI_MODEL_TYPE_SURFACE')
assert_equal(right_cortex.brain_structure, brain_models[2][0])
assert_equal(right_cortex.voxel_indices_ijk, None)
assert_equal(right_cortex.vertex_indices._indices, brain_models[2][1])
assert_equal(right_cortex.surface_number_of_vertices, number_of_vertices)

assert_equal(mapping.volume.volume_dimensions, dimensions)
assert_true((mapping.volume.transformation_matrix_voxel_indices_ijk_to_xyz.matrix == affine).all())


parcels = [('volume_parcel', ([[60, 60, 60],
[61, 59, 60],
[61, 60, 59],
Expand All @@ -84,7 +104,10 @@ def check_geometry_map(mapping):
[0, 100, 381]))),
('mixed_parcel', ([[71, 81, 39],
[53, 21, 91]],
('CIFTI_STRUCTURE_CORTEX_LEFT', [71, 88, 999])))]
('CIFTI_STRUCTURE_CORTEX_LEFT', [71, 88, 999]))),
('single_element', ([[71, 81, 39]],
('CIFTI_STRUCTURE_CORTEX_LEFT', [40]))),
]


def create_parcel_map(applies_to_matrix_dimension):
Expand All @@ -109,7 +132,7 @@ def create_parcel_map(applies_to_matrix_dimension):

def check_parcel_map(mapping):
assert_equal(mapping.indices_map_to_data_type, 'CIFTI_INDEX_TYPE_PARCELS')
assert_equal(len(list(mapping.parcels)), 3)
assert_equal(len(list(mapping.parcels)), len(parcels))
for (name, elements), parcel in zip(parcels, mapping.parcels):
assert_equal(parcel.name, name)
idx_surface = 0
Expand Down