Skip to content

Commit 25c8064

Browse files
committed
Merge pull request #957 from satra/enh/misc
Enh/misc - a few cleanup and enhancement changes
2 parents d38e7f0 + aa1d1f9 commit 25c8064

File tree

13 files changed

+80
-107
lines changed

13 files changed

+80
-107
lines changed

nipype/interfaces/ants/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# the computer (when running MultiProc) by forcing everything to
1616
# single threaded. This can be a severe penalty for registration
1717
# performance.
18-
LOCAL_DEFAULT_NUMBER_OF_THREADS=-1
18+
LOCAL_DEFAULT_NUMBER_OF_THREADS=1
1919
# -Using NSLOTS has the same behavior as ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS
2020
# as long as ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS is not set. Otherwise
2121
# ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS takes precidence.
@@ -28,8 +28,8 @@ class ANTSCommandInputSpec(CommandLineInputSpec):
2828
"""Base Input Specification for all ANTS Commands
2929
"""
3030

31-
num_threads = traits.Int(LOCAL_DEFAULT_NUMBER_OF_THREADS, usedefault=True, nohash=True,
32-
desc="Number of ITK threads to use")
31+
num_threads = traits.Int(LOCAL_DEFAULT_NUMBER_OF_THREADS, usedefault=True,
32+
nohash=True, desc="Number of ITK threads to use")
3333

3434

3535
class ANTSCommand(CommandLine):

nipype/interfaces/fsl/epi.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ class EddyInputSpec(FSLCommandInputSpec):
398398
in_bval = File(exists=True, mandatory=True, argstr='--bvals=%s',
399399
desc=('File containing the b-values for all volumes in '
400400
'--imain'))
401-
out_base = File(argstr='--out=%s',
402-
desc=('basename for output (warped) image'))
403-
401+
out_base = traits.Unicode('eddy_corrected', argstr='--out=%s',
402+
usedefault=True,
403+
desc=('basename for output (warped) image'))
404404
session = File(exists=True, argstr='--session=%s',
405405
desc=('File containing session indices for all volumes in '
406406
'--imain'))
@@ -424,6 +424,8 @@ class EddyInputSpec(FSLCommandInputSpec):
424424
'squares)'))
425425
repol = traits.Bool(False, argstr='--repol',
426426
desc='Detect and replace outlier slices')
427+
num_threads = traits.Int(1, usedefault=True, nohash=True,
428+
desc="Number of openmp threads to use")
427429

428430

