Skip to content

Commit d4a472d

Browse files
authored
Merge pull request #3 from nipy/master
up to date
2 parents aa6db2d + f39e222 commit d4a472d

24 files changed

+462
-321
lines changed

doc/devel/testing_nipype.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ To enable the tests depending on these data, just unpack the targz file and set
8989
variable to point to that folder.
9090

9191
Xfail tests
92-
~~~~~~~~~~
92+
~~~~~~~~~~~
9393

9494
Some tests are expect to fail until the code will be changed or for other reasons.
9595

doc/documentation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Previous versions: `0.12.0 <http://nipype.readthedocs.io/en/0.12.0/>`_ `0.11.0
2929
:maxdepth: 2
3030

3131
users/index
32-
32+
3333
.. toctree::
3434
:maxdepth: 1
3535

doc/users/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Execution
145145
crashfiles allow interactive debugging and rerunning of nodes, while text
146146
crashfiles allow portability across machines and shorter load time.
147147
(possible values: ``pklz`` and ``txt``; default value: ``pklz``)
148-
148+
149149
Example
150150
~~~~~~~
151151

nipype/algorithms/confounds.py

Lines changed: 217 additions & 200 deletions
Large diffs are not rendered by default.

nipype/algorithms/tests/test_auto_ACompCor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
def test_ACompCor_inputs():
77
input_map = dict(components_file=dict(usedefault=True,
88
),
9-
header=dict(),
9+
header_prefix=dict(),
1010
ignore_exception=dict(nohash=True,
1111
usedefault=True,
1212
),
13-
mask_file=dict(),
13+
mask_files=dict(),
14+
mask_index=dict(requires=['mask_files'],
15+
xor=['merge_method'],
16+
),
17+
merge_method=dict(requires=['mask_files'],
18+
xor=['mask_index'],
19+
),
1420
num_components=dict(usedefault=True,
1521
),
1622
realigned_file=dict(mandatory=True,

nipype/algorithms/tests/test_auto_TCompCor.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
def test_TCompCor_inputs():
77
input_map = dict(components_file=dict(usedefault=True,
88
),
9-
header=dict(),
9+
header_prefix=dict(),
1010
ignore_exception=dict(nohash=True,
1111
usedefault=True,
1212
),
13-
mask_file=dict(),
13+
mask_files=dict(),
14+
mask_index=dict(requires=['mask_files'],
15+
xor=['merge_method'],
16+
),
17+
merge_method=dict(requires=['mask_files'],
18+
xor=['mask_index'],
19+
),
1420
num_components=dict(usedefault=True,
1521
),
1622
percentile_threshold=dict(usedefault=True,
@@ -30,22 +36,8 @@ def test_TCompCor_inputs():
3036

3137

3238
def test_TCompCor_outputs():
33-
output_map = dict(components_file=dict(usedefault=True,
34-
),
35-
header=dict(),
36-
high_variance_mask=dict(),
37-
ignore_exception=dict(nohash=True,
38-
usedefault=True,
39-
),
40-
mask_file=dict(),
41-
num_components=dict(usedefault=True,
42-
),
43-
realigned_file=dict(mandatory=True,
44-
),
45-
regress_poly_degree=dict(usedefault=True,
46-
),
47-
use_regress_poly=dict(usedefault=True,
48-
),
39+
output_map = dict(components_file=dict(),
40+
high_variance_masks=dict(),
4941
)
5042
outputs = TCompCor.output_spec()
5143

nipype/algorithms/tests/test_compcor.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99
from ...testing import utils
1010
from ..confounds import CompCor, TCompCor, ACompCor
11-
from ...interfaces.base import Undefined
1211

1312

1413
class TestCompCor():
@@ -48,11 +47,13 @@ def test_compcor(self):
4847
['-0.1246655485', '-0.1235705610']]
4948

5049
self.run_cc(CompCor(realigned_file=self.realigned_file,
51-
mask_files=self.mask_files),
50+
mask_files=self.mask_files,
51+
mask_index=0),
5252
expected_components)
5353

5454
self.run_cc(ACompCor(realigned_file=self.realigned_file,
5555
mask_files=self.mask_files,
56+
mask_index=0,
5657
components_file='acc_components_file'),
5758
expected_components, 'aCompCor')
5859

@@ -64,40 +65,44 @@ def test_tcompcor(self):
6465
['0.4566907310', '0.6983205193'],
6566
['-0.7132557407', '0.1340170559'],
6667
['0.5022537643', '-0.5098322262'],
67-
['-0.1342351356', '0.1407855119']], 'tCompCor')
68+
['-0.1342351356', '0.1407855119']],
69+
'tCompCor')
6870

6971
def test_tcompcor_no_percentile(self):
7072
ccinterface = TCompCor(realigned_file=self.realigned_file)
7173
ccinterface.run()
7274

73-
mask = nb.load('mask.nii').get_data()
75+
mask = nb.load('mask_000.nii.gz').get_data()
7476
num_nonmasked_voxels = np.count_nonzero(mask)
7577
assert num_nonmasked_voxels == 1
7678

7779
def test_compcor_no_regress_poly(self):
7880
self.run_cc(CompCor(realigned_file=self.realigned_file,
79-
mask_files=self.mask_files,
80-
use_regress_poly=False), [['0.4451946442', '-0.7683311482'],
81-
['-0.4285129505', '-0.0926034137'],
82-
['0.5721540256', '0.5608764842'],
83-
['-0.5367548139', '0.0059943226'],
84-
['-0.0520809054', '0.2940637551']])
81+
mask_files=self.mask_files,
82+
mask_index=0,
83+
use_regress_poly=False),
84+
[['0.4451946442', '-0.7683311482'],
85+
['-0.4285129505', '-0.0926034137'],
86+
['0.5721540256', '0.5608764842'],
87+
['-0.5367548139', '0.0059943226'],
88+
['-0.0520809054', '0.2940637551']])
8589

8690
def test_tcompcor_asymmetric_dim(self):
8791
asymmetric_shape = (2, 3, 4, 5)
8892
asymmetric_data = utils.save_toy_nii(np.zeros(asymmetric_shape),
8993
'asymmetric.nii')
9094

9195
TCompCor(realigned_file=asymmetric_data).run()
92-
assert nb.load('mask.nii').get_data().shape == asymmetric_shape[:3]
96+
assert nb.load('mask_000.nii.gz').get_data().shape == asymmetric_shape[:3]
9397

9498
def test_compcor_bad_input_shapes(self):
9599
shape_less_than = (1, 2, 2, 5) # dim 0 is < dim 0 of self.mask_files (2)
96100
shape_more_than = (3, 3, 3, 5) # dim 0 is > dim 0 of self.mask_files (2)
97101

98102
for data_shape in (shape_less_than, shape_more_than):
99103
data_file = utils.save_toy_nii(np.zeros(data_shape), 'temp.nii')
100-
interface = CompCor(realigned_file=data_file, mask_files=self.mask_files)
104+
interface = CompCor(realigned_file=data_file,
105+
mask_files=self.mask_files[0])
101106
with pytest.raises(ValueError, message="Dimension mismatch"): interface.run()
102107

103108
def test_tcompcor_bad_input_dim(self):
@@ -112,19 +117,25 @@ def test_tcompcor_merge_intersect_masks(self):
112117
mask_files=self.mask_files,
113118
merge_method=method).run()
114119
if method == 'union':
115-
assert np.array_equal(nb.load('mask.nii').get_data(),
120+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
116121
([[[0,0],[0,0]],[[0,0],[1,0]]]))
117122
if method == 'intersect':
118-
assert np.array_equal(nb.load('mask.nii').get_data(),
123+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
119124
([[[0,0],[0,0]],[[0,1],[0,0]]]))
120125

121126
def test_tcompcor_index_mask(self):
122127
TCompCor(realigned_file=self.realigned_file,
123128
mask_files=self.mask_files,
124129
mask_index=1).run()
125-
assert np.array_equal(nb.load('mask.nii').get_data(),
130+
assert np.array_equal(nb.load('mask_000.nii.gz').get_data(),
126131
([[[0,0],[0,0]],[[0,1],[0,0]]]))
127132

133+
def test_tcompcor_multi_mask_no_index(self):
134+
interface = TCompCor(realigned_file=self.realigned_file,
135+
mask_files=self.mask_files)
136+
with pytest.raises(ValueError, message='more than one mask file'):
137+
interface.run()
138+
128139
def run_cc(self, ccinterface, expected_components, expected_header='CompCor'):
129140
# run
130141
ccresult = ccinterface.run()
@@ -137,12 +148,15 @@ def run_cc(self, ccinterface, expected_components, expected_header='CompCor'):
137148
assert ccinterface.inputs.num_components == 6
138149

139150
with open(ccresult.outputs.components_file, 'r') as components_file:
140-
expected_n_components = min(ccinterface.inputs.num_components, self.fake_data.shape[3])
151+
expected_n_components = min(ccinterface.inputs.num_components,
152+
self.fake_data.shape[3])
141153

142154
components_data = [line.split('\t') for line in components_file]
143155

144-
header = components_data.pop(0) # the first item will be '#', we can throw it out
145-
expected_header = [expected_header + str(i) for i in range(expected_n_components)]
156+
# the first item will be '#', we can throw it out
157+
header = components_data.pop(0)
158+
expected_header = [expected_header + '{:02d}'.format(i) for i in
159+
range(expected_n_components)]
146160
for i, heading in enumerate(header):
147161
assert expected_header[i] in heading
148162

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy,
2121
Eval, FWHMx,
2222
MaskTool, Merge, Notes, Refit, Resample, TCat, TStat, To3D,
23-
ZCutUp,)
23+
Unifize, ZCutUp,)

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ class QwarpPlusMinusOutputSpec(TraitedSpec):
24172417

24182418

24192419
class QwarpPlusMinus(CommandLine):
2420-
"""A version of 3dQwarp for performing field susceptibility correction
2420+
"""A version of 3dQwarp for performing field susceptibility correction
24212421
using two images with opposing phase encoding directions.
24222422
24232423
For complete details, see the `3dQwarp Documentation.
@@ -2434,7 +2434,7 @@ class QwarpPlusMinus(CommandLine):
24342434
>>> qwarp.cmdline # doctest: +ALLOW_UNICODE
24352435
'3dQwarp -prefix Qwarp.nii.gz -plusminus -base sub-01_dir-RL_epi.nii.gz -nopadWARP -source sub-01_dir-LR_epi.nii.gz'
24362436
>>> res = warp.run() # doctest: +SKIP
2437-
2437+
24382438
"""
24392439
_cmd = '3dQwarp -prefix Qwarp.nii.gz -plusminus'
24402440
input_spec = QwarpPlusMinusInputSpec

nipype/interfaces/afni/utils.py

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class FWHMx(AFNICommandBase):
695695
_cmd = '3dFWHMx'
696696
input_spec = FWHMxInputSpec
697697
output_spec = FWHMxOutputSpec
698-
698+
699699
references_ = [{'entry': BibTeX('@article{CoxReynoldsTaylor2016,'
700700
'author={R.W. Cox, R.C. Reynolds, and P.A. Taylor},'
701701
'title={AFNI and clustering: false positive rates redux},'
@@ -1237,6 +1237,108 @@ class To3D(AFNICommand):
12371237
output_spec = AFNICommandOutputSpec
12381238

12391239

1240+
class UnifizeInputSpec(AFNICommandInputSpec):
1241+
in_file = File(
1242+
desc='input file to 3dUnifize',
1243+
argstr='-input %s',
1244+
position=-1,
1245+
mandatory=True,
1246+
exists=True,
1247+
copyfile=False)
1248+
out_file = File(
1249+
desc='output image file name',
1250+
argstr='-prefix %s')
1251+
t2 = traits.Bool(
1252+
desc='Treat the input as if it were T2-weighted, rather than '
1253+
'T1-weighted. This processing is done simply by inverting '
1254+
'the image contrast, processing it as if that result were '
1255+
'T1-weighted, and then re-inverting the results '
1256+
'counts of voxel overlap, i.e., each voxel will contain the '
1257+
'number of masks that it is set in.',
1258+
argstr='-T2')
1259+
gm = traits.Bool(
1260+
desc='Also scale to unifize \'gray matter\' = lower intensity voxels '
1261+
'(to aid in registering images from different scanners).',
1262+
argstr='-GM')
1263+
urad = traits.Float(
1264+
desc='Sets the radius (in voxels) of the ball used for the sneaky '
1265+
'trick. Default value is 18.3, and should be changed '
1266+
'proportionally if the dataset voxel size differs significantly '
1267+
'from 1 mm.',
1268+
argstr='-Urad %s')
1269+
scale_file = File(
1270+
desc='output file name to save the scale factor used at each voxel ',
1271+
argstr='-ssave %s')
1272+
no_duplo = traits.Bool(
1273+
desc='Do NOT use the \'duplo down\' step; this can be useful for '
1274+
'lower resolution datasets.',
1275+
argstr='-noduplo')
1276+
epi = traits.Bool(
1277+
desc='Assume the input dataset is a T2 (or T2*) weighted EPI time '
1278+
'series. After computing the scaling, apply it to ALL volumes '
1279+
'(TRs) in the input dataset. That is, a given voxel will be '
1280+
'scaled by the same factor at each TR. '
1281+
'This option also implies \'-noduplo\' and \'-T2\'.'
1282+
'This option turns off \'-GM\' if you turned it on.',
1283+
argstr='-EPI',
1284+
requires=['no_duplo', 't2'],
1285+
xor=['gm'])
1286+
1287+
1288+
class UnifizeOutputSpec(TraitedSpec):
1289+
scale_file = File(desc='scale factor file')
1290+
out_file = File(desc='unifized file', exists=True)
1291+
1292+
1293+
class Unifize(AFNICommand):
1294+
"""3dUnifize - for uniformizing image intensity
1295+
1296+
* The input dataset is supposed to be a T1-weighted volume,
1297+
possibly already skull-stripped (e.g., via 3dSkullStrip).
1298+
However, this program can be a useful step to take BEFORE
1299+
3dSkullStrip, since the latter program can fail if the input
1300+
volume is strongly shaded -- 3dUnifize will (mostly) remove
1301+
such shading artifacts.
1302+
1303+
* The output dataset has the white matter (WM) intensity approximately
1304+
uniformized across space, and scaled to peak at about 1000.
1305+
1306+
* The output dataset is always stored in float format!
1307+
1308+
* If the input dataset has more than 1 sub-brick, only sub-brick
1309+
#0 will be processed!
1310+
1311+
* Want to correct EPI datasets for nonuniformity?
1312+
You can try the new and experimental [Mar 2017] '-EPI' option.
1313+
1314+
* The principal motive for this program is for use in an image
1315+
registration script, and it may or may not be useful otherwise.
1316+
1317+
* This program replaces the older (and very different) 3dUniformize,
1318+
which is no longer maintained and may sublimate at any moment.
1319+
(In other words, we do not recommend the use of 3dUniformize.)
1320+
1321+
For complete details, see the `3dUnifize Documentation.
1322+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dUnifize.html>`_
1323+
1324+
Examples
1325+
========
1326+
1327+
>>> from nipype.interfaces import afni
1328+
>>> unifize = afni.Unifize()
1329+
>>> unifize.inputs.in_file = 'structural.nii'
1330+
>>> unifize.inputs.out_file = 'structural_unifized.nii'
1331+
>>> unifize.cmdline # doctest: +ALLOW_UNICODE
1332+
'3dUnifize -prefix structural_unifized.nii -input structural.nii'
1333+
>>> res = unifize.run() # doctest: +SKIP
1334+
1335+
"""
1336+
1337+
_cmd = '3dUnifize'
1338+
input_spec = UnifizeInputSpec
1339+
output_spec = UnifizeOutputSpec
1340+
1341+
12401342
class ZCutUpInputSpec(AFNICommandInputSpec):
12411343
in_file = File(
12421344
desc='input file to 3dZcutup',

0 commit comments

Comments
 (0)