Skip to content

Commit 38626ee

Browse files
authored
Merge branch 'master' into afni_qwarp
2 parents 02fa84f + 5cc2702 commit 38626ee

File tree

9 files changed

+288
-9
lines changed

9 files changed

+288
-9
lines changed
-150 KB
Loading

doc/images/nipype_architecture_overview2.svg

Lines changed: 1 addition & 1 deletion
Loading

nipype/interfaces/afni/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
Seg, SkullStrip, TCorr1D, TCorrMap, TCorrelate,
1818
TShift, Volreg, Warp, QwarpPlusMinus, Qwarp)
1919
from .svm import (SVMTest, SVMTrain)
20-
from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy, Edge3,
20+
from .utils import (AFNItoNIFTI, Autobox,Axialize, BrickStat, Calc, Copy, Edge3,
2121
Eval, FWHMx,
2222
MaskTool, Merge, Notes, Refit, Resample, TCat, TStat, To3D,
23-
Unifize, ZCutUp, GCOR, Axialize,)
23+
Unifize, ZCutUp, GCOR,Zcat, Zeropad)
2424
from .model import (Deconvolve, Remlfit)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..preprocess import QwarpPlusMinus
4+
5+
6+
def test_QwarpPlusMinus_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
base_file=dict(argstr='-base %s',
10+
copyfile=False,
11+
mandatory=True,
12+
),
13+
blur=dict(argstr='-blur %s',
14+
),
15+
environ=dict(nohash=True,
16+
usedefault=True,
17+
),
18+
ignore_exception=dict(nohash=True,
19+
usedefault=True,
20+
),
21+
minpatch=dict(argstr='-minpatch %d',
22+
),
23+
nopadWARP=dict(argstr='-nopadWARP',
24+
),
25+
noweight=dict(argstr='-noweight',
26+
),
27+
pblur=dict(argstr='-pblur %s',
28+
),
29+
source_file=dict(argstr='-source %s',
30+
copyfile=False,
31+
mandatory=True,
32+
),
33+
terminal_output=dict(nohash=True,
34+
),
35+
)
36+
inputs = QwarpPlusMinus.input_spec()
37+
38+
for key, metadata in list(input_map.items()):
39+
for metakey, value in list(metadata.items()):
40+
assert getattr(inputs.traits()[key], metakey) == value
41+
42+
43+
def test_QwarpPlusMinus_outputs():
44+
output_map = dict(base_warp=dict(),
45+
source_warp=dict(),
46+
warped_base=dict(),
47+
warped_source=dict(),
48+
)
49+
outputs = QwarpPlusMinus.output_spec()
50+
51+
for key, metadata in list(output_map.items()):
52+
for metakey, value in list(metadata.items()):
53+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import Unifize
4+
5+
6+
def test_Unifize_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
environ=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
epi=dict(argstr='-EPI',
13+
requires=['no_duplo', 't2'],
14+
xor=['gm'],
15+
),
16+
gm=dict(argstr='-GM',
17+
),
18+
ignore_exception=dict(nohash=True,
19+
usedefault=True,
20+
),
21+
in_file=dict(argstr='-input %s',
22+
copyfile=False,
23+
mandatory=True,
24+
position=-1,
25+
),
26+
no_duplo=dict(argstr='-noduplo',
27+
),
28+
out_file=dict(argstr='-prefix %s',
29+
name_source='in_file',
30+
),
31+
outputtype=dict(),
32+
scale_file=dict(argstr='-ssave %s',
33+
),
34+
t2=dict(argstr='-T2',
35+
),
36+
terminal_output=dict(nohash=True,
37+
),
38+
urad=dict(argstr='-Urad %s',
39+
),
40+
)
41+
inputs = Unifize.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(inputs.traits()[key], metakey) == value
46+
47+
48+
def test_Unifize_outputs():
49+
output_map = dict(out_file=dict(),
50+
scale_file=dict(),
51+
)
52+
outputs = Unifize.output_spec()
53+
54+
for key, metadata in list(output_map.items()):
55+
for metakey, value in list(metadata.items()):
56+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 164 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,6 @@ def _run_interface(self, runtime):
15351535
def _list_outputs(self):
15361536
return {'out': getattr(self, '_gcor')}
15371537