429431
class EddyOutputSpec(TraitedSpec):
@@ -457,27 +459,38 @@ class Eddy(FSLCommand):
457459
>>> eddy.cmdline #doctest: +ELLIPSIS
458460
'eddy --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme \
459461
--imain=epi.nii --index=epi_index.txt --mask=epi_mask.nii \
460-
--out=.../eddy_corrected'
462+
--out=eddy_corrected'
461463
>>> res = eddy.run() # doctest: +SKIP
462464
463465
"""
464466
_cmd = 'eddy'
465467
input_spec = EddyInputSpec
466468
output_spec = EddyOutputSpec
467469

470+
_num_threads = 1
471+
472+
def __init__(self, **inputs):
473+
super(Eddy, self).__init__(**inputs)
474+
self.inputs.on_trait_change(self._num_threads_update, 'num_threads')
475+
476+
if not isdefined(self.inputs.num_threads):
477+
self.inputs.num_threads = self._num_threads
478+
else:
479+
self._num_threads_update()
480+
481+
def _num_threads_update(self):
482+
self._num_threads = self.inputs.num_threads
483+
if not isdefined(self.inputs.num_threads):
484+
if 'OMP_NUM_THREADS' in self.inputs.environ:
485+
del self.inputs.environ['OMP_NUM_THREADS']
486+
else:
487+
self.inputs.environ['OMP_NUM_THREADS'] = str(self.inputs.num_threads)
488+
468489
def _format_arg(self, name, spec, value):
469490
if name == 'in_topup_fieldcoef':
470491
return spec.argstr % value.split('_fieldcoef')[0]
471492
return super(Eddy, self)._format_arg(name, spec, value)
472493

473-
def _parse_inputs(self, skip=None):
474-
if skip is None:
475-
skip = []
476-
477-
if not isdefined(self.inputs.out_base):
478-
self.inputs.out_base = os.path.abspath('eddy_corrected')
479-
return super(Eddy, self)._parse_inputs(skip=skip)
480-
481494
def _list_outputs(self):
482495
outputs = self.output_spec().get()
483496
outputs['out_corrected'] = '%s.nii.gz' % self.inputs.out_base

nipype/interfaces/fsl/tests/test_auto_Eddy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def test_Eddy_inputs():
4242
),
4343
niter=dict(argstr='--niter=%s',
4444
),
45+
num_threads=dict(nohash=True,
46+
usedefault=True,
47+
),
4548
out_base=dict(argstr='--out=%s',
49+
usedefault=True,
4650
),
4751
output_type=dict(),
4852
repol=dict(argstr='--repol',

nipype/interfaces/spm/model.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ class Level1DesignInputSpec(SPMCommandInputSpec):
7070
Number of basis functions
7171
""", mandatory=True)
7272
volterra_expansion_order = traits.Enum(1, 2, field='volt',
73-
desc='Model interactions - yes:1, no:2 (opt)')
73+
desc='Model interactions - yes:1, no:2')
7474
global_intensity_normalization = traits.Enum('none', 'scaling', field='global',
75-
desc='Global intensity normalization - scaling or none (opt)')
75+
desc='Global intensity normalization - scaling or none')
7676
mask_image = File(exists=True, field='mask',
77-
desc='Image for explicitly masking the analysis (opt)')
77+
desc='Image for explicitly masking the analysis')
7878
mask_threshold = traits.Either(traits.Enum('-Inf'), traits.Float(),
79-
desc="Thresholding for the mask (opt, '-Inf')", default='-Inf', usedefault=True)
80-
model_serial_correlations = traits.Enum('AR(1)', 'none', field='cvi',
81-
desc='Model serial correlations AR(1) or none (opt)')
79+
desc="Thresholding for the mask",
80+
default='-Inf', usedefault=True)
81+
model_serial_correlations = traits.Enum('AR(1)', 'FAST', 'none',
82+
field='cvi',
83+
desc=('Model serial correlations '
84+
'AR(1), FAST or none. FAST '
85+
'is available in SPM12'))
8286

8387

8488
class Level1DesignOutputSpec(TraitedSpec):

nipype/interfaces/spm/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ class Segment(SPMCommand):
599599
>>> seg.run() # doctest: +SKIP
600600
601601
"""
602-
602+
603603
if Info.version() and Info.version()['name'] == "SPM12":
604604
_jobtype = 'tools'
605605
_jobname = 'oldseg'

nipype/interfaces/spm/tests/test_preprocess.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,24 @@ def test_normalize_list_outputs():
8989
yield assert_true, norm._list_outputs()['normalized_files'][0].startswith('w')
9090
clean_directory(outdir, cwd)
9191

92+
@skipif(no_spm)
9293
def test_segment():
93-
yield assert_equal, spm.Segment._jobtype, 'spatial'
94-
yield assert_equal, spm.Segment._jobname, 'preproc'
95-
94+
if spm.Info.version()['name'] == "SPM12":
95+
yield assert_equal, spm.Segment._jobtype, 'tools'
96+
yield assert_equal, spm.Segment._jobname, 'oldseg'
97+
else:
98+
yield assert_equal, spm.Segment._jobtype, 'spatial'
99+
yield assert_equal, spm.Segment._jobname, 'preproc'
100+
101+
@skipif(no_spm)
96102
def test_newsegment():
97-
yield assert_equal, spm.NewSegment._jobtype, 'tools'
98-
yield assert_equal, spm.NewSegment._jobname, 'preproc8'
103+
if spm.Info.version()['name'] == "SPM12":
104+
yield assert_equal, spm.NewSegment._jobtype, 'spatial'
105+
yield assert_equal, spm.NewSegment._jobname, 'preproc'
106+
else:
107+
yield assert_equal, spm.NewSegment._jobtype, 'tools'
108+
yield assert_equal, spm.NewSegment._jobname, 'preproc8'
109+
99110

100111
def test_smooth():
101112
yield assert_equal, spm.Smooth._jobtype, 'spatial'

nipype/pipeline/engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,8 @@ def __init__(self, interface, iterfield, name, serial=False, nested=False, **kwa
20452045
serial : boolean
20462046
flag to enforce executing the jobs of the mapnode in a serial manner rather than parallel
20472047
nested : boolea
2048-
support for nested lists, if set the input list will be flattened before running, and the
2049-
nested list structure of the outputs will be resored
2048+
support for nested lists, if set the input list will be flattened before running, and the
2049+
nested list structure of the outputs will be resored
20502050
See Node docstring for additional keyword arguments.
20512051
"""
20522052

