Skip to content

Afni nwarpadjust #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nipype/interfaces/afni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utils import (
ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket, Calc, Cat,
CatMatvec, CenterMass, ConvertDset, Copy, Dot, Edge3, Eval, FWHMx,
MaskTool, Merge, Notes, NwarpApply, NwarpCat, OneDToolPy, Refit, Resample,
TCat, TCatSubBrick, TStat, To3D, Unifize, Undump, ZCutUp, GCOR, Zcat,
Zeropad)
MaskTool, Merge, Notes, NwarpApply, NwarpAdjust, NwarpCat, OneDToolPy,
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize, Undump, ZCutUp,
GCOR, Zcat, Zeropad)
from .model import (Deconvolve, Remlfit, Synthesize)
51 changes: 51 additions & 0 deletions nipype/interfaces/afni/tests/test_auto_NwarpAdjust.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..utils import NwarpAdjust


def test_NwarpAdjust_inputs():
input_map = dict(
args=dict(argstr='%s', ),
environ=dict(
nohash=True,
usedefault=True,
),
ignore_exception=dict(
deprecated='1.0.0',
nohash=True,
usedefault=True,
),
in_files=dict(argstr='-source %s', ),
num_threads=dict(
nohash=True,
usedefault=True,
),
out_file=dict(
argstr='-prefix %s',
keep_extension=True,
name_source='in_files',
name_template='%s_NwarpAdjust',
requires=['in_files'],
),
outputtype=dict(),
terminal_output=dict(
deprecated='1.0.0',
nohash=True,
),
warps=dict(
argstr='-nwarp %s',
mandatory=True,
),
)
inputs = NwarpAdjust.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value
def test_NwarpAdjust_outputs():
output_map = dict(out_file=dict(), )
outputs = NwarpAdjust.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
75 changes: 75 additions & 0 deletions nipype/interfaces/afni/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,81 @@ def _list_outputs(self):
return outputs


class NwarpAdjustInputSpec(AFNICommandInputSpec):
warps = InputMultiPath(
File(exists=True),
minlen=5,
mandatory=True,
argstr='-nwarp %s',
desc='List of input 3D warp datasets')
in_files = InputMultiPath(
File(exists=True),
minlen=5,
argstr='-source %s',
desc='List of input 3D datasets to be warped by the adjusted warp '
'datasets. There must be exactly as many of these datasets as '
'there are input warps.')
out_file = File(
desc='Output mean dataset, only needed if in_files are also given. '
'The output dataset will be on the common grid shared by the '
'source datasets.',
argstr='-prefix %s',
name_source='in_files',
name_template='%s_NwarpAdjust',
keep_extension=True,
requires=['in_files'])


class NwarpAdjust(AFNICommandBase):
"""This program takes as input a bunch of 3D warps, averages them,
and computes the inverse of this average warp. It then composes
each input warp with this inverse average to 'adjust' the set of
warps. Optionally, it can also read in a set of 1-brick datasets
corresponding to the input warps, and warp each of them, and average
those.

For complete details, see the `3dNwarpAdjust Documentation.
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpAdjust.html>`_

Examples
========

>>> from nipype.interfaces import afni
>>> adjust = afni.NwarpAdjust()
>>> adjust.inputs.warps = ['func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz']
>>> adjust.cmdline
'3dNwarpAdjust -nwarp func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz'
>>> res = adjust.run() # doctest: +SKIP

"""
_cmd = '3dNwarpAdjust'
input_spec = NwarpAdjustInputSpec
output_spec = AFNICommandOutputSpec

def _parse_inputs(self, skip=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this function can be skipped as well.

if not self.inputs.in_files:
if skip is None:
skip = []
skip += ['out_file']
return super(NwarpAdjust, self)._parse_inputs(skip=skip)

def _list_outputs(self):
outputs = self.output_spec().get()

if self.inputs.in_files:
if self.inputs.out_file:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
else:
basename = os.path.basename(self.inputs.in_files[0])
basename_noext, ext = op.splitext(basename)
if '.gz' in ext:
basename_noext, ext2 = op.splitext(basename_noext)
ext = ext2 + ext
outputs['out_file'] = os.path.abspath(
basename_noext + '_NwarpAdjust' + ext)
return outputs


class NwarpApplyInputSpec(CommandLineInputSpec):
in_file = traits.Either(
File(exists=True),
Expand Down