Skip to content

Commit b87be8b

Browse files
committed
Merge pull request #1 from satra/fix/ants
Fix/ants
2 parents 8fc7d32 + b2a1e3d commit b87be8b

File tree

11 files changed

+333
-74
lines changed

11 files changed

+333
-74
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def _format_arg(self, opt, spec, val):
500500
if priors_directory is not '':
501501
retval = "-p %s/BrainSegmentationPrior%%02d" % priors_directory
502502
else:
503-
retval = "-p BrainSegmentationPrior%02d"
503+
retval = "-p BrainSegmentationPrior%02d"
504504
retval += ext
505505
return retval
506506
return super(ANTSCommand, self)._format_arg(opt, spec, val)

nipype/interfaces/spm/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
from .base import (Info, SPMCommand, logger, no_spm, scans_for_fname,
66
scans_for_fnames)
7-
from .preprocess import (SliceTiming, Realign, Coregister, Normalize, Segment,
8-
Smooth, NewSegment, DARTEL, DARTELNorm2MNI,
9-
CreateWarped, VBMSegment)
7+
from .preprocess import (SliceTiming, Realign, Coregister, Normalize,
8+
Normalize12, Segment, Smooth, NewSegment, DARTEL,
9+
DARTELNorm2MNI, CreateWarped, VBMSegment)
1010
from .model import (Level1Design, EstimateModel, EstimateContrast, Threshold,
1111
OneSampleTTestDesign, TwoSampleTTestDesign,
1212
PairedTTestDesign, MultipleRegressionDesign)
1313
from .utils import (Analyze2nii, CalcCoregAffine, ApplyTransform, Reslice,
14-
ApplyInverseDeformation,ResliceToReference,DicomImport)
15-
14+
ApplyInverseDeformation, ResliceToReference, DicomImport)

nipype/interfaces/spm/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def _make_matlab_command(self, contents, postscript=None):
467467
fprintf('SPM path: %s\\n', which('spm'));
468468
spm('Defaults','fMRI');
469469
470-
if strcmp(name, 'SPM8') || strcmp(name, 'SPM12b'),
470+
if strcmp(name, 'SPM8') || strcmp(name(1:5), 'SPM12'),
471471
spm_jobman('initcfg');
472472
spm_get_defaults('cmdline', 1);
473473
end\n
@@ -502,7 +502,7 @@ def _make_matlab_command(self, contents, postscript=None):
502502
"""
503503
if self.inputs.use_mcr:
504504
mscript += """
505-
if strcmp(name, 'SPM8') || strcmp(name, 'SPM12b'),
505+
if strcmp(name, 'SPM8') || strcmp(name(1:5), 'SPM12'),
506506
close(\'all\', \'force\');
507507
end;
508508
"""

nipype/interfaces/spm/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Level1DesignOutputSpec(TraitedSpec):
9292
class Level1Design(SPMCommand):
9393
"""Generate an SPM design matrix
9494
95-
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=61
95+
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=59
9696
9797
Examples
9898
--------
@@ -182,7 +182,7 @@ class EstimateModelOutputSpec(TraitedSpec):
182182
class EstimateModel(SPMCommand):
183183
"""Use spm_spm to estimate the parameters of a model
184184
185-
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=71
185+
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=69
186186
187187
Examples
188188
--------
@@ -744,7 +744,7 @@ class FactorialDesignOutputSpec(TraitedSpec):
744744
class FactorialDesign(SPMCommand):
745745
"""Base class for factorial designs
746746
747-
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=79
747+
http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=77
748748
749749
"""
750750

nipype/interfaces/spm/preprocess.py

Lines changed: 218 additions & 56 deletions
Large diffs are not rendered by default.

nipype/interfaces/spm/tests/test_auto_Normalize.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
def test_Normalize_inputs():
66
input_map = dict(DCT_period_cutoff=dict(field='eoptions.cutoff',
77
),
8-
affine_regularization_type=dict(field='eoptions.regype',
8+
affine_regularization_type=dict(field='eoptions.regtype',
99
),
1010
apply_to_files=dict(copyfile=True,
1111
field='subj.resample',
1212
),
1313
ignore_exception=dict(nohash=True,
1414
usedefault=True,
1515
),
16-
jobtype=dict(usedefault=True,
17-
),
16+
jobtype=dict(),
1817
matlab_cmd=dict(),
1918
mfile=dict(usedefault=True,
2019
),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.spm.preprocess import Normalize12
4+
5+
def test_Normalize12_inputs():
6+
input_map = dict(affine_regularization_type=dict(field='eoptions.affreg',
7+
),
8+
apply_to_files=dict(copyfile=True,
9+
field='subj.resample',
10+
),
11+
bias_fwhm=dict(field='eoptions.biasfwhm',
12+
),
13+
bias_regularization=dict(field='eoptions.biasreg',
14+
),
15+
deformation_file=dict(copyfile=False,
16+
field='subj.def',
17+
mandatory=True,
18+
xor=['image_to_align', 'tpm'],
19+
),
20+
ignore_exception=dict(nohash=True,
21+
usedefault=True,
22+
),
23+
image_to_align=dict(copyfile=True,
24+
field='subj.vol',
25+
mandatory=True,
26+
xor=['deformation_file'],
27+
),
28+
jobtype=dict(),
29+
matlab_cmd=dict(),
30+
mfile=dict(usedefault=True,
31+
),
32+
paths=dict(),
33+
sampling_distance=dict(field='eoptions.samp',
34+
),
35+
smoothness=dict(field='eoptions.fwhm',
36+
),
37+
tpm=dict(copyfile=False,
38+
field='eoptions.tpm',
39+
mandatory=False,
40+
xor=['deformation_file'],
41+
),
42+
use_mcr=dict(),
43+
use_v8struct=dict(min_ver='8',
44+
usedefault=True,
45+
),
46+
warping_regularization=dict(field='eoptions.reg',
47+
),
48+
write_bounding_box=dict(field='woptions.bb',
49+
),
50+
write_interp=dict(field='woptions.interp',
51+
),
52+
write_voxel_sizes=dict(field='woptions.vox',
53+
),
54+
)
55+
inputs = Normalize12.input_spec()
56+
57+
for key, metadata in input_map.items():
58+
for metakey, value in metadata.items():
59+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
60+
61+
def test_Normalize12_outputs():
62+
output_map = dict(deformation_field=dict(),
63+
normalized_files=dict(),
64+
normalized_image=dict(),
65+
)
66+
outputs = Normalize12.output_spec()
67+
68+
for key, metadata in output_map.items():
69+
for metakey, value in metadata.items():
70+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
71+

nipype/interfaces/spm/tests/test_preprocess.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,24 @@ 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

92+
def test_normalize12():
93+
yield assert_equal, spm.Normalize12._jobtype, 'spatial'
94+
yield assert_equal, spm.Normalize12._jobname, 'normalise'
95+
yield assert_equal, spm.Normalize12().inputs.jobtype, 'estwrite'
96+
97+
def test_normalize12_list_outputs():
98+
filelist, outdir, cwd = create_files_in_directory()
99+
norm12 = spm.Normalize12(image_to_align=filelist[0])
100+
yield assert_true, norm12._list_outputs()['normalized_image'][0].startswith('w')
101+
norm12 = spm.Normalize12(image_to_align=filelist[0],
102+
apply_to_files=filelist[1])
103+
yield assert_true, norm12._list_outputs()['normalized_files'][0].startswith('w')
104+
clean_directory(outdir, cwd)
105+
92106
@skipif(no_spm)
93107
def test_segment():
94108
if spm.Info.version()['name'] == "SPM12":

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)