Skip to content

Commit b3c71b0

Browse files
committed
Add 3dZcat and 3dZeropad
Create nipype wrappers for the AFNI commands 3dZcat and 3dZeropad.
1 parent 9ac1058 commit b3c71b0

File tree

4 files changed

+272
-1
lines changed

4 files changed

+272
-1
lines changed

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-
Unifize, ZCutUp, GCOR,)
23+
Unifize, ZCutUp, GCOR, Zcat, Zeropad)
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: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,3 +1441,165 @@ def _run_interface(self, runtime):
14411441

14421442
def _list_outputs(self):
14431443
return {'out': getattr(self, '_gcor')}
1444+
1445+
class ZcatInputSpec(AFNICommandInputSpec):
1446+
in_files = InputMultiPath(
1447+
File(
1448+
desc='input files to 3dZcat',
1449+
exists=True),
1450+
argstr='%s',
1451+
position=-1,
1452+
mandatory=True,
1453+
copyfile=False)
1454+
out_file = File(
1455+
name_template='zcat',
1456+
desc='output dataset prefix name (default \'zcat\')',
1457+
argstr='-prefix %s')
1458+
datum = traits.Enum(
1459+
'byte','short','float',
1460+
argstr='-datum %s',
1461+
desc='specify data type for output. Valid types are \'byte\', '
1462+
'\'short\' and \'float\'.')
1463+
verb = traits.Bool(
1464+
desc='print out some verbositiness as the program proceeds.',
1465+
argstr='-verb')
1466+
fscale = traits.Bool(
1467+
desc='Force scaling of the output to the maximum integer '
1468+
'range. This only has effect if the output datum is '
1469+
'byte or short (either forced or defaulted). This '
1470+
'option is sometimes necessary to eliminate '
1471+
'unpleasant truncation artifacts.',
1472+
argstr='-fscale',
1473+
xor=['nscale'])
1474+
nscale = traits.Bool(
1475+
desc='Don\'t do any scaling on output to byte or short '
1476+
'datasets. This may be especially useful when '
1477+
'operating on mask datasets whose output values '
1478+
'are only 0\'s and 1\'s.',
1479+
argstr='-nscale',
1480+
xor=['fscale'])
1481+
1482+
class Zcat(AFNICommand):
1483+
"""Copies an image of one type to an image of the same
1484+
or different type using 3dZcat command
1485+
1486+
For complete details, see the `3dZcat Documentation.
1487+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZcat.html>`_
1488+
1489+
Examples
1490+
========
1491+
1492+
>>> from nipype.interfaces import afni
1493+
>>> zcat = afni.Zcat()
1494+
>>> zcat.inputs.in_files = ['functional2.nii', 'functional3.nii']
1495+
>>> zcat.inputs.out_file = 'cat_functional.nii'
1496+
>>> zcat.cmdline # doctest: +ALLOW_UNICODE
1497+
'3dZcat -prefix cat_functional.nii functional2.nii functional3.nii'
1498+
>>> res = zcat.run() # doctest: +SKIP
1499+
"""
1500+
1501+
_cmd = '3dZcat'
1502+
input_spec = ZcatInputSpec
1503+
output_spec = AFNICommandOutputSpec
1504+
1505+
class ZeropadInputSpec(AFNICommandInputSpec):
1506+
in_files = File(
1507+
desc='input dataset',
1508+
argstr='%s',
1509+
position=-1,
1510+
mandatory=True,
1511+
exists=True,
1512+
copyfile=False)
1513+
out_file = File(
1514+
name_template='zeropad',
1515+
desc='output dataset prefix name (default \'zeropad\')',
1516+
argstr='-prefix %s')
1517+
I = traits.Int(
1518+
desc='adds \'n\' planes of zero at the Inferior edge',
1519+
argstr='-I %i',
1520+
xor=['master'])
1521+
S = traits.Int(
1522+
desc='adds \'n\' planes of zero at the Superior edge',
1523+
argstr='-S %i',
1524+
xor=['master'])
1525+
A = traits.Int(
1526+
desc='adds \'n\' planes of zero at the Anterior edge',
1527+
argstr='-A %i',
1528+
xor=['master'])
1529+
P = traits.Int(
1530+
desc='adds \'n\' planes of zero at the Posterior edge',
1531+
argstr='-P %i',
1532+
xor=['master'])
1533+
L = traits.Int(
1534+
desc='adds \'n\' planes of zero at the Left edge',
1535+
argstr='-L %i',
1536+
xor=['master'])
1537+
R = traits.Int(
1538+
desc='adds \'n\' planes of zero at the Right edge',
1539+
argstr='-R %i',
1540+
xor=['master'])
1541+
z = traits.Int(
1542+
desc='adds \'n\' planes of zero on EACH of the '
1543+
'dataset z-axis (slice-direction) faces',
1544+
argstr='-z %i',
1545+
xor=['master'])
1546+
RL = traits.Int(desc='specify that planes should be added or cut '
1547+
'symmetrically to make the resulting volume have'
1548+
'N slices in the right-left direction',
1549+
argstr='-RL %i',
1550+
xor=['master'])
1551+
AP = traits.Int(desc='specify that planes should be added or cut '
1552+
'symmetrically to make the resulting volume have'
1553+
'N slices in the anterior-posterior direction',
1554+
argstr='-AP %i',
1555+
xor=['master'])
1556+
IS = traits.Int(desc='specify that planes should be added or cut '
1557+
'symmetrically to make the resulting volume have'
1558+
'N slices in the inferior-superior direction',
1559+
argstr='-IS %i',
1560+
xor=['master'])
1561+
mm = traits.Bool(desc='pad counts \'n\' are in mm instead of slices, '
1562+
'where each \'n\' is an integer and at least \'n\' '
1563+
'mm of slices will be added/removed; e.g., n = 3 '
1564+
'and slice thickness = 2.5 mm ==> 2 slices added',
1565+
argstr='-mm',
1566+
xor=['master'])
1567+
master = traits.File(desc='match the volume described in dataset '
1568+
'\'mset\', where mset must have the same '
1569+
'orientation and grid spacing as dataset to be '
1570+
'padded. the goal of -master is to make the '
1571+
'output dataset from 3dZeropad match the '
1572+
'spatial \'extents\' of mset by adding or '
1573+
'subtracting slices as needed. You can\'t use '
1574+
'-I,-S,..., or -mm with -master',
1575+
argstr='-master %s',
1576+
xor=['I', 'S', 'A', 'P', 'L', 'R', 'z',
1577+
'RL', 'AP', 'IS', 'mm'])
1578+
1579+
class Zeropad(AFNICommand):
1580+
"""Adds planes of zeros to a dataset (i.e., pads it out).
1581+
1582+
For complete details, see the `3dZeropad Documentation.
1583+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZeropad.html>`_
1584+
1585+
Examples
1586+
========
1587+
1588+
>>> from nipype.interfaces import afni
1589+
>>> zeropad = afni.Zeropad()
1590+
>>> zeropad.inputs.in_files = 'functional.nii'
1591+
>>> zeropad.inputs.out_file = 'pad_functional.nii'
1592+
>>> zeropad.inputs.I = 10
1593+
>>> zeropad.inputs.S = 10
1594+
>>> zeropad.inputs.A = 10
1595+
>>> zeropad.inputs.P = 10
1596+
>>> zeropad.inputs.R = 10
1597+
>>> zeropad.inputs.L = 10
1598+
>>> zeropad.cmdline # doctest: +ALLOW_UNICODE
1599+
'3dZeropad -A 10 -I 10 -L 10 -P 10 -R 10 -S 10 -prefix pad_functional.nii functional.nii'
1600+
>>> res = zeropad.run() # doctest: +SKIP
1601+
"""
1602+
1603+
_cmd = '3dZeropad'
1604+
input_spec = ZeropadInputSpec
1605+
output_spec = AFNICommandOutputSpec

0 commit comments

Comments
 (0)