Skip to content

Commit 74deb38

Browse files
committed
allow functions in NwarpCat inputs
1 parent 3ce081a commit 74deb38

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .utils import (ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat,
2323
Bucket, Calc, Cat, CatMatvec, CenterMass, Copy, Dot,
2424
Edge3, Eval, FWHMx, MaskTool, Merge, Notes, NwarpApply,
25-
OneDToolPy,
25+
NwarpCat, OneDToolPy,
2626
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize,
2727
Undump, ZCutUp, GCOR,
2828
Zcat, Zeropad)
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 NwarpCat
4+
5+
6+
def test_NwarpCat_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
environ=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
expad=dict(argstr='-expad %d',
13+
),
14+
ignore_exception=dict(nohash=True,
15+
usedefault=True,
16+
),
17+
in_files=dict(argstr='%s',
18+
descr='list of tuples of 3D warps and associated functions',
19+
mandatory=True,
20+
position=-1,
21+
),
22+
interp=dict(argstr='-interp %s',
23+
),
24+
inv_warp=dict(argstr='-iwarp',
25+
),
26+
num_threads=dict(nohash=True,
27+
usedefault=True,
28+
),
29+
out_file=dict(argstr='-prefix %s',
30+
name_source='in_file',
31+
name_template='%s_Nwarp',
32+
),
33+
outputtype=dict(),
34+
space=dict(argstr='-space %s',
35+
),
36+
terminal_output=dict(deprecated='1.0.0',
37+
nohash=True,
38+
),
39+
verb=dict(argstr='-verb',
40+
),
41+
)
42+
inputs = NwarpCat.input_spec()
43+
44+
for key, metadata in list(input_map.items()):
45+
for metakey, value in list(metadata.items()):
46+
assert getattr(inputs.traits()[key], metakey) == value
47+
48+
49+
def test_NwarpCat_outputs():
50+
output_map = dict(out_file=dict(),
51+
)
52+
outputs = NwarpCat.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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,108 @@ class NwarpApply(AFNICommandBase):
15881588
input_spec = NwarpApplyInputSpec
15891589
output_spec = AFNICommandOutputSpec
15901590

1591+
1592+
class NwarpCatInputSpec(AFNICommandInputSpec):
1593+
in_files = traits.List(
1594+
traits.Either(
1595+
traits.File(), traits.Tuple(
1596+
traits.Enum('IDENT', 'INV', 'SQRT', 'SQRTINV'), traits.File())),
1597+
descr="list of tuples of 3D warps and associated functions",
1598+
mandatory=True,
1599+
argstr="%s",
1600+
position=-1)
1601+
space = traits.String(
1602+
desc='string to attach to the output dataset as its atlas space '
1603+
'marker.',
1604+
argstr='-space %s')
1605+
inv_warp = traits.Bool(
1606+
desc='invert the final warp before output',
1607+
argstr='-iwarp')
1608+
interp = traits.Enum(
1609+
'linear', 'quintic', 'wsinc5',
1610+
desc='specify a different interpolation method than might '
1611+
'be used for the warp',
1612+
argstr='-interp %s',
1613+
default='wsinc5')
1614+
expad = traits.Int(
1615+
desc='Pad the nonlinear warps by the given number of voxels voxels in '
1616+
'all directions. The warp displacements are extended by linear '
1617+
'extrapolation from the faces of the input grid..',
1618+
argstr='-expad %d')
1619+
out_file = File(
1620+
name_template='%s_Nwarp',
1621+
desc='output image file name',
1622+
argstr='-prefix %s',
1623+
name_source='in_file')
1624+
verb = traits.Bool(
1625+
desc='be verbose',
1626+
argstr='-verb')
1627+
1628+
1629+
class NwarpCat(AFNICommand):
1630+
"""Catenates (composes) 3D warps defined on a grid, OR via a matrix.
1631+
1632+
.. note::
1633+
1634+
* All transformations are from DICOM xyz (in mm) to DICOM xyz.
1635+
1636+
* Matrix warps are in files that end in '.1D' or in '.txt'. A matrix
1637+
warp file should have 12 numbers in it, as output (for example), by
1638+
'3dAllineate -1Dmatrix_save'.
1639+
1640+
* Nonlinear warps are in dataset files (AFNI .HEAD/.BRIK or NIfTI .nii)
1641+
with 3 sub-bricks giving the DICOM order xyz grid displacements in mm.
1642+
1643+
* If all the input warps are matrices, then the output is a matrix
1644+
and will be written to the file 'prefix.aff12.1D'.
1645+
Unless the prefix already contains the string '.1D', in which case
1646+
the filename is just the prefix.
1647+
1648+
* If 'prefix' is just 'stdout', then the output matrix is written
1649+
to standard output.
1650+
In any of these cases, the output format is 12 numbers in one row.
1651+
1652+
* If any of the input warps are datasets, they must all be defined on
1653+
the same 3D grid!
1654+
And of course, then the output will be a dataset on the same grid.
1655+
However, you can expand the grid using the '-expad' option.
1656+
1657+
* The order of operations in the final (output) warp is, for the
1658+
case of 3 input warps:
1659+
1660+
OUTPUT(x) = warp3( warp2( warp1(x) ) )
1661+
1662+
That is, warp1 is applied first, then warp2, et cetera.
1663+
The 3D x coordinates are taken from each grid location in the
1664+
first dataset defined on a grid.
1665+
1666+
For complete details, see the `3dNwarpCat Documentation.
1667+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpCat.html>`_
1668+
1669+
Examples
1670+
========
1671+
1672+
>>> from nipype.interfaces import afni
1673+
>>> nwarpcat = afni.NwarpCat()
1674+
>>> nwarpcat.inputs.in_files = ['Q25_warp+tlrc.HEAD', ('IDENT', 'structural.nii')]
1675+
>>> nwarpcat.inputs.out_file = 'Fred_total_WARP'
1676+
>>> nwarpcat.cmdline # doctest: +ALLOW_UNICODE
1677+
"3dNwarpCat -prefix Fred_total_WARP Q25_warp+tlrc.HEAD 'IDENT(structural.nii)'"
1678+
>>> res = nwarpcat.run() # doctest: +SKIP
1679+
1680+
"""
1681+
_cmd = '3dNwarpCat'
1682+
input_spec = NwarpCatInputSpec
1683+
output_spec = AFNICommandOutputSpec
1684+
1685+
def _format_arg(self, name, spec, value):
1686+
if name == 'in_files':
1687+
return spec.argstr%(' '.join(["'" + v[0] + "(" + v[1] + ")'"
1688+
if isinstance(v, tuple) else v
1689+
for v in value]))
1690+
return super(NwarpCat, self)._format_arg(name, spec, value)
1691+
1692+
15911693
class OneDToolPyInputSpec(AFNIPythonCommandInputSpec):
15921694
in_file = File(
15931695
desc='input file to OneDTool',

0 commit comments

Comments
 (0)