Skip to content

Commit 90bcf3f

Browse files
committed
Add ConvertWarp interface
1 parent f8b4fc7 commit 90bcf3f

File tree

4 files changed

+196
-6
lines changed

4 files changed

+196
-6
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ImageStats, FilterRegressor, Overlay, Slicer,
1717
PlotTimeSeries, PlotMotionParams, ConvertXFM,
1818
SwapDimensions, PowerSpectrum, Reorient2Std,
19-
Complex, InvWarp, WarpUtils)
19+
Complex, InvWarp, WarpUtils, ConvertWarp)
2020

2121
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp,
2222
SigLoss, EddyCorrect)

nipype/interfaces/fsl/preprocess.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,17 @@ def _list_outputs(self):
678678
'_variance.ext', cwd=cwd)
679679
outputs['std_img'] = self._gen_fname(outputs['out_file'] +
680680
'_sigma.ext', cwd=cwd)
681-
681+
682682
# The mean image created if -stats option is specified ('meanvol')
683-
# is missing the top and bottom slices. Therefore we only expose the
684-
# mean image created by -meanvol option ('mean_reg') which isn't
683+
# is missing the top and bottom slices. Therefore we only expose the
684+
# mean image created by -meanvol option ('mean_reg') which isn't
685685
# corrupted.
686686
# Note that the same problem holds for the std and variance image.
687-
687+
688688
if isdefined(self.inputs.mean_vol) and self.inputs.mean_vol:
689689
outputs['mean_img'] = self._gen_fname(outputs['out_file'] +
690690
'_mean_reg.ext', cwd=cwd)
691-
691+
692692
if isdefined(self.inputs.save_mats) and self.inputs.save_mats:
693693
_, filename = os.path.split(outputs['out_file'])
694694
matpathname = os.path.join(cwd, filename + '.mat')
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.fsl.utils import ConvertWarp
4+
5+
def test_ConvertWarp_inputs():
6+
input_map = dict(abswarp=dict(argstr='--abs',
7+
xor=['relwarp'],
8+
),
9+
args=dict(argstr='%s',
10+
),
11+
cons_jacobian=dict(argstr='--constrainj',
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
jacobian_max=dict(argstr='--jmax=%f',
20+
),
21+
jacobian_min=dict(argstr='--jmin=%f',
22+
),
23+
out_abswarp=dict(argstr='--absout',
24+
xor=['out_relwarp'],
25+
),
26+
out_file=dict(argstr='--out=%s',
27+
genfile=True,
28+
hash_files=False,
29+
),
30+
out_relwarp=dict(argstr='--relout',
31+
xor=['out_abswarp'],
32+
),
33+
output_type=dict(),
34+
postmat=dict(argstr='--postmat=%s',
35+
),
36+
premat=dict(argstr='--premat=%s',
37+
),
38+
reference=dict(argstr='--ref=%s',
39+
mandatory=True,
40+
),
41+
relwarp=dict(argstr='--rel',
42+
xor=['abswarp'],
43+
),
44+
shift_direction=dict(argstr='--shiftdir=%s',
45+
requires=['shift_in_file'],
46+
),
47+
shift_in_file=dict(argstr='--shiftmap=%s',
48+
),
49+
terminal_output=dict(mandatory=True,
50+
nohash=True,
51+
),
52+
warp1=dict(argstr='--warp1=%s',
53+
),
54+
warp2=dict(argstr='--warp2=%s',
55+
),
56+
)
57+
inputs = ConvertWarp.input_spec()
58+
59+
for key, metadata in input_map.items():
60+
for metakey, value in metadata.items():
61+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
62+
63+
def test_ConvertWarp_outputs():
64+
output_map = dict(out_file=dict(),
65+
)
66+
outputs = ConvertWarp.output_spec()
67+
68+
for key, metadata in output_map.items():
69+
for metakey, value in metadata.items():
70+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
71+

nipype/interfaces/fsl/utils.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,3 +1578,122 @@ def _gen_filename(self, name):
15781578
return self._list_outputs()[name]
15791579

15801580
return None
1581+
1582+
1583+
1584+
1585+
class ConvertWarpInputSpec(FSLCommandInputSpec):
1586+
reference = File(exists=True, argstr='--ref=%s', mandatory=True,
1587+
desc=('Name of a file in target space of the full transform.'))
1588+
1589+
out_file = File(genfile=True, hash_files=False, argstr='--out=%s',
1590+
desc=('Name of output file, containing warps that are the combination of all '
1591+
'those given as arguments. The format of this will be a field-file (rather '
1592+
'than spline coefficients) with any affine components included.'))
1593+
1594+
premat = File(exists=True, argstr='--premat=%s',
1595+
desc='filename for pre-transform (affine matrix)')
1596+
1597+
warp1 = File(exists=True, argstr='--warp1=%s',
1598+
desc=('Name of file containing warp-fields/coefficients. This could e.g. be a '
1599+
'fnirt-transform from a subjects structural scan to an average of a group '
1600+
'of subjects.'))
1601+
1602+
warp2 = File(exists=True, argstr='--warp2=%s',
1603+
desc=('Name of file containing warp-fields/coefficients. This could e.g. be a '
1604+
'fnirt-transform from the average of a group of subjects to some standard '
1605+
'space (e.g. MNI152).'))
1606+
1607+
postmat = File(exists=True, argstr='--postmat=%s',
1608+
desc=('Name of file containing an affine transform. It could e.g. be an affine '
1609+
'transform that maps the MNI152-space into a better approximation to the '
1610+
'Talairach-space (if indeed there is one).'))
1611+
1612+
shift_in_file = File(exists=True, argstr='--shiftmap=%s',
1613+
desc=('Name of file containing a "shiftmap", a non-linear transform with '
1614+
'displacements only in one direction. This would typically be a '
1615+
'fieldmap that has been pre-processed using fugue that maps a '
1616+
'subjects functional (EPI) data onto an undistorted space (i.e. a space '
1617+
'that corresponds to his/her true anatomy).'))
1618+
1619+
shift_direction = traits.Enum('-y','y','x','-x','z','-z',
1620+
argstr="--shiftdir=%s", requires=['shift_in_file'],
1621+
desc=('Indicates the direction that the distortions from '
1622+
'--shiftmap goes. It depends on the direction and '
1623+
'polarity of the phase-encoding in the EPI sequence.'))
1624+
1625+
cons_jacobian = traits.Bool(False, argstr='--constrainj',
1626+
desc=('Constrain the Jacobian of the warpfield to lie within specified '
1627+
'min/max limits.'))
1628+
1629+
jacobian_min = traits.Float(argstr='--jmin=%f',
1630+
desc=('Minimum acceptable Jacobian value for '
1631+
'constraint (default 0.01)'))
1632+
jacobian_max = traits.Float(argstr='--jmax=%f',
1633+
desc=('Maximum acceptable Jacobian value for '
1634+
'constraint (default 100.0)'))
1635+
1636+
abswarp = traits.Bool(argstr='--abs', xor=['relwarp'],
1637+
desc=('If set it indicates that the warps in --warp1 and --warp2 should be '
1638+
'interpreted as absolute. I.e. the values in --warp1/2 are the '
1639+
'coordinates in the next space, rather than displacements. This flag '
1640+
'is ignored if --warp1/2 was created by fnirt, which always creates '
1641+
'relative displacements.'))
1642+
1643+
relwarp = traits.Bool(argstr='--rel', xor=['abswarp'],
1644+
desc=('If set it indicates that the warps in --warp1/2 should be interpreted '
1645+
'as relative. I.e. the values in --warp1/2 are displacements from the '
1646+
'coordinates in the next space.'))
1647+
1648+
out_abswarp = traits.Bool(argstr='--absout', xor=['out_relwarp'],
1649+
desc=('If set it indicates that the warps in --out should be relative, i.e. '
1650+
'the vaulues in --out are displacements from the coordinates in --ref.'))
1651+
1652+
out_relwarp = traits.Bool(argstr='--relout', xor=['out_abswarp'],
1653+
desc=('If set it indicates that the warps in --out should be relative, i.e. '
1654+
'the vaulues in --out are displacements from the coordinates in --ref.'))
1655+
1656+
1657+
class ConvertWarpOutputSpec(TraitedSpec):
1658+
out_file = File(exists=True,
1659+
desc=('Name of output file, containing the warp as field or coefficients.'))
1660+
1661+
1662+
class ConvertWarp(FSLCommand):
1663+
"""Use FSL `convertwarp <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/fnirt/warp_utils.html>`_
1664+
for combining multiple transforms into one.
1665+
1666+
1667+
Examples::
1668+
1669+
>>> from nipype.interfaces.fsl import ConvertWarp
1670+
>>> warputils = ConvertWarp()
1671+
>>> warputils.inputs.warp1 = "warpfield.nii"
1672+
>>> warputils.inputs.reference = "T1.nii"
1673+
>>> warputils.inputs.relwarp = True
1674+
>>> warputils.cmdline # doctest: +ELLIPSIS
1675+
'convertwarp --out=.../T1_concatwarps.nii.gz --ref=T1.nii --rel --warp1=warpfield.nii'
1676+
>>> res = invwarp.run() # doctest: +SKIP
1677+
"""
1678+
1679+
input_spec = ConvertWarpInputSpec
1680+
output_spec = ConvertWarpOutputSpec
1681+
1682+
_cmd = 'convertwarp'
1683+
1684+
def _list_outputs(self):
1685+
outputs = self.output_spec().get()
1686+
outputs['out_file'] = self.inputs.out_file
1687+
1688+
if not isdefined(outputs['out_file']):
1689+
outputs['out_file'] = self._gen_fname(self.inputs.reference,
1690+
suffix='_concatwarps')
1691+
1692+
outputs['out_file'] = os.path.abspath(outputs['out_file'])
1693+
return outputs
1694+
1695+
def _gen_filename(self, name):
1696+
if name == 'out_file':
1697+
return self._list_outputs()[name]
1698+
1699+
return None

0 commit comments

Comments
 (0)