Skip to content

Commit 80034ac

Browse files
committed
Merge pull request #1 from satra/enh/spmnormalize
Enh/spmnormalize
2 parents 356696a + d3aed2b commit 80034ac

File tree

8 files changed

+39
-24
lines changed

8 files changed

+39
-24
lines changed

nipype/interfaces/ants/resampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class ApplyTransformsInputSpec(ANTSCommandInputSpec):
249249
File(exists=True), argstr='%s', mandatory=True, desc=(''))
250250
invert_transform_flags = InputMultiPath(traits.Bool())
251251
default_value = traits.Float(
252-
0.0, argstr='--default-value %d', usedefault=True)
252+
0.0, argstr='--default-value %g', usedefault=True)
253253
print_out_composite_warp_file = traits.Enum(
254254
0, 1, requires=["output_image"], desc=('')) # TODO: Change to boolean
255255

nipype/interfaces/ants/segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def _format_arg(self, opt, spec, val):
490490
if priors_directory is not '':
491491
retval = "-p %s/BrainSegmentationPrior%%02d" %(priors_directory)
492492
else:
493-
retval = "-p BrainSegmentationPrior%02d"
493+
retval = "-p BrainSegmentationPrior%02d"
494494
retval += ext
495495
return retval
496496
return super(ANTSCommand, self)._format_arg(opt, spec, val)

