Commit f02bd21f authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

ENH: added command line support for output images (in FSL style)

parent 41461fc2
......@@ -40,6 +40,16 @@ def Image(filename):
return image.Image(full_filename)
def ImageOut(basename):
"""
Uses the FSL convention to create a complete image output filename
:param basename: filename provided by the user
:return: filename with extension
"""
return image.addExt(basename, mustExist=False)
def Mesh(filename):
"""
Reads in a mesh from either a GIFTI (.surf.gii) or a VTK (.vtk) file
......
......@@ -6,7 +6,7 @@
#
import argparse
from fsl.utils import parse_data, tempdir
from fsl.utils import parse_data, tempdir, path
import os.path as op
from fsl.data.vtk import VTKMesh
from fsl.data.gifti import GiftiMesh
......@@ -14,6 +14,7 @@ from fsl.data.image import Image
from fsl.data.atlases import Atlas
from pytest import raises
from .test_image import make_image
import os
datadir = op.join(op.dirname(__file__), 'testdata')
......@@ -84,6 +85,36 @@ def test_image():
image_parser.parse_args([double_filename])
def test_image_out():
image_parser = argparse.ArgumentParser("Reads an image")
image_parser.add_argument("image_out", type=parse_data.ImageOut)
for fsl_output_type, extension in (
('NIFTI', '.nii'),
('NIFTI_PAIR', '.img'),
('NIFTI_GZ', '.nii.gz')
):
os.environ['FSLOUTPUTTYPE'] = fsl_output_type
args = image_parser.parse_args(['test'])
assert path.hasExt(args.image_out, extension)
assert args.image_out == 'test' + extension
args = image_parser.parse_args(['test.nii'])
assert path.hasExt(args.image_out, '.nii')
assert args.image_out == 'test.nii'
args = image_parser.parse_args(['test.nii.gz'])
assert path.hasExt(args.image_out, '.nii.gz')
assert args.image_out == 'test.nii.gz'
args = image_parser.parse_args(['test.img'])
assert path.hasExt(args.image_out, '.img')
assert args.image_out == 'test.img'
args = image_parser.parse_args(['test.surf.gii'])
assert path.hasExt(args.image_out, extension)
assert args.image_out == 'test.surf.gii' + extension
def test_atlas():
atlas_parser = argparse.ArgumentParser('reads an atlas')
atlas_parser.add_argument('atlas', type=parse_data.Atlas)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment