Skip to content

Commit db91b8b

Browse files
author
bpinsard
committed
fsl invertwarp
1 parent ea909c7 commit db91b8b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

nipype/interfaces/fsl/tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,16 @@ def test_swapdims():
382382

383383
# Clean up
384384
clean_directory(testdir, origdir)
385+
386+
@skipif(no_fsl)
387+
def test_invwarp():
388+
input_map = dict(environ = dict(),
389+
args = dict(argstr='%s',),
390+
environ = dict(),
391+
warp = dict(mandatory=True,),
392+
reference = dict(mandatory=True,),
393+
inverse_warp = dict(mandatory=True,))
394+
instance = fsl.InvWarp()
395+
for key, metadata in input_map.items():
396+
for metakey, value in metadata.items():
397+
yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value

nipype/interfaces/fsl/utils.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,59 @@ def _list_outputs(self):
11881188
else:
11891189
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
11901190
return outputs
1191+
1192+
class InvWarpInputSpec(FSLCommandInputSpec):
1193+
warp = File(exists=True,
1194+
desc='Name of file containing warp-coefficients/fields. This would typically be the output from the --cout switch of fnirt (but can also use fields, like the output from --fout).',
1195+
argstr='--warp=%s',
1196+
mandatory=True)
1197+
reference = File(exists=True,
1198+
desc='Name of a file in target space. Note that the target space is now different from the target space that was used to create the --warp file. It would typically be the file that was specified with the --in argument when running fnirt.',
1199+
argstr='--ref=%s',
1200+
mandatory=True)
1201+
1202+
inverse_warp = File(exists=True,
1203+
desc='Name of output file, containing warps that are the "reverse" of those in --warp. This will be a field-file (rather than a file of spline coefficients), and it will have any affine component included as part of the displacements.',
1204+
argstr='--out=%s',
1205+
gen_file=True)
1206+
1207+
absolute = traits.Bool(argstr='--abs',
1208+
desc='If set it indicates that the warps in --warp should be interpreted as absolute, provided that it is not created by fnirt (which always uses relative warps). If set it also indicates that the output --out should be absolute.',
1209+
xor='relative')
1210+
relative = traits.Bool(argstr='--rel',
1211+
desc='If set it indicates that the warps in --warp should be interpreted as relative. I.e. the values in --warp are displacements from the coordinates in the --ref space. If set it also indicates that the output --out should be relative.',
1212+
xor='absolute')
1213+
niter = traits.Int(argstr='--niter=%d',
1214+
desc='Determines how many iterations of the gradient-descent search that should be run.')
1215+
regularise = traits.Float(argstr='--regularise=%f',
1216+
desc='Regularisation strength (deafult=1.0).')
1217+
noconstraint = traits.Bool(argstr='--noconstraint',
1218+
desc='Do not apply Jacobian constraint')
1219+
jacobian_min = traits.Float(argstr='--jmin=%f',
1220+
desc='Minimum acceptable Jacobian value for constraint (default 0.01)')
1221+
jacobian_max = traits.Float(argstr='--jmax=%f',
1222+
desc='Maximum acceptable Jacobian value for constraint (default 100.0)')
1223+
1224+
class InvWarpOutputSpec(TraitedSpec):
1225+
inverse_warp = File(exists=True, desc='Name of output file, containing warps that are the "reverse" of those in --warp.')
1226+
1227+
class InvWarp(FSLCommand):
1228+
"""Use FSL Invwarp to inverse a FNIRT warp
1229+
1230+
Examples
1231+
1232+
>>> TODO
1233+
"""
1234+
1235+
input_spec = InvWarpInputSpec
1236+
output_spec = InvWarpOutputSpec
1237+
1238+
1239+
_cmd = 'invwarp'
1240+
1241+
def _gen_filename(self, name):
1242+
if name == 'inverse_warp':
1243+
in_file1 = self.inputs.in_file1
1244+
return '%s_inv%s' % os.path.splitext(in_file1)
1245+
else:
1246+
raise NotImplementedError

0 commit comments

Comments
 (0)