Repository: nipy/nipype

Issue:
Missing mask1 and mask2 arguments in doc example for Similarity
The mandatory arguments mask1 and mask2 are missing from the example here:

http://nipy.sourceforge.net/nipype/interfaces/generated/nipype.interfaces.nipy.utils.html

ApplyXFM does not set default value of required flag
from @davidgutman

Just noticed this, after scratching my head for a bit....  by default
it seems the ApplyXfm doesn't bass the applyxfm.inputs.apply_xfm=True
parameter... in which case it is rerunning the registration ...

I couldn't figure out why my transformation was working oddly and
realized it's because that flag wasn't being passed, and I
inadvertently assumed that that was the default behavior of ApplyXfm
(i.e. to apply an XFM)....

Not sure if this should be changed or not as the default behavior that
can be overridden (in which case.. you'd probably just want to use
fsl.FLIRT() anyway)..

More of a semantics thing I guess..

ApplyXfm
Code: http://github.com/nipy/nipype/blob/master/nipype/interfaces/fsl/preprocess.py#L495

Wraps command flirt

Currently just a light wrapper around FLIRT, with no modifications

ApplyXfm is used to apply an existing tranform to an image

Examples

> > > import nipype.interfaces.fsl as fsl
> > > from nipype.testing import example_data
> > > applyxfm = fsl.ApplyXfm()
> > > applyxfm.inputs.in_file = example_data('structural.nii')
> > > applyxfm.inputs.in_matrix_file = example_data('trans.mat')
> > > applyxfm.inputs.out_file = 'newfile.nii'
> > > applyxfm.inputs.reference = example_data('mni.nii')
> > > applyxfm.inputs.apply_xfm = True
> > > result = applyxfm.run()
> > > Inputs:

[Mandatory]
in_file: (an existing file name)
        input file
reference: (an existing file name)
        reference file

[Optional]
angle_rep: ('quaternion' or 'euler')
        representation of rotation angles
apply_xfm: (a boolean)
        apply transformation supplied by in_matrix_file
## 

David A Gutman, M.D. Ph.D.



Discussion:

Hey,

I just started building my own preproc-pipeline and just found out about this and wanted to post this issue. It took me a lot of time and frustration to figure out today. I do love the software so keep up the good work.

:)


Resolving patch:
diff --git a/nipype/interfaces/nipy/preprocess.py b/nipype/interfaces/nipy/preprocess.py
--- a/nipype/interfaces/nipy/preprocess.py
+++ b/nipype/interfaces/nipy/preprocess.py
@@ -5,7 +5,7 @@
 import numpy as np
 
 from ...utils.misc import package_check
-from ...utils.filemanip import split_filename
+from ...utils.filemanip import split_filename, fname_presuffix
 
 
 try:
@@ -183,3 +183,65 @@ def _list_outputs(self):
         outputs['out_file'] = self._out_file_path
         outputs['par_file'] = self._par_file_path
         return outputs
+
+
+class TrimInputSpec(BaseInterfaceInputSpec):
+    in_file = File(
+        exists=True, mandatory=True,
+        desc="EPI image to trim")
+    begin_index = traits.Int(
+        0,usedefault=True,
+        desc='first volume')
+    end_index = traits.Int(
+        0,usedefault=True,
+        desc='last volume indexed as in python (and 0 for last)')
+    out_file = File(desc='output filename')
+    suffix = traits.Str(
+        '_trim',usedefault=True,
+        desc='suffix for out_file to use if no out_file provided')
+
+class TrimOutputSpec(TraitedSpec):
+    out_file = File(exists=True)
+
+class Trim(BaseInterface):
+    """ Simple interface to trim a few volumes from a 4d fmri nifti file
+
+    Examples
+    --------
+    >>> from nipype.interfaces.nipy.preprocess import Trim
+    >>> trim = Trim()
+    >>> trim.inputs.in_file = ['functional.nii']
+    >>> trim.inputs.begin_index = 3 # remove 3 first volumes
+    >>> res = trim.run() # doctest: +SKIP
+
+    """
+
+    input_spec = TrimInputSpec
+    output_spec = TrimOutputSpec
+
+    def _run_interface(self, runtime):
+        out_file = self._list_outputs()['out_file']
+        nii = nb.load(self.inputs.in_file)
+        if self.inputs.end_index == 0:
+            s = slice(self.inputs.begin_index,nii.shape[3])
+        else:
+            s = slice(self.inputs.begin_index,self.inputs.end_index)
+        nii2 = nb.Nifti1Image(
+            nii.get_data()[...,s],
+            nii.get_affine(),
+            nii.get_header())
+        nb.save(nii2,out_file)
+        return runtime
+
+    def _list_outputs(self):
+        outputs = self.output_spec().get()
+        outputs['out_file'] = self.inputs.out_file
+        if not isdefined(outputs['out_file']):
+            outputs['out_file'] = fname_presuffix(
+                self.inputs.in_file,
+                newpath=os.getcwd(),
+                suffix=self.inputs.suffix)
+        outputs['out_file'] = os.path.abspath(outputs['out_file'])
+        return outputs
+
+


Test patch: