Skip to content

Commit ada8c56

Browse files
authored
Merge pull request #2186 from salma1601/afni_undump
add AFNI interface 3dUndump
2 parents 41d831d + 5138a4c commit ada8c56

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Bucket, Calc, Cat, CatMatvec, Copy, Dot,
2424
Edge3, Eval, FWHMx, MaskTool, Merge, Notes, NwarpApply,
2525
OneDToolPy,
26-
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize, ZCutUp, GCOR,
26+
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize,
27+
Undump, ZCutUp, GCOR,
2728
Zcat, Zeropad)
2829
from .model import (Deconvolve, Remlfit)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import Undump
4+
5+
6+
def test_Undump_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
coordinates_specification=dict(argstr='-%s',
10+
),
11+
datatype=dict(argstr='-datum %s',
12+
),
13+
default_value=dict(argstr='-dval %f',
14+
),
15+
environ=dict(nohash=True,
16+
usedefault=True,
17+
),
18+
fill_value=dict(argstr='-fval %f',
19+
),
20+
head_only=dict(argstr='-head_only',
21+
),
22+
ignore_exception=dict(nohash=True,
23+
usedefault=True,
24+
),
25+
in_file=dict(argstr='-master %s',
26+
copyfile=False,
27+
mandatory=True,
28+
position=-1,
29+
),
30+
mask_file=dict(argstr='-mask %s',
31+
),
32+
out_file=dict(argstr='-prefix %s',
33+
name_source='in_file',
34+
),
35+
outputtype=dict(),
36+
srad=dict(argstr='-srad -%f',
37+
),
38+
terminal_output=dict(nohash=True,
39+
),
40+
)
41+
inputs = Undump.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_Undump_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = Undump.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,103 @@ class To3D(AFNICommand):
19631963
output_spec = AFNICommandOutputSpec
19641964

19651965

1966+
class UndumpInputSpec(AFNICommandInputSpec):
1967+
in_file = File(
1968+
desc='input file to 3dUndump, whose geometry will determine'
1969+
'the geometry of the output',
1970+
argstr='-master %s',
1971+
position=-1,
1972+
mandatory=True,
1973+
exists=True,
1974+
copyfile=False)
1975+
out_file = File(
1976+
desc='output image file name',
1977+
argstr='-prefix %s',
1978+
name_source='in_file')
1979+
mask_file = File(
1980+
desc='mask image file name. Only voxels that are nonzero in the mask '
1981+
'can be set.',
1982+
argstr='-mask %s')
1983+
datatype = traits.Enum(
1984+
'short', 'float', 'byte',
1985+
desc='set output file datatype',
1986+
argstr='-datum %s')
1987+
default_value = traits.Float(
1988+
desc='default value stored in each input voxel that does not have '
1989+
'a value supplied in the input file',
1990+
argstr='-dval %f')
1991+
fill_value = traits.Float(
1992+
desc='value, used for each voxel in the output dataset that is NOT '
1993+
'listed in the input file',
1994+
argstr='-fval %f')
1995+
coordinates_specification = traits.Enum(
1996+
'ijk', 'xyz',
1997+
desc='Coordinates in the input file as index triples (i, j, k) '
1998+
'or spatial coordinates (x, y, z) in mm',
1999+
argstr='-%s')
2000+
srad = traits.Float(
2001+
desc='radius in mm of the sphere that will be filled about each input '
2002+
'(x,y,z) or (i,j,k) voxel. If the radius is not given, or is 0, '
2003+
'then each input data line sets the value in only one voxel.',
2004+
argstr='-srad -%f')
2005+
srad = traits.Tuple(
2006+
traits.Enum('R', 'L'), traits.Enum('A', 'P'), traits.Enum('I', 'S'),
2007+
desc='radius in mm of the sphere that will be filled about each input '
2008+
'(x,y,z) or (i,j,k) voxel. If the radius is not given, or is 0, '
2009+
'then each input data line sets the value in only one voxel.',
2010+
argstr='-srad -%f')
2011+
head_only = traits.Bool(
2012+
desc='create only the .HEAD file which gets exploited by '
2013+
'the AFNI matlab library function New_HEAD.m',
2014+
argstr='-head_only')
2015+
2016+
2017+
class UndumpOutputSpec(TraitedSpec):
2018+
out_file = File(desc='assembled file', exists=True)
2019+
2020+
2021+
class Undump(AFNICommand):
2022+
"""3dUndump - Assembles a 3D dataset from an ASCII list of coordinates and
2023+
(optionally) values.
2024+
2025+
The input file(s) are ASCII files, with one voxel specification per
2026+
line. A voxel specification is 3 numbers (-ijk or -xyz coordinates),
2027+
with an optional 4th number giving the voxel value. For example:
2028+
2029+
1 2 3
2030+
3 2 1 5
2031+
5.3 6.2 3.7
2032+
// this line illustrates a comment
2033+
2034+
The first line puts a voxel (with value given by '-dval') at point
2035+
(1,2,3). The second line puts a voxel (with value 5) at point (3,2,1).
2036+
The third line puts a voxel (with value given by '-dval') at point
2037+
(5.3,6.2,3.7). If -ijk is in effect, and fractional coordinates
2038+
are given, they will be rounded to the nearest integers; for example,
2039+
the third line would be equivalent to (i,j,k) = (5,6,4).
2040+
2041+
2042+
For complete details, see the `3dUndump Documentation.
2043+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dUndump.html>`_
2044+
2045+
Examples
2046+
========
2047+
2048+
>>> from nipype.interfaces import afni
2049+
>>> unndump = afni.Undump()
2050+
>>> unndump.inputs.in_file = 'structural.nii'
2051+
>>> unndump.inputs.out_file = 'structural_undumped.nii'
2052+
>>> unndump.cmdline # doctest: +ALLOW_UNICODE
2053+
'3dUndump -prefix structural_undumped.nii -master structural.nii'
2054+
>>> res = unndump.run() # doctest: +SKIP
2055+
2056+
"""
2057+
2058+
_cmd = '3dUndump'
2059+
input_spec = UndumpInputSpec
2060+
output_spec = UndumpOutputSpec
2061+
2062+
19662063
class UnifizeInputSpec(AFNICommandInputSpec):
19672064
in_file = File(
19682065
desc='input file to 3dUnifize',

0 commit comments

Comments
 (0)