Skip to content

Commit 8e25ba7

Browse files
authored
Merge pull request #2450 from salma1601/afni_nwarpadjust
Afni nwarpadjust
2 parents 27b33ef + 3a27625 commit 8e25ba7

File tree

3 files changed

+129
-3
lines changed

3 files changed

+129
-3
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .utils import (
1919
ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket, Calc, Cat,
2020
CatMatvec, CenterMass, ConvertDset, Copy, Dot, Edge3, Eval, FWHMx,
21-
MaskTool, Merge, Notes, NwarpApply, NwarpCat, OneDToolPy, Refit, Resample,
22-
TCat, TCatSubBrick, TStat, To3D, Unifize, Undump, ZCutUp, GCOR, Zcat,
23-
Zeropad)
21+
MaskTool, Merge, Notes, NwarpApply, NwarpAdjust, NwarpCat, OneDToolPy,
22+
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize, Undump, ZCutUp,
23+
GCOR, Zcat, Zeropad)
2424
from .model import (Deconvolve, Remlfit, Synthesize)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import NwarpAdjust
4+
5+
6+
def test_NwarpAdjust_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
environ=dict(
10+
nohash=True,
11+
usedefault=True,
12+
),
13+
ignore_exception=dict(
14+
deprecated='1.0.0',
15+
nohash=True,
16+
usedefault=True,
17+
),
18+
in_files=dict(argstr='-source %s', ),
19+
num_threads=dict(
20+
nohash=True,
21+
usedefault=True,
22+
),
23+
out_file=dict(
24+
argstr='-prefix %s',
25+
keep_extension=True,
26+
name_source='in_files',
27+
name_template='%s_NwarpAdjust',
28+
requires=['in_files'],
29+
),
30+
outputtype=dict(),
31+
terminal_output=dict(
32+
deprecated='1.0.0',
33+
nohash=True,
34+
),
35+
warps=dict(
36+
argstr='-nwarp %s',
37+
mandatory=True,
38+
),
39+
)
40+
inputs = NwarpAdjust.input_spec()
41+
42+
for key, metadata in list(input_map.items()):
43+
for metakey, value in list(metadata.items()):
44+
assert getattr(inputs.traits()[key], metakey) == value
45+
def test_NwarpAdjust_outputs():
46+
output_map = dict(out_file=dict(), )
47+
outputs = NwarpAdjust.output_spec()
48+
49+
for key, metadata in list(output_map.items()):
50+
for metakey, value in list(metadata.items()):
51+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,81 @@ def _list_outputs(self):
15111511
return outputs
15121512

15131513

1514+
class NwarpAdjustInputSpec(AFNICommandInputSpec):
1515+
warps = InputMultiPath(
1516+
File(exists=True),
1517+
minlen=5,
1518+
mandatory=True,
1519+
argstr='-nwarp %s',
1520+
desc='List of input 3D warp datasets')
1521+
in_files = InputMultiPath(
1522+
File(exists=True),
1523+
minlen=5,
1524+
argstr='-source %s',
1525+
desc='List of input 3D datasets to be warped by the adjusted warp '
1526+
'datasets. There must be exactly as many of these datasets as '
1527+
'there are input warps.')
1528+
out_file = File(
1529+
desc='Output mean dataset, only needed if in_files are also given. '
1530+
'The output dataset will be on the common grid shared by the '
1531+
'source datasets.',
1532+
argstr='-prefix %s',
1533+
name_source='in_files',
1534+
name_template='%s_NwarpAdjust',
1535+
keep_extension=True,
1536+
requires=['in_files'])
1537+
1538+
1539+
class NwarpAdjust(AFNICommandBase):
1540+
"""This program takes as input a bunch of 3D warps, averages them,
1541+
and computes the inverse of this average warp. It then composes
1542+
each input warp with this inverse average to 'adjust' the set of
1543+
warps. Optionally, it can also read in a set of 1-brick datasets
1544+
corresponding to the input warps, and warp each of them, and average
1545+
those.
1546+
1547+
For complete details, see the `3dNwarpAdjust Documentation.
1548+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpAdjust.html>`_
1549+
1550+
Examples
1551+
========
1552+
1553+
>>> from nipype.interfaces import afni
1554+
>>> adjust = afni.NwarpAdjust()
1555+
>>> adjust.inputs.warps = ['func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz']
1556+
>>> adjust.cmdline
1557+
'3dNwarpAdjust -nwarp func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz'
1558+
>>> res = adjust.run() # doctest: +SKIP
1559+
1560+
"""
1561+
_cmd = '3dNwarpAdjust'
1562+
input_spec = NwarpAdjustInputSpec
1563+
output_spec = AFNICommandOutputSpec
1564+
1565+
def _parse_inputs(self, skip=None):
1566+
if not self.inputs.in_files:
1567+
if skip is None:
1568+
skip = []
1569+
skip += ['out_file']
1570+
return super(NwarpAdjust, self)._parse_inputs(skip=skip)
1571+
1572+
def _list_outputs(self):
1573+
outputs = self.output_spec().get()
1574+
1575+
if self.inputs.in_files:
1576+
if self.inputs.out_file:
1577+
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
1578+
else:
1579+
basename = os.path.basename(self.inputs.in_files[0])
1580+
basename_noext, ext = op.splitext(basename)
1581+
if '.gz' in ext:
1582+
basename_noext, ext2 = op.splitext(basename_noext)
1583+
ext = ext2 + ext
1584+
outputs['out_file'] = os.path.abspath(
1585+
basename_noext + '_NwarpAdjust' + ext)
1586+
return outputs
1587+
1588+
15141589
class NwarpApplyInputSpec(CommandLineInputSpec):
15151590
in_file = traits.Either(
15161591
File(exists=True),

0 commit comments

Comments
 (0)