Skip to content

Commit 51e6038

Browse files
vanandreweffigies
authored andcommitted
FIX: Reshape CIFTI-2 affines to 4x4 when encoded as row-major sequence
fix cifti2 transform loading without newlines add test for space separated affine Backport of gh-1059
1 parent 298ac81 commit 51e6038

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

nibabel/cifti2/parse_cifti2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ def flush_chardata(self):
538538
# conversion to numpy array
539539
c = BytesIO(data.strip().encode('utf-8'))
540540
transform = self.struct_state[-1]
541-
transform.matrix = np.loadtxt(c, dtype=np.float64)
541+
matrix = np.loadtxt(c, dtype=np.float64)
542+
transform.matrix = matrix.reshape(4, 4)
542543
c.close()
543544

544545
elif self.write_to == 'Label':

nibabel/cifti2/tests/test_cifti2io_header.py

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
datafiles = [DATA_FILE2, DATA_FILE3, DATA_FILE4, DATA_FILE5, DATA_FILE6]
4242

4343

44+
def test_space_separated_affine():
45+
img = ci.Cifti2Image.from_filename(
46+
pjoin(NIBABEL_TEST_DATA, "row_major.dconn.nii"))
47+
48+
4449
def test_read_nifti2():
4550
# Error trying to read a CIFTI-2 image from a NIfTI2-only image.
4651
filemap = ci.Cifti2Image.make_file_map()
1.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)