Skip to content
5 changes: 3 additions & 2 deletions nipype/interfaces/fsl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

Examples
--------
See the docstrings of the individual classes for examples.
See the docstrings of the individual classes for examples.

"""
from __future__ import print_function, division, unicode_literals, absolute_import
Expand Down Expand Up @@ -263,4 +263,5 @@ def no_fsl():

def no_fsl_course_data():
"""check if fsl_course data is present"""
return not ('FSL_COURSE_DATA' in os.environ and os.path.isdir(os.path.abspath(os.environ['FSL_COURSE_DATA'])))
return not ('FSL_COURSE_DATA' in os.environ and
os.path.isdir(os.path.abspath(os.environ['FSL_COURSE_DATA'])))
571 changes: 354 additions & 217 deletions nipype/interfaces/fsl/dti.py

Large diffs are not rendered by default.

72 changes: 40 additions & 32 deletions nipype/interfaces/fsl/epi.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ def _parse_inputs(self, skip=None):
# If not defined, assume index are the first N entries in the
# parameters file, for N input images.
if not isdefined(self.inputs.in_index):
self.inputs.in_index = list(range(1, len(self.inputs.in_files) + 1))
self.inputs.in_index = list(
range(1, len(self.inputs.in_files) + 1))

return super(ApplyTOPUP, self)._parse_inputs(skip=skip)

Expand Down Expand Up @@ -489,7 +490,8 @@ def _num_threads_update(self):
if 'OMP_NUM_THREADS' in self.inputs.environ:
del self.inputs.environ['OMP_NUM_THREADS']
else:
self.inputs.environ['OMP_NUM_THREADS'] = str(self.inputs.num_threads)
self.inputs.environ['OMP_NUM_THREADS'] = str(
self.inputs.num_threads)

def _format_arg(self, name, spec, value):
if name == 'in_topup_fieldcoef':
Expand All @@ -500,8 +502,10 @@ def _format_arg(self, name, spec, value):

def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_corrected'] = os.path.abspath('%s.nii.gz' % self.inputs.out_base)
outputs['out_parameter'] = os.path.abspath('%s.eddy_parameters' % self.inputs.out_base)
outputs['out_corrected'] = os.path.abspath(
'%s.nii.gz' % self.inputs.out_base)
outputs['out_parameter'] = os.path.abspath(
'%s.eddy_parameters' % self.inputs.out_base)
return outputs


Expand Down Expand Up @@ -573,7 +577,8 @@ class EpiRegInputSpec(FSLCommandInputSpec):
position=-3, desc='wholehead T1 image')
t1_brain = File(exists=True, argstr='--t1brain=%s', mandatory=True,
position=-2, desc='brain extracted T1 image')
out_base = traits.String("epi2struct", desc='output base name', argstr='--out=%s',
out_base = traits.String("epi2struct", desc='output base name',
argstr='--out=%s',
position=-1, usedefault=True)
fmap = File(exists=True, argstr='--fmap=%s',
desc='fieldmap image (in rad/s)')
Expand Down Expand Up @@ -620,7 +625,8 @@ class EpiRegOutputSpec(TraitedSpec):
fullwarp = File(exists=True,
desc='warpfield to unwarp epi and transform into \
structural space')
wmseg = File(exists=True, desc='white matter segmentation used in flirt bbr')
wmseg = File(exists=True,
desc='white matter segmentation used in flirt bbr')
wmedge = File(exists=True, desc='white matter edges for visualization')


Expand Down Expand Up @@ -659,32 +665,34 @@ def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = os.path.join(os.getcwd(),
self.inputs.out_base + '.nii.gz')
if not (isdefined(self.inputs.no_fmapreg) and self.inputs.no_fmapreg) and isdefined(self.inputs.fmap):
outputs['out_1vol'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_1vol.nii.gz')
outputs['fmap2str_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmap2str.mat')
outputs['fmap2epi_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi.mat')
outputs['fmap_epi'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi.nii.gz')
outputs['fmap_str'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2str.nii.gz')
outputs['fmapmag_str'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmap2str.nii.gz')
outputs['shiftmap'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi_shift.nii.gz')
outputs['fullwarp'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_warp.nii.gz')
outputs['epi2str_inv'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_inv.mat')

outputs['epi2str_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '.mat')
outputs['wmedge'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fast_wmedge.nii.gz')
outputs['wmseg'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fast_wmseg.nii.gz')
if (not (isdefined(self.inputs.no_fmapreg) and
self.inputs.no_fmapreg) and isdefined(self.inputs.fmap)):
outputs['out_1vol'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_1vol.nii.gz')
outputs['fmap2str_mat'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fieldmap2str.mat')
outputs['fmap2epi_mat'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fieldmaprads2epi.mat')
outputs['fmap_epi'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fieldmaprads2epi.nii.gz')
outputs['fmap_str'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fieldmaprads2str.nii.gz')
outputs['fmapmag_str'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fieldmap2str.nii.gz')
outputs['shiftmap'] = os.path.join(
os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi_shift.nii.gz')
outputs['fullwarp'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_warp.nii.gz')
outputs['epi2str_inv'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_inv.mat')

outputs['epi2str_mat'] = os.path.join(
os.getcwd(), self.inputs.out_base + '.mat')
outputs['wmedge'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fast_wmedge.nii.gz')
outputs['wmseg'] = os.path.join(
os.getcwd(), self.inputs.out_base + '_fast_wmseg.nii.gz')

return outputs

Expand Down
99 changes: 66 additions & 33 deletions nipype/interfaces/fsl/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ class MathsInput(FSLCommandInputSpec):

in_file = File(position=2, argstr="%s", exists=True, mandatory=True,
desc="image to operate on")
out_file = File(genfile=True, position=-2, argstr="%s", desc="image to write", hash_files=False)
out_file = File(genfile=True, position=-2, argstr="%s",
desc="image to write", hash_files=False)
_dtypes = ["float", "char", "int", "short", "double", "input"]
internal_datatype = traits.Enum(*_dtypes, position=1, argstr="-dt %s",
desc="datatype to use for calculations (default is float)")
desc=("datatype to use for calculations "
"(default is float)"))
output_datatype = traits.Enum(*_dtypes,
position=-1, argstr="-odt %s",
desc="datatype to use for output (default uses input type)")
desc=("datatype to use for output (default "
"uses input type)"))

nan2zeros = traits.Bool(position=3, argstr='-nan',
desc='change NaNs to zeros before doing anything')
Expand All @@ -51,7 +54,8 @@ def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_file"] = self.inputs.out_file
if not isdefined(self.inputs.out_file):
outputs["out_file"] = self._gen_fname(self.inputs.in_file, suffix=self._suffix)
outputs["out_file"] = self._gen_fname(self.inputs.in_file,
suffix=self._suffix)
outputs["out_file"] = os.path.abspath(outputs["out_file"])
return outputs

Expand All @@ -65,7 +69,8 @@ class ChangeDataTypeInput(MathsInput):

_dtypes = ["float", "char", "int", "short", "double", "input"]
output_datatype = traits.Enum(*_dtypes,
position=-1, argstr="-odt %s", mandatory=True,
position=-1, argstr="-odt %s",
mandatory=True,
desc="output data type")


Expand All @@ -83,9 +88,11 @@ class ThresholdInputSpec(MathsInput):
desc="threshold value")
direction = traits.Enum("below", "above", usedefault=True,
desc="zero-out either below or above thresh value")
use_robust_range = traits.Bool(desc="interpret thresh as percentage (0-100) of robust range")
use_nonzero_voxels = traits.Bool(desc="use nonzero voxels to calculate robust range",
requires=["use_robust_range"])
use_robust_range = traits.Bool(
desc="interpret thresh as percentage (0-100) of robust range")
use_nonzero_voxels = traits.Bool(
desc="use nonzero voxels to calculate robust range",
requires=["use_robust_range"])


class Threshold(MathsCommand):
Expand All @@ -103,29 +110,35 @@ def _format_arg(self, name, spec, value):
arg += "u"
arg += "thr"
if isdefined(_si.use_robust_range) and _si.use_robust_range:
if isdefined(_si.use_nonzero_voxels) and _si.use_nonzero_voxels:
if (isdefined(_si.use_nonzero_voxels) and
_si.use_nonzero_voxels):
arg += "P"
else:
arg += "p"
arg += " %.10f" % value
return arg
return super(Threshold, self)._format_arg(name, spec, value)


class StdImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True, argstr="-%sstd", position=4,
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%sstd", position=4,
desc="dimension to standard deviate across")


class StdImage(MathsCommand):
"""Use fslmaths to generate a standard deviation in an image across a given dimension.
"""Use fslmaths to generate a standard deviation in an image across a given
dimension.
"""
input_spec = StdImageInput
_suffix = "_std"


class MeanImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True, argstr="-%smean", position=4,
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%smean", position=4,
desc="dimension to mean across")


Expand All @@ -139,7 +152,8 @@ class MeanImage(MathsCommand):

class MaxImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True, argstr="-%smax", position=4,
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%smax", position=4,
desc="dimension to max across")


Expand All @@ -162,9 +176,11 @@ class MaxImage(MathsCommand):

class IsotropicSmoothInput(MathsInput):

fwhm = traits.Float(mandatory=True, xor=["sigma"], position=4, argstr="-s %.5f",
fwhm = traits.Float(mandatory=True, xor=["sigma"],
position=4, argstr="-s %.5f",
desc="fwhm of smoothing kernel [mm]")
sigma = traits.Float(mandatory=True, xor=["fwhm"], position=4, argstr="-s %.5f",
sigma = traits.Float(mandatory=True, xor=["fwhm"],
position=4, argstr="-s %.5f",
desc="sigma of smoothing kernel [mm]")


Expand Down Expand Up @@ -198,17 +214,22 @@ class ApplyMask(MathsCommand):

class KernelInput(MathsInput):

kernel_shape = traits.Enum("3D", "2D", "box", "boxv", "gauss", "sphere", "file",
argstr="-kernel %s", position=4, desc="kernel shape to use")
kernel_shape = traits.Enum("3D", "2D", "box", "boxv", "gauss", "sphere",
"file",
argstr="-kernel %s", position=4,
desc="kernel shape to use")
kernel_size = traits.Float(argstr="%.4f", position=5, xor=["kernel_file"],
desc="kernel size - voxels for box/boxv, mm for sphere, mm sigma for gauss")
kernel_file = File(exists=True, argstr="%s", position=5, xor=["kernel_size"],
desc=("kernel size - voxels for box/boxv, mm "
"for sphere, mm sigma for gauss"))
kernel_file = File(exists=True, argstr="%s", position=5,
xor=["kernel_size"],
desc="use external file for kernel")


class DilateInput(KernelInput):

operation = traits.Enum("mean", "modal", "max", argstr="-dil%s", position=6, mandatory=True,
operation = traits.Enum("mean", "modal", "max", argstr="-dil%s",
position=6, mandatory=True,
desc="filtering operation to perfoem in dilation")


Expand All @@ -227,8 +248,10 @@ def _format_arg(self, name, spec, value):

class ErodeInput(KernelInput):

minimum_filter = traits.Bool(argstr="%s", position=6, usedefault=True, default_value=False,
desc="if true, minimum filter rather than erosion by zeroing-out")
minimum_filter = traits.Bool(argstr="%s", position=6, usedefault=True,
default_value=False,
desc=("if true, minimum filter rather than "
"erosion by zeroing-out"))


class ErodeImage(MathsCommand):
Expand All @@ -248,7 +271,8 @@ def _format_arg(self, name, spec, value):

class SpatialFilterInput(KernelInput):

operation = traits.Enum("mean", "median", "meanu", argstr="-f%s", position=6, mandatory=True,
operation = traits.Enum("mean", "median", "meanu", argstr="-f%s",
position=6, mandatory=True,
desc="operation to filter with")


Expand All @@ -262,8 +286,9 @@ class SpatialFilter(MathsCommand):

class UnaryMathsInput(MathsInput):

operation = traits.Enum("exp", "log", "sin", "cos", "tan", "asin", "acos", "atan", "sqr", "sqrt",
"recip", "abs", "bin", "binv", "fillh", "fillh26", "index", "edge", "nan",
operation = traits.Enum("exp", "log", "sin", "cos", "tan", "asin", "acos",
"atan", "sqr", "sqrt", "recip", "abs", "bin",
"binv", "fillh", "fillh26", "index", "edge", "nan",
"nanm", "rand", "randn", "range",
argstr="-%s", position=4, mandatory=True,
desc="operation to perform")
Expand All @@ -285,14 +310,17 @@ class BinaryMathsInput(MathsInput):
operation = traits.Enum("add", "sub", "mul", "div", "rem", "max", "min",
mandatory=True, argstr="-%s", position=4,
desc="operation to perform")
operand_file = File(exists=True, argstr="%s", mandatory=True, position=5, xor=["operand_value"],
operand_file = File(exists=True, argstr="%s", mandatory=True,
position=5, xor=["operand_value"],
desc="second image to perform operation with")
operand_value = traits.Float(argstr="%.8f", mandatory=True, position=5, xor=["operand_file"],
operand_value = traits.Float(argstr="%.8f", mandatory=True,
position=5, xor=["operand_file"],
desc="value to perform operation with")


class BinaryMaths(MathsCommand):
"""Use fslmaths to perform mathematical operations using a second image or a numeric value.
"""Use fslmaths to perform mathematical operations using a second image or
a numeric value.

"""
input_spec = BinaryMathsInput
Expand All @@ -301,9 +329,11 @@ class BinaryMaths(MathsCommand):
class MultiImageMathsInput(MathsInput):

op_string = traits.String(position=4, argstr="%s", mandatory=True,
desc="python formatted string of operations to perform")
desc=("python formatted string of operations "
"to perform"))
operand_files = InputMultiPath(File(exists=True), mandatory=True,
desc="list of file names to plug into op string")
desc=("list of file names to plug into op "
"string"))


class MultiImageMaths(MathsCommand):
Expand Down Expand Up @@ -331,14 +361,17 @@ def _format_arg(self, name, spec, value):

class TemporalFilterInput(MathsInput):

lowpass_sigma = traits.Float(-1, argstr="%.6f", position=5, usedefault=True,
lowpass_sigma = traits.Float(-1, argstr="%.6f", position=5,
usedefault=True,
desc="lowpass filter sigma (in volumes)")
highpass_sigma = traits.Float(-1, argstr="-bptf %.6f", position=4, usedefault=True,
highpass_sigma = traits.Float(-1, argstr="-bptf %.6f", position=4,
usedefault=True,
desc="highpass filter sigma (in volumes)")


class TemporalFilter(MathsCommand):
"""Use fslmaths to apply a low, high, or bandpass temporal filter to a timeseries.
"""Use fslmaths to apply a low, high, or bandpass temporal filter to a
timeseries.

"""
input_spec = TemporalFilterInput
Expand Down
Loading