|
19 | 19 | import re
|
20 | 20 | from collections.abc import MutableSequence, MutableMapping, Iterable
|
21 | 21 | from collections import OrderedDict
|
| 22 | +from warnings import warn |
| 23 | + |
| 24 | +import numpy as np |
| 25 | + |
22 | 26 | from .. import xmlutils as xml
|
23 | 27 | from ..filebasedimages import FileBasedHeader, SerializableImage
|
24 | 28 | from ..dataobj_images import DataobjImage
|
25 | 29 | from ..nifti1 import Nifti1Extensions
|
26 | 30 | from ..nifti2 import Nifti2Image, Nifti2Header
|
27 | 31 | from ..arrayproxy import reshape_dataobj
|
28 | 32 | from ..caret import CaretMetaData
|
29 |
| -from warnings import warn |
| 33 | +from ..volumeutils import make_dt_codes |
30 | 34 |
|
31 | 35 |
|
32 | 36 | def _float_01(val):
|
@@ -1383,7 +1387,8 @@ def __init__(self,
|
1383 | 1387 | header=None,
|
1384 | 1388 | nifti_header=None,
|
1385 | 1389 | extra=None,
|
1386 |
| - file_map=None): |
| 1390 | + file_map=None, |
| 1391 | + dtype=None): |
1387 | 1392 | """ Initialize image
|
1388 | 1393 |
|
1389 | 1394 | The image is a combination of (dataobj, header), with optional metadata
|
@@ -1415,9 +1420,10 @@ def __init__(self,
|
1415 | 1420 | self._nifti_header = LimitedNifti2Header.from_header(nifti_header)
|
1416 | 1421 |
|
1417 | 1422 | # 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) |
1421 | 1427 | self.update_headers()
|
1422 | 1428 |
|
1423 | 1429 | if self._dataobj.shape != self.header.matrix.get_data_shape():
|
|
0 commit comments