@@ -1476,16 +1476,28 @@ def to_file_map(self, file_map=None):
14761476 def update_headers (self ):
14771477 ''' Harmonize NIfTI headers with image data
14781478
1479+ Ensures that the NIfTI-2 header records the data shape in the last three
1480+ ``dim`` fields. Per the spec:
1481+
1482+ Because the first four dimensions in NIfTI are reserved for space and time, the CIFTI
1483+ dimensions are stored in the NIfTI header in dim[5] and up, where dim[5] is the length
1484+ of the first CIFTI dimension (number of values in a row), dim[6] is the length of the
1485+ second CIFTI dimension, and dim[7] is the length of the third CIFTI dimension, if
1486+ applicable. The fields dim[1] through dim[4] will be 1; dim[0] will be 6 or 7,
1487+ depending on whether a third matrix dimension exists.
1488+
14791489 >>> import numpy as np
14801490 >>> data = np.zeros((2,3,4))
14811491 >>> img = Cifti2Image(data)
14821492 >>> img.shape == (2, 3, 4)
14831493 True
14841494 >>> img.update_headers()
1485- >>> img.nifti_header.get_data_shape() == (2, 3, 4)
1495+ >>> img.nifti_header.get_data_shape() == (1, 1, 1, 1, 2, 3, 4)
1496+ True
1497+ >>> img.shape == (2, 3, 4)
14861498 True
14871499 '''
1488- self ._nifti_header .set_data_shape (self ._dataobj .shape )
1500+ self ._nifti_header .set_data_shape (( 1 , 1 , 1 , 1 ) + self ._dataobj .shape )
14891501
14901502 def get_data_dtype (self ):
14911503 return self ._nifti_header .get_data_dtype ()
0 commit comments