Skip to content

Commit aba96da

Browse files
Michiel CottaarMichiel Cottaar
authored andcommitted
ENH: raise warning if creating Cifti2Image with incorrect shape
1 parent 61e6b6a commit aba96da

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from ..nifti2 import Nifti2Image, Nifti2Header
3131
from ..arrayproxy import reshape_dataobj
3232
from ..keywordonly import kw_only_meth
33+
from warnings import warn
3334

3435

3536
def _float_01(val):
@@ -1374,12 +1375,19 @@ def __init__(self,
13741375
super(Cifti2Image, self).__init__(dataobj, header=header,
13751376
extra=extra, file_map=file_map)
13761377
self._nifti_header = Nifti2Header.from_header(nifti_header)
1378+
13771379
# if NIfTI header not specified, get data type from input array
13781380
if nifti_header is None:
13791381
if hasattr(dataobj, 'dtype'):
13801382
self._nifti_header.set_data_dtype(dataobj.dtype)
13811383
self.update_headers()
13821384

1385+
if self._nifti_header.get_data_shape() != self.header.matrix.get_data_shape():
1386+
warn("Dataobj shape {} does not match shape expected from CIFTI-2 header {}".format(
1387+
self._dataobj.shape, self.header.matrix.get_data_shape()
1388+
))
1389+
1390+
13831391
@property
13841392
def nifti_header(self):
13851393
return self._nifti_header

0 commit comments

Comments
 (0)