nipype/interfaces/ants/tests/test_auto_ApplyTransforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def test_ApplyTransforms_inputs():
66
input_map = dict(args=dict(argstr='%s',
77
),
8-
default_value=dict(argstr='--default-value %d',
8+
default_value=dict(argstr='--default-value %g',
99
usedefault=True,
1010
),
1111
dimension=dict(argstr='--dimensionality %d',

nipype/interfaces/spm/preprocess.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ class NormalizeInputSpec(SPMCommandInputSpec):
374374
desc='file to normalize to template',
375375
xor=['parameter_file'],
376376
mandatory=True, copyfile=True)
377-
jobtype = traits.Enum('estwrite', 'est', 'write',
378-
desc='one of: est, write, estwrite estwrite')
377+
jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True,
378+
desc='Estimate, Write or do both')
379379
apply_to_files = InputMultiPath(traits.Either(File(exists=True),
380380
traits.List(File(exists=True))),
381381
field='subj.resample',
@@ -527,11 +527,11 @@ class Normalize12InputSpec(SPMCommandInputSpec):
527527
copyfile=True)
528528
deformation_file = File(field='subj.def', mandatory=True,
529529
xor=['image_to_align', 'tpm'],
530-
desc=('file y_*.nii containing 3 deformation fields',
530+
desc=('file y_*.nii containing 3 deformation fields '
531531
'for the deformation in x, y and z dimension'),
532532
copyfile=False)
533-
jobtype = traits.Enum('estwrite', 'est', 'write',
534-
desc='one of: est, write, estwrite estwrite')
533+
jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True,
534+
desc='Estimate, Write or do Both')
535535
bias_regularization = traits.Enum(0, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1,
536536
10, field='eoptions.biasreg',
537537
desc='no(0) - extremely heavy (10)')
@@ -547,37 +547,37 @@ class Normalize12InputSpec(SPMCommandInputSpec):
547547
desc='mni, size, none')
548548
warping_regularization = traits.List(traits.Float(), field='eoptions.reg',
549549
minlen=5, maxlen=5,
550-
desc=('controls balance between',
550+
desc=('controls balance between '
551551
'parameters and data'))
552552
smoothness = traits.Float(field='eoptions.fwhm',
553-
desc=('value (in mm) to smooth the data before',
553+
desc=('value (in mm) to smooth the data before '
554554
'normalization'))
555555
sampling_distance = traits.Float(field='eoptions.samp',
556-
desc=('Sampling distance on data for',
556+
desc=('Sampling distance on data for '
557557
'parameter estimation'))
558558
write_bounding_box = traits.List(traits.List(traits.Float(),
559559
minlen=3, maxlen=3),
560560
field='woptions.bb', minlen=2, maxlen=2,
561-
desc=('3x2-element list of lists representing',
561+
desc=('3x2-element list of lists representing '
562562
'the bounding box (in mm) to be written'))
563563
write_voxel_sizes = traits.List(traits.Float(), field='woptions.vox',
564564
minlen=3, maxlen=3,
565-
desc=('3-element list representing the',
566-
'voxel sizes (in mm) of the written',
565+
desc=('3-element list representing the '
566+
'voxel sizes (in mm) of the written '
567567
'normalised images'))
568568
write_interp = traits.Range(low=0, high=7, field='woptions.interp',
569569
desc='degree of b-spline used for interpolation')
570570

571571

572572
class Normalize12OutputSpec(TraitedSpec):
573573
deformation_field = OutputMultiPath(File(exists=True),
574-
desc=('NIfTI file containing 3 deformation',
575-
'fields for the deformation in',
574+
desc=('NIfTI file containing 3 deformation '
575+
'fields for the deformation in '
576576
'x, y and z dimension'))
577577
normalized_image = OutputMultiPath(File(exists=True),
578-
desc=('Normalized file that needed to',
578+
desc=('Normalized file that needed to '
579579
'be aligned'))
580-
normalized_files = OutputMultiPath(File(exists=True),
580+
normalized_files = OutputMultiPath(File(exists=True),
581581
desc='Normalized other files')
582582

583583

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

624-
def _parse_inputs(self):
624+
def _parse_inputs(self, skip=()):
625625
"""validate spm normalize options if set to None ignore
626626
"""
627627
einputs = super(Normalize12, self)._parse_inputs(skip=('jobtype',

nipype/interfaces/spm/tests/test_preprocess.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_normalize_list_outputs():
8585
filelist, outdir, cwd = create_files_in_directory()
8686
norm = spm.Normalize(source=filelist[0])
8787
yield assert_true, norm._list_outputs()['normalized_source'][0].startswith('w')
88-
norm = spm.Normalize(source=filelist[0],apply_to_files=filelist[1])
88+
norm = spm.Normalize(source=filelist[0], apply_to_files=filelist[1])
8989
yield assert_true, norm._list_outputs()['normalized_files'][0].startswith('w')
9090
clean_directory(outdir, cwd)
9191

@@ -98,7 +98,8 @@ def test_normalize12_list_outputs():
9898
filelist, outdir, cwd = create_files_in_directory()
9999
norm12 = spm.Normalize12(image_to_align=filelist[0])
100100
yield assert_true, norm12._list_outputs()['normalized_image'][0].startswith('w')
101-
norm12 = spm.Normalize12(image_to_align=filelist[0],apply_to_files=filelist[1])
101+
norm12 = spm.Normalize12(image_to_align=filelist[0],
102+
apply_to_files=filelist[1])
102103
yield assert_true, norm12._list_outputs()['normalized_files'][0].startswith('w')
103104
clean_directory(outdir, cwd)
104105

nipype/interfaces/utility.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
"""Various utilities
4+
5+
Change directory to provide relative paths for doctests
6+
>>> import os
7+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
8+
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
9+
>>> os.chdir(datadir)
10+
"""
11+
312
import os
413
import re
514
from cPickle import dumps, loads

nipype/pipeline/plugins/ipython.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def execute_task(pckld_task, node_config, updatehash):
2222
from nipype import config, logging
2323
traceback=None
2424
result=None
25+
import os
26+
cwd = os.getcwd()
2527
try:
2628
config.update_config(node_config)
2729
logging.update_logging(config)
@@ -31,6 +33,7 @@ def execute_task(pckld_task, node_config, updatehash):
3133
except:
3234
traceback = format_exc()
3335
result = task.result
36+
os.chdir(cwd)
3437
return result, traceback, gethostname()
3538

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

7376
def _get_result(self, taskid):
7477
if taskid not in self.taskmap:
75-
raise ValueError('Task %d not in pending list'%taskid)
78+
raise ValueError('Task %d not in pending list' % taskid)
7679
if self.taskmap[taskid].ready():
7780
result, traceback, hostname = self.taskmap[taskid].get()
7881
result_out = dict(result=None, traceback=None)

nipype/workflows/dmri/fsl/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,11 @@ def recompose_xfm(in_bval, in_xfms):
381381
return out_files
382382

383383

384-
def b0_average(in_dwi, in_bval, out_file=None):
384+
def b0_average(in_dwi, in_bval, max_b=10.0, out_file=None):
385385
"""
386386
A function that averages the *b0* volumes from a DWI dataset.
387+
As current dMRI data are being acquired with all b-values > 0.0,
388+
the *lowb* volumes are selected by specifying the parameter max_b.
387389
388390
.. warning:: *b0* should be already registered (head motion artifact should
389391
be corrected).
@@ -403,7 +405,7 @@ def b0_average(in_dwi, in_bval, out_file=None):
403405
imgs = np.array(nb.four_to_three(nb.load(in_dwi)))
404406
bval = np.loadtxt(in_bval)
405407
b0s = [im.get_data().astype(np.float32)
406-
for im in imgs[np.where(bval == 0)]]
408+
for im in imgs[np.where(bval <= max_b)]]
407409
b0 = np.average(np.array(b0s), axis=0)
408410

409411
hdr = imgs[0].get_header().copy()

0 commit comments

Comments
 (0)