Skip to content
Snippets Groups Projects
Commit f2ce0ed9 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Better support for nifti1/2 + FSLOUTPUTTYPE

parent a33a8492
No related branches found
No related tags found
No related merge requests found
......@@ -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')
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment