Skip to content

Enh/spmnormalize #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 4, 2014
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ApplyTransformsInputSpec(ANTSCommandInputSpec):
File(exists=True), argstr='%s', mandatory=True, desc=(''))
invert_transform_flags = InputMultiPath(traits.Bool())
default_value = traits.Float(
0.0, argstr='--default-value %d', usedefault=True)
0.0, argstr='--default-value %g', usedefault=True)
print_out_composite_warp_file = traits.Enum(
0, 1, requires=["output_image"], desc=('')) # TODO: Change to boolean

Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _format_arg(self, opt, spec, val):
if priors_directory is not '':
retval = "-p %s/BrainSegmentationPrior%%02d" %(priors_directory)
else:
retval = "-p BrainSegmentationPrior%02d"
retval = "-p BrainSegmentationPrior%02d"
retval += ext
return retval
return super(ANTSCommand, self)._format_arg(opt, spec, val)
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/tests/test_auto_ApplyTransforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def test_ApplyTransforms_inputs():
input_map = dict(args=dict(argstr='%s',
),
default_value=dict(argstr='--default-value %d',
default_value=dict(argstr='--default-value %g',
usedefault=True,
),
dimension=dict(argstr='--dimensionality %d',
Expand Down
32 changes: 16 additions & 16 deletions nipype/interfaces/spm/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ class NormalizeInputSpec(SPMCommandInputSpec):
desc='file to normalize to template',
xor=['parameter_file'],
mandatory=True, copyfile=True)
jobtype = traits.Enum('estwrite', 'est', 'write',
desc='one of: est, write, estwrite estwrite')
jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True,
desc='Estimate, Write or do both')
apply_to_files = InputMultiPath(traits.Either(File(exists=True),
traits.List(File(exists=True))),
field='subj.resample',
Expand Down Expand Up @@ -527,11 +527,11 @@ class Normalize12InputSpec(SPMCommandInputSpec):
copyfile=True)
deformation_file = File(field='subj.def', mandatory=True,
xor=['image_to_align', 'tpm'],
desc=('file y_*.nii containing 3 deformation fields',
desc=('file y_*.nii containing 3 deformation fields '
'for the deformation in x, y and z dimension'),
copyfile=False)
jobtype = traits.Enum('estwrite', 'est', 'write',
desc='one of: est, write, estwrite estwrite')
jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True,
desc='Estimate, Write or do Both')
bias_regularization = traits.Enum(0, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1,
10, field='eoptions.biasreg',
desc='no(0) - extremely heavy (10)')
Expand All @@ -547,37 +547,37 @@ class Normalize12InputSpec(SPMCommandInputSpec):
desc='mni, size, none')
warping_regularization = traits.List(traits.Float(), field='eoptions.reg',
minlen=5, maxlen=5,
desc=('controls balance between',
desc=('controls balance between '
'parameters and data'))
smoothness = traits.Float(field='eoptions.fwhm',
desc=('value (in mm) to smooth the data before',
desc=('value (in mm) to smooth the data before '
'normalization'))
sampling_distance = traits.Float(field='eoptions.samp',
desc=('Sampling distance on data for',
desc=('Sampling distance on data for '
'parameter estimation'))
write_bounding_box = traits.List(traits.List(traits.Float(),
minlen=3, maxlen=3),
field='woptions.bb', minlen=2, maxlen=2,
desc=('3x2-element list of lists representing',
desc=('3x2-element list of lists representing '
'the bounding box (in mm) to be written'))
write_voxel_sizes = traits.List(traits.Float(), field='woptions.vox',
minlen=3, maxlen=3,
desc=('3-element list representing the',
'voxel sizes (in mm) of the written',
desc=('3-element list representing the '
'voxel sizes (in mm) of the written '
'normalised images'))
write_interp = traits.Range(low=0, high=7, field='woptions.interp',
desc='degree of b-spline used for interpolation')


class Normalize12OutputSpec(TraitedSpec):
deformation_field = OutputMultiPath(File(exists=True),
desc=('NIfTI file containing 3 deformation',
'fields for the deformation in',
desc=('NIfTI file containing 3 deformation '
'fields for the deformation in '
'x, y and z dimension'))
normalized_image = OutputMultiPath(File(exists=True),
desc=('Normalized file that needed to',
desc=('Normalized file that needed to '
'be aligned'))
normalized_files = OutputMultiPath(File(exists=True),
normalized_files = OutputMultiPath(File(exists=True),
desc='Normalized other files')


Expand Down Expand Up @@ -621,7 +621,7 @@ def _format_arg(self, opt, spec, val):
raise ValueError('%s must have 5 elements' % opt)
return super(Normalize12, self)._format_arg(opt, spec, val)

def _parse_inputs(self):
def _parse_inputs(self, skip=()):
"""validate spm normalize options if set to None ignore
"""
einputs = super(Normalize12, self)._parse_inputs(skip=('jobtype',
Expand Down
5 changes: 3 additions & 2 deletions nipype/interfaces/spm/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_normalize_list_outputs():
filelist, outdir, cwd = create_files_in_directory()
norm = spm.Normalize(source=filelist[0])
yield assert_true, norm._list_outputs()['normalized_source'][0].startswith('w')
norm = spm.Normalize(source=filelist[0],apply_to_files=filelist[1])
norm = spm.Normalize(source=filelist[0], apply_to_files=filelist[1])
yield assert_true, norm._list_outputs()['normalized_files'][0].startswith('w')
clean_directory(outdir, cwd)

Expand All @@ -98,7 +98,8 @@ def test_normalize12_list_outputs():
filelist, outdir, cwd = create_files_in_directory()
norm12 = spm.Normalize12(image_to_align=filelist[0])
yield assert_true, norm12._list_outputs()['normalized_image'][0].startswith('w')
norm12 = spm.Normalize12(image_to_align=filelist[0],apply_to_files=filelist[1])
norm12 = spm.Normalize12(image_to_align=filelist[0],
apply_to_files=filelist[1])
yield assert_true, norm12._list_outputs()['normalized_files'][0].startswith('w')
clean_directory(outdir, cwd)

Expand Down
9 changes: 9 additions & 0 deletions nipype/interfaces/utility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Various utilities

Change directory to provide relative paths for doctests
>>> import os
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
>>> os.chdir(datadir)
"""

import os
import re
from cPickle import dumps, loads
Expand Down
5 changes: 4 additions & 1 deletion nipype/pipeline/plugins/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def execute_task(pckld_task, node_config, updatehash):
from nipype import config, logging
traceback=None
result=None
import os
cwd = os.getcwd()
try:
config.update_config(node_config)
logging.update_logging(config)
Expand All @@ -31,6 +33,7 @@ def execute_task(pckld_task, node_config, updatehash):
except:
traceback = format_exc()
result = task.result
os.chdir(cwd)
return result, traceback, gethostname()

class IPythonPlugin(DistributedPluginBase):
Expand Down Expand Up @@ -72,7 +75,7 @@ def run(self, graph, config, updatehash=False):

def _get_result(self, taskid):
if taskid not in self.taskmap:
raise ValueError('Task %d not in pending list'%taskid)
raise ValueError('Task %d not in pending list' % taskid)
if self.taskmap[taskid].ready():
result, traceback, hostname = self.taskmap[taskid].get()
result_out = dict(result=None, traceback=None)
Expand Down
6 changes: 4 additions & 2 deletions nipype/workflows/dmri/fsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ def recompose_xfm(in_bval, in_xfms):
return out_files


def b0_average(in_dwi, in_bval, out_file=None):
def b0_average(in_dwi, in_bval, max_b=10.0, out_file=None):
"""
A function that averages the *b0* volumes from a DWI dataset.
As current dMRI data are being acquired with all b-values > 0.0,
the *lowb* volumes are selected by specifying the parameter max_b.

.. warning:: *b0* should be already registered (head motion artifact should
be corrected).
Expand All @@ -403,7 +405,7 @@ def b0_average(in_dwi, in_bval, out_file=None):
imgs = np.array(nb.four_to_three(nb.load(in_dwi)))
bval = np.loadtxt(in_bval)
b0s = [im.get_data().astype(np.float32)
for im in imgs[np.where(bval == 0)]]
for im in imgs[np.where(bval <= max_b)]]
b0 = np.average(np.array(b0s), axis=0)

hdr = imgs[0].get_header().copy()
Expand Down