1538-
15391538
class AxializeInputSpec(AFNICommandInputSpec):
15401539
in_file = File(
15411540
desc='input file to 3daxialize',
@@ -1572,7 +1571,7 @@ class AxializeInputSpec(AFNICommandInputSpec):
15721571
orientation = Str(
15731572
desc='new orientation code',
15741573
argstr='-orient %s')
1575-
1574+
15761575

15771576
class Axialize(AFNICommand):
15781577
"""Read in a dataset and write it out as a new dataset
@@ -1583,7 +1582,6 @@ class Axialize(AFNICommand):
15831582
15841583
Examples
15851584
========
1586-
15871585
>>> from nipype.interfaces import afni
15881586
>>> axial3d = afni.Axialize()
15891587
>>> axial3d.inputs.in_file = 'functional.nii'
@@ -1597,3 +1595,166 @@ class Axialize(AFNICommand):
15971595
_cmd = '3daxialize'
15981596
input_spec = AxializeInputSpec
15991597
output_spec = AFNICommandOutputSpec
1598+
1599+
1600+
class ZcatInputSpec(AFNICommandInputSpec):
1601+
in_files = InputMultiPath(
1602+
File(
1603+
desc='input files to 3dZcat',
1604+
exists=True),
1605+
argstr='%s',
1606+
position=-1,
1607+
mandatory=True,
1608+
copyfile=False)
1609+
out_file = File(
1610+
name_template='zcat',
1611+
desc='output dataset prefix name (default \'zcat\')',
1612+
argstr='-prefix %s')
1613+
datum = traits.Enum(
1614+
'byte','short','float',
1615+
argstr='-datum %s',
1616+
desc='specify data type for output. Valid types are \'byte\', '
1617+
'\'short\' and \'float\'.')
1618+
verb = traits.Bool(
1619+
desc='print out some verbositiness as the program proceeds.',
1620+
argstr='-verb')
1621+
fscale = traits.Bool(
1622+
desc='Force scaling of the output to the maximum integer '
1623+
'range. This only has effect if the output datum is '
1624+
'byte or short (either forced or defaulted). This '
1625+
'option is sometimes necessary to eliminate '
1626+
'unpleasant truncation artifacts.',
1627+
argstr='-fscale',
1628+
xor=['nscale'])
1629+
nscale = traits.Bool(
1630+
desc='Don\'t do any scaling on output to byte or short '
1631+
'datasets. This may be especially useful when '
1632+
'operating on mask datasets whose output values '
1633+
'are only 0\'s and 1\'s.',
1634+
argstr='-nscale',
1635+
xor=['fscale'])
1636+
1637+
class Zcat(AFNICommand):
1638+
"""Copies an image of one type to an image of the same
1639+
or different type using 3dZcat command
1640+
1641+
For complete details, see the `3dZcat Documentation.
1642+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZcat.html>`_
1643+
1644+
Examples
1645+
========
1646+
1647+
>>> from nipype.interfaces import afni
1648+
>>> zcat = afni.Zcat()
1649+
>>> zcat.inputs.in_files = ['functional2.nii', 'functional3.nii']
1650+
>>> zcat.inputs.out_file = 'cat_functional.nii'
1651+
>>> zcat.cmdline # doctest: +ALLOW_UNICODE
1652+
'3dZcat -prefix cat_functional.nii functional2.nii functional3.nii'
1653+
>>> res = zcat.run() # doctest: +SKIP
1654+
"""
1655+
1656+
_cmd = '3dZcat'
1657+
input_spec = ZcatInputSpec
1658+
output_spec = AFNICommandOutputSpec
1659+
1660+
class ZeropadInputSpec(AFNICommandInputSpec):
1661+
in_files = File(
1662+
desc='input dataset',
1663+
argstr='%s',
1664+
position=-1,
1665+
mandatory=True,
1666+
exists=True,
1667+
copyfile=False)
1668+
out_file = File(
1669+
name_template='zeropad',
1670+
desc='output dataset prefix name (default \'zeropad\')',
1671+
argstr='-prefix %s')
1672+
I = traits.Int(
1673+
desc='adds \'n\' planes of zero at the Inferior edge',
1674+
argstr='-I %i',
1675+
xor=['master'])
1676+
S = traits.Int(
1677+
desc='adds \'n\' planes of zero at the Superior edge',
1678+
argstr='-S %i',
1679+
xor=['master'])
1680+
A = traits.Int(
1681+
desc='adds \'n\' planes of zero at the Anterior edge',
1682+
argstr='-A %i',
1683+
xor=['master'])
1684+
P = traits.Int(
1685+
desc='adds \'n\' planes of zero at the Posterior edge',
1686+
argstr='-P %i',
1687+
xor=['master'])
1688+
L = traits.Int(
1689+
desc='adds \'n\' planes of zero at the Left edge',
1690+
argstr='-L %i',
1691+
xor=['master'])
1692+
R = traits.Int(
1693+
desc='adds \'n\' planes of zero at the Right edge',
1694+
argstr='-R %i',
1695+
xor=['master'])
1696+
z = traits.Int(
1697+
desc='adds \'n\' planes of zero on EACH of the '
1698+
'dataset z-axis (slice-direction) faces',
1699+
argstr='-z %i',
1700+
xor=['master'])
1701+
RL = traits.Int(desc='specify that planes should be added or cut '
1702+
'symmetrically to make the resulting volume have'
1703+
'N slices in the right-left direction',
1704+
argstr='-RL %i',
1705+
xor=['master'])
1706+
AP = traits.Int(desc='specify that planes should be added or cut '
1707+
'symmetrically to make the resulting volume have'
1708+
'N slices in the anterior-posterior direction',
1709+
argstr='-AP %i',
1710+
xor=['master'])
1711+
IS = traits.Int(desc='specify that planes should be added or cut '
1712+
'symmetrically to make the resulting volume have'
1713+
'N slices in the inferior-superior direction',
1714+
argstr='-IS %i',
1715+
xor=['master'])
1716+
mm = traits.Bool(desc='pad counts \'n\' are in mm instead of slices, '
1717+
'where each \'n\' is an integer and at least \'n\' '
1718+
'mm of slices will be added/removed; e.g., n = 3 '
1719+
'and slice thickness = 2.5 mm ==> 2 slices added',
1720+
argstr='-mm',
1721+
xor=['master'])
1722+
master = traits.File(desc='match the volume described in dataset '
1723+
'\'mset\', where mset must have the same '
1724+
'orientation and grid spacing as dataset to be '
1725+
'padded. the goal of -master is to make the '
1726+
'output dataset from 3dZeropad match the '
1727+
'spatial \'extents\' of mset by adding or '
1728+
'subtracting slices as needed. You can\'t use '
1729+
'-I,-S,..., or -mm with -master',
1730+
argstr='-master %s',
1731+
xor=['I', 'S', 'A', 'P', 'L', 'R', 'z',
1732+
'RL', 'AP', 'IS', 'mm'])
1733+
1734+
class Zeropad(AFNICommand):
1735+
"""Adds planes of zeros to a dataset (i.e., pads it out).
1736+
1737+
For complete details, see the `3dZeropad Documentation.
1738+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZeropad.html>`_
1739+
1740+
Examples
1741+
========
1742+
1743+
>>> from nipype.interfaces import afni
1744+
>>> zeropad = afni.Zeropad()
1745+
>>> zeropad.inputs.in_files = 'functional.nii'
1746+
>>> zeropad.inputs.out_file = 'pad_functional.nii'
1747+
>>> zeropad.inputs.I = 10
1748+
>>> zeropad.inputs.S = 10
1749+
>>> zeropad.inputs.A = 10
1750+
>>> zeropad.inputs.P = 10
1751+
>>> zeropad.inputs.R = 10
1752+
>>> zeropad.inputs.L = 10
1753+
>>> zeropad.cmdline # doctest: +ALLOW_UNICODE
1754+
'3dZeropad -A 10 -I 10 -L 10 -P 10 -R 10 -S 10 -prefix pad_functional.nii functional.nii'
1755+
>>> res = zeropad.run() # doctest: +SKIP
1756+
"""
1757+
1758+
_cmd = '3dZeropad'
1759+
input_spec = ZeropadInputSpec
1760+
output_spec = AFNICommandOutputSpec

nipype/interfaces/io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,10 @@ def __init__(self, templates, **kwargs):
12561256
infields = []
12571257
for name, template in list(templates.items()):
12581258
for _, field_name, _, _ in string.Formatter().parse(template):
1259-
if field_name is not None and field_name not in infields:
1260-
infields.append(field_name)
1259+
if field_name is not None:
1260+
field_name = re.match("\w+", field_name).group()
1261+
if field_name not in infields:
1262+
infields.append(field_name)
12611263

12621264
self._infields = infields
12631265
self._outfields = list(templates)

nipype/interfaces/tests/test_io.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os.path as op
1212
from subprocess import Popen
1313
import hashlib
14+
from collections import namedtuple
1415

1516
import pytest
1617
import nipype
@@ -62,6 +63,7 @@ def test_s3datagrabber():
6263
templates1 = {"model": "interfaces/{package}/model.py",
6364
"preprocess": "interfaces/{package}/pre*.py"}
6465
templates2 = {"converter": "interfaces/dcm{to!s}nii.py"}
66+
templates3 = {"model": "interfaces/{package.name}/model.py"}
6567

6668
@pytest.mark.parametrize("SF_args, inputs_att, expected", [
6769
({"templates":templates1}, {"package":"fsl"},
@@ -75,6 +77,11 @@ def test_s3datagrabber():
7577
7678
({"templates":templates2}, {"to":2},
7779
{"infields":["to"], "outfields":["converter"], "run_output":{"converter":op.join(op.dirname(nipype.__file__), "interfaces/dcm2nii.py")}, "node_output":["converter"]}),
80+
81+
({"templates": templates3}, {"package": namedtuple("package", ["name"])("fsl")},
82+
{"infields": ["package"], "outfields": ["model"],
83+
"run_output": {"model": op.join(op.dirname(nipype.__file__), "interfaces/fsl/model.py")},
84+
"node_output": ["model"]}),
7885
])
7986
def test_selectfiles(SF_args, inputs_att, expected):
8087
base_dir = op.dirname(nipype.__file__)

tools/build_interface_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
]
4343
docwriter.class_skip_patterns += ['AFNICommand',
4444
'ANTS',
45-
'FSL',
45+
'FSLCommand',
4646
'FS',
4747
'Info',
4848
'^SPM',

0 commit comments

Comments
 (0)