diff --git a/fsl/data/image.py b/fsl/data/image.py index f02023ff92abc26c1e9a24e7d2e36765dd76059c..a12f39b12eec26064096a23dcc9365726588e3d2 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -39,7 +39,6 @@ import json import string import logging import tempfile -import warnings import six import numpy as np @@ -1099,11 +1098,12 @@ class Image(Nifti): if header is not None: xform = header.get_best_affine() else: xform = np.identity(4) - # We default to NIFTI1 and not - # NIFTI2, because the rest of - # FSL is not yet NIFTI2 compatible. + # default to NIFTI1 if FSLOUTPUTTYPE + # is not set, just to be safe. if header is None: - ctr = nib.nifti1.Nifti1Image + outputType = os.environ.get('FSLOUTPUTTYPE', 'NIFTI_GZ') + if 'NIFTI2' in outputType: ctr = nib.Nifti2Image + else: ctr = nib.Nifti1Image # make sure that the data type is correct, # in case this header was passed in from @@ -1648,9 +1648,14 @@ def defaultExt(): # TODO: Add analyze support. options = { - 'NIFTI' : '.nii', - 'NIFTI_PAIR' : '.img', - 'NIFTI_GZ' : '.nii.gz', + 'NIFTI' : '.nii', + 'NIFTI2' : '.nii', + 'NIFTI_GZ' : '.nii.gz', + 'NIFTI2_GZ' : '.nii.gz', + 'NIFTI_PAIR' : '.img', + 'NIFTI2_PAIR' : '.img', + 'NIFTI_PAIR_GZ' : '.img.gz', + 'NIFTI2_PAIR_GZ' : '.img.gz', } outputType = os.environ.get('FSLOUTPUTTYPE', 'NIFTI_GZ') diff --git a/tests/test_image.py b/tests/test_image.py index 75ec686a9cdfba1d682d7b992fdd9820e1573512..d5fbd94c0eef0f0c764d0dfce8885cbfe0e69350 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -246,6 +246,11 @@ def _test_Image_atts(imgtype): allowedExts = fslimage.ALLOWED_EXTENSIONS fileGroups = fslimage.FILE_GROUPS + typeMap = {np.uint8 : constants.NIFTI_DT_UINT8, + np.int16 : constants.NIFTI_DT_INT16, + np.int32 : constants.NIFTI_DT_INT32, + np.float32 : constants.NIFTI_DT_FLOAT32, + np.float64 : constants.NIFTI_DT_FLOAT64} # (file, dims, pixdims, dtype) dtypes = [np.uint8, np.int16, np.int32, np.float32, np.double] @@ -307,14 +312,15 @@ def _test_Image_atts(imgtype): assert tuple(i.nibImage.shape) == tuple(dims) assert tuple(i.nibImage.header.get_zooms()) == tuple(pixdims) - assert i.nvals == 1 - assert i.ndim == expndims - assert i.dtype == dtype - assert i.name == op.basename(path) - assert i.dataSource == fslpath.addExt(path, - allowedExts=allowedExts, - mustExist=True, - fileGroups=fileGroups) + assert i.nvals == 1 + assert i.ndim == expndims + assert i.dtype == dtype + assert i.niftiDataType == typeMap[dtype] + assert i.name == op.basename(path) + assert i.dataSource == fslpath.addExt(path, + allowedExts=allowedExts, + mustExist=True, + fileGroups=fileGroups) i = None