Skip to content

Commit 264af7c

Browse files
committed
resolved conflict
2 parents 76742de + 170210a commit 264af7c

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Release 0.4 (FUTURE)
22
======================
33

44
* ENH: New interface: freesurfer.ApplyMask (mri_mask)
5+
* ENH: New FSL interface -- SwapDimensions (fslswapdim)
56

67
Release 0.3.4 (Jan 12, 2011)
78
======================

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ImageMaths, ImageMeants, ImageStats,
2323
FilterRegressor, Overlay, Slicer,
2424
PlotTimeSeries, PlotMotionParams,
25-
ConvertXFM)
25+
ConvertXFM, SwapDimensions)
2626
from nipype.interfaces.fsl.dti import (EddyCorrect, BEDPOSTX, DTIFit,
2727
ProbTrackX, VecReg, ProjThresh,
2828
FindTheBiggest)

nipype/interfaces/fsl/tests/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,29 @@ def test_convertxfm():
355355
"convert_xfm -omat bar.mat -concat %s %s"%(filelist[1], filelist[0])
356356

357357
clean_directory(outdir, cwd)
358+
359+
@skipif(no_fsl)
360+
def test_swapdims():
361+
files, testdir, origdir = create_files_in_directory()
362+
swap = fsl.SwapDimensions()
363+
364+
# Test the underlying command
365+
yield assert_equal, swap.cmd, "fslswapdim"
366+
367+
# Test mandatory args
368+
args = [dict(in_file=files[0]), dict(new_dims=("x","y","z"))]
369+
for arg in args:
370+
wontrun = fsl.SwapDimensions(**arg)
371+
yield assert_raises, ValueError, wontrun.run
372+
373+
# Now test a basic command line
374+
swap.inputs.in_file = files[0]
375+
swap.inputs.new_dims = ("x", "y", "z")
376+
yield assert_equal, swap.cmdline, "fslswapdim a.nii x y z %s"%os.path.join(testdir, "a_newdims.nii")
377+
378+
# Test that we can set an output name
379+
swap.inputs.out_file = "b.nii"
380+
yield assert_equal, swap.cmdline, "fslswapdim a.nii x y z b.nii"
381+
382+
# Clean up
383+
clean_directory(testdir, origdir)

nipype/interfaces/fsl/utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,45 @@ def _gen_filename(self, name):
832832
if name == "out_file":
833833
return self._list_outputs()["out_file"]
834834
return None
835+
836+
837+
class SwapDimensionsInputSpec(FSLCommandInputSpec):
838+
839+
in_file = File(exists=True, mandatory=True, argstr="%s", position="1",
840+
desc="input image")
841+
_dims = ["x","-x","y","-y","z","-z","RL","LR","AP","PA","IS","SI"]
842+
new_dims = traits.Tuple(traits.Enum(_dims), traits.Enum(_dims), traits.Enum(_dims),
843+
argstr="%s %s %s", mandatory=True,
844+
desc="3-tuple of new dimension order")
845+
out_file = File(genfile=True, argstr="%s", desc="image to write")
846+
847+
class SwapDimensionsOutputSpec(TraitedSpec):
848+
849+
out_file = File(exists=True, desc="image with new dimensions")
850+
851+
class SwapDimensions(FSLCommand):
852+
"""Use fslswapdim to alter the orientation of an image.
853+
854+
This interface accepts a three-tuple corresponding to the new
855+
orientation. You may either provide dimension ids in the form of
856+
(-)x, (-)y, or (-z), or nifti-syle dimension codes (RL, LR, AP, PA, IS, SI).
857+
858+
"""
859+
_cmd = "fslswapdim"
860+
input_spec = SwapDimensionsInputSpec
861+
output_spec = SwapDimensionsOutputSpec
862+
863+
def _list_outputs(self):
864+
outputs = self._outputs().get()
865+
outputs["out_file"] = self.inputs.out_file
866+
if not isdefined(self.inputs.out_file):
867+
outputs["out_file"] = fname_presuffix(self.inputs.in_file,
868+
suffix="_newdims",
869+
use_ext=True,
870+
newpath=os.getcwd())
871+
return outputs
872+
873+
def _gen_filename(self, name):
874+
if name == "out_file":
875+
return self._list_outputs()["out_file"]
876+
return None

0 commit comments

Comments
 (0)