@@ -2150,7 +2150,7 @@ def _make_nodes(self, cwd=None):
21502150
cwd = self.output_dir()
21512151
if self.nested:
21522152
nitems = len(flatten(filename_to_list(getattr(self.inputs, self.iterfield[0]))))
2153-
else:
2153+
else:
21542154
nitems = len(filename_to_list(getattr(self.inputs, self.iterfield[0])))
21552155
for i in range(nitems):
21562156
nodename = '_' + self.name + str(i)
@@ -2216,14 +2216,14 @@ def _collate_results(self, nodes):
22162216
defined_vals = [isdefined(val) for val in values]
22172217
if any(defined_vals) and self._result.outputs:
22182218
setattr(self._result.outputs, key, values)
2219-
2219+
22202220
if self.nested:
22212221
for key, _ in self.outputs.items():
22222222
values = getattr(self._result.outputs, key)
22232223
if isdefined(values):
22242224
values = unflatten(values, filename_to_list(getattr(self.inputs, self.iterfield[0])))
22252225
setattr(self._result.outputs, key, values)
2226-
2226+
22272227
if returncode and any([code is not None for code in returncode]):
22282228
msg = []
22292229
for i, code in enumerate(returncode):

nipype/pipeline/tests/test_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def func1(in1):
487487
n1.run()
488488
print n1.get_output('out')
489489
yield assert_equal, n1.get_output('out'), [[2,[3]],4,[5,6]]
490-
490+
491491
n2 = MapNode(Function(input_names=['in1'],
492492
output_names=['out'],
493493
function=func1),

nipype/utils/misc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def str2bool(v):
206206
return False
207207
else:
208208
raise ValueError("%s cannot be converted to bool"%v)
209-
209+
210210
def flatten(S):
211211
if S == []:
212212
return S
@@ -217,14 +217,14 @@ def flatten(S):
217217
def unflatten(in_list, prev_structure):
218218
if not isinstance(in_list, Iterator):
219219
in_list = iter(in_list)
220-
220+
221221
if not isinstance(prev_structure, list):
222222
return in_list.next()
223223
else:
224224
out = []
225225
for item in prev_structure:
226226
out.append(unflatten(in_list, item))
227227
return out
228-
229-
228+
229+
230230

nipype/utils/tests/test_misc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ def test_str2bool():
5454

5555
def test_flatten():
5656
in_list = [[1,2,3],[4],[[5,6],7],8]
57-
57+
5858
flat = flatten(in_list)
5959
yield assert_equal, flat, [1,2,3,4,5,6,7,8]
60-
60+
6161
back = unflatten(flat, in_list)
6262
yield assert_equal, in_list, back
63-
63+
6464
new_list = [2,3,4,5,6,7,8,9]
6565
back = unflatten(new_list, in_list)
6666
yield assert_equal, back, [[2,3,4],[5],[[6,7],8],9]
67-
67+
6868
flat = flatten([])
6969
yield assert_equal, flat, []
70-
70+
7171
back = unflatten([], [])
7272
yield assert_equal, back, []

0 commit comments

Comments
 (0)