From d5cdfa36b09d711f7c29fdc831ad8f1459c9f3f4 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Thu, 2 Jul 2020 11:20:05 -0400 Subject: [PATCH] ENH: Update NIfTI header dimensions for CIFTI-2 compliance --- nibabel/cifti2/cifti2.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index bd86ebfaa7..11c71e26ec 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -19,6 +19,7 @@ import re from collections.abc import MutableSequence, MutableMapping, Iterable from collections import OrderedDict +import numpy as np from .. import xmlutils as xml from ..filebasedimages import FileBasedHeader from ..dataobj_images import DataobjImage @@ -1484,8 +1485,14 @@ def update_headers(self): >>> img.update_headers() >>> img.nifti_header.get_data_shape() == (2, 3, 4) True + >>> np.array_equal(img.nifti_header['dim'], [7, 1, 1, 1, 1, 2, 3, 4]) + True """ self._nifti_header.set_data_shape(self._dataobj.shape) + _dims = np.ones((8), dtype=int) + _dims[0] = 7 if len(self._dataobj.shape) == 3 else 6 + _dims[5:8] = (self._dataobj.shape + (1,))[:3] + self._nifti_header['dim'] = _dims def get_data_dtype(self): return self._nifti_header.get_data_dtype()