Skip to content

Commit 582cdfa

Browse files
mgxdeffigies
authored andcommitted
ENH: Update NIfTI header dimensions for CIFTI-2 compliance
1 parent f23b279 commit 582cdfa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
from collections.abc import MutableSequence, MutableMapping, Iterable
2121
from collections import OrderedDict
22+
import numpy as np
2223
from .. import xmlutils as xml
2324
from ..filebasedimages import FileBasedHeader
2425
from ..dataobj_images import DataobjImage
@@ -1484,8 +1485,14 @@ def update_headers(self):
14841485
>>> img.update_headers()
14851486
>>> img.nifti_header.get_data_shape() == (2, 3, 4)
14861487
True
1488+
>>> np.array_equal(img.nifti_header['dim'], [7, 1, 1, 1, 1, 2, 3, 4])
1489+
True
14871490
'''
14881491
self._nifti_header.set_data_shape(self._dataobj.shape)
1492+
_dims = np.ones((8), dtype=int)
1493+
_dims[0] = 7 if len(self._dataobj.shape) == 3 else 6
1494+
_dims[5:8] = (self._dataobj.shape + (1,))[:3]
1495+
self._nifti_header['dim'] = _dims
14891496

14901497
def get_data_dtype(self):
14911498
return self._nifti_header.get_data_dtype()

0 commit comments

Comments
 (0)