Skip to content

Commit 696840f

Browse files
committed
ENH: Add dtype argument to Cifti2Image
1 parent 82b0b05 commit 696840f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
import re
2020
from collections.abc import MutableSequence, MutableMapping, Iterable
2121
from collections import OrderedDict
22+
from warnings import warn
23+
24+
import numpy as np
25+
2226
from .. import xmlutils as xml
2327
from ..filebasedimages import FileBasedHeader, SerializableImage
2428
from ..dataobj_images import DataobjImage
2529
from ..nifti1 import Nifti1Extensions
2630
from ..nifti2 import Nifti2Image, Nifti2Header
2731
from ..arrayproxy import reshape_dataobj
2832
from ..caret import CaretMetaData
29-
from warnings import warn
33+
from ..volumeutils import make_dt_codes
3034

3135

3236
def _float_01(val):
@@ -1383,7 +1387,8 @@ def __init__(self,
13831387
header=None,
13841388
nifti_header=None,
13851389
extra=None,
1386-
file_map=None):
1390+
file_map=None,
1391+
dtype=None):
13871392
""" Initialize image
13881393
13891394
The image is a combination of (dataobj, header), with optional metadata
@@ -1415,9 +1420,10 @@ def __init__(self,
14151420
self._nifti_header = LimitedNifti2Header.from_header(nifti_header)
14161421

14171422
# if NIfTI header not specified, get data type from input array
1418-
if nifti_header is None:
1419-
if hasattr(dataobj, 'dtype'):
1420-
self._nifti_header.set_data_dtype(dataobj.dtype)
1423+
if dtype is not None:
1424+
self.set_data_dtype(dtype)
1425+
elif nifti_header is None and hasattr(dataobj, 'dtype'):
1426+
self.set_data_dtype(dataobj.dtype)
14211427
self.update_headers()
14221428

14231429
if self._dataobj.shape != self.header.matrix.get_data_shape():

0 commit comments

Comments
 (0)