Skip to content
Snippets Groups Projects
Commit 4dcba47b authored by Paul McCarthy's avatar Paul McCarthy
Browse files

New function defaultExt, which checks FSLOUTPUTTYPE, and returns an

appropriate extension
parent bfb5f567
No related branches found
No related tags found
No related merge requests found
...@@ -27,12 +27,14 @@ and file names: ...@@ -27,12 +27,14 @@ and file names:
looksLikeImage looksLikeImage
removeExt removeExt
addExt addExt
defaultExt
loadIndexedImageFile loadIndexedImageFile
""" """
import logging import os
import os.path as op import os.path as op
import logging
import six import six
import numpy as np import numpy as np
...@@ -758,10 +760,6 @@ ambiguities - see :func:`fsl.utils.path.addExt`. ...@@ -758,10 +760,6 @@ ambiguities - see :func:`fsl.utils.path.addExt`.
""" """
DEFAULT_EXTENSION = '.nii.gz'
"""The default file extension (TODO read this from ``$FSLOUTPUTTYPE``)."""
PathError = fslpath.PathError PathError = fslpath.PathError
"""Error raised by :mod:`fsl.utils.path` functions when an error occurs. """Error raised by :mod:`fsl.utils.path` functions when an error occurs.
Made available in this module for convenience. Made available in this module for convenience.
...@@ -809,10 +807,29 @@ def addExt(prefix, mustExist=True): ...@@ -809,10 +807,29 @@ def addExt(prefix, mustExist=True):
return fslpath.addExt(prefix, return fslpath.addExt(prefix,
ALLOWED_EXTENSIONS, ALLOWED_EXTENSIONS,
mustExist, mustExist,
DEFAULT_EXTENSION, defaultExt(),
fileGroups=FILE_GROUPS) fileGroups=FILE_GROUPS)
def defaultExt():
"""Returns the default NIFTI file extension that should be used.
If the ``$FSLOUTPUTTYPE`` variable is set, its value is used.
Otherwise, ``.nii.gz`` is returned.
"""
# TODO: Add analyze support.
options = {
'NIFTI' : '.nii',
'NIFTI_PAIR' : '.img',
'NIFTI_GZ' : '.nii.gz',
}
outputType = os.environ.get('FSLOUTPUTTYPE', 'NIFTI_GZ')
return options.get(outputType, '.nii.gz')
def loadIndexedImageFile(filename): def loadIndexedImageFile(filename):
"""Loads the given image file using ``nibabel`` and ``indexed_gzip``. """Loads the given image file using ``nibabel`` and ``indexed_gzip``.
......
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