Skip to content

Commit a60b790

Browse files
Merge pull request #1 from chrisfilo/jacobian_determinant
Jacobian determinant
2 parents d3eb515 + 5b68b5a commit a60b790

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

nipype/interfaces/ants/utils.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
from ...utils.filemanip import split_filename
1717
from nipype.interfaces.base import InputMultiPath
1818

19+
1920
class AverageAffineTransformInputSpec(ANTSCommandInputSpec):
2021
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False, mandatory=True, position=0, desc='image dimension (2 or 3)')
2122
output_affine_transform = File(argstr='%s', mandatory=True, position=1, desc='Outputfname.txt: the name of the resulting transform.')
22-
transforms = InputMultiPath(File(exists=True), argstr='%s', mandatory=True, position=3, desc=('transforms to average') )
23+
transforms = InputMultiPath(File(exists=True), argstr='%s', mandatory=True,
24+
position=3, desc=('transforms to average'))
25+
2326

2427
class AverageAffineTransformOutputSpec(TraitedSpec):
2528
affine_transform = File(exists=True, desc='average transform file')
2629

30+
2731
class AverageAffineTransform(ANTSCommand):
2832
"""
2933
Examples
@@ -45,20 +49,24 @@ def _format_arg(self, opt, spec, val):
4549

4650
def _list_outputs(self):
4751
outputs = self._outputs().get()
48-
outputs['affine_transform'] = os.path.abspath(self.inputs.output_affine_transform)
52+
outputs['affine_transform'] = os.path.abspath(
53+
self.inputs.output_affine_transform)
4954
return outputs
5055

5156

5257
class AverageImagesInputSpec(ANTSCommandInputSpec):
53-
dimension = traits.Enum(3, 2, argstr='%d', mandatory=True, position=0, desc='image dimension (2 or 3)')
58+
dimension = traits.Enum(3, 2, argstr='%d', mandatory=True,
59+
position=0, desc='image dimension (2 or 3)')
5460
output_average_image = File("average.nii", argstr='%s', position=1, desc='the name of the resulting image.', usedefault=True, hash_files=False)
5561
normalize = traits.Bool(argstr="%d", mandatory=True, position=2, desc='Normalize: if true, the 2nd image' +
5662
'is divided by its mean. This will select the largest image to average into.')
57-
images = InputMultiPath(File(exists=True), argstr='%s', mandatory=True, position=3, desc=('image to apply transformation to (generally a coregistered functional)') )
63+
images = InputMultiPath(File(exists=True), argstr='%s', mandatory=True, position=3, desc=('image to apply transformation to (generally a coregistered functional)'))
64+
5865

5966
class AverageImagesOutputSpec(TraitedSpec):
6067
output_average_image = File(exists=True, desc='average image file')
6168

69+
6270
class AverageImages(ANTSCommand):
6371
"""
6472
Examples
@@ -81,18 +89,23 @@ def _format_arg(self, opt, spec, val):
8189

8290
def _list_outputs(self):
8391
outputs = self._outputs().get()
84-
outputs['output_average_image'] = os.path.realpath(self.inputs.output_average_image)
92+
outputs['output_average_image'] = os.path.realpath(
93+
self.inputs.output_average_image)
8594
return outputs
8695

96+
8797
class MultiplyImagesInputSpec(ANTSCommandInputSpec):
8898
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False, mandatory=True, position=0, desc='image dimension (2 or 3)')
89-
first_input = File(argstr='%s', exists=True, mandatory=True, position=1, desc='image 1')
99+
first_input = File(
100+
argstr='%s', exists=True, mandatory=True, position=1, desc='image 1')
90101
second_input = traits.Either(File(exists=True), traits.Float, argstr='%s', mandatory=True, position=2, desc='image 2 or multiplication weight')
91102
output_product_image = File(argstr='%s', mandatory=True, position=3, desc='Outputfname.nii.gz: the name of the resulting image.')
92103

104+
93105
class MultiplyImagesOutputSpec(TraitedSpec):
94106
output_product_image = File(exists=True, desc='average image file')
95107

108+
96109
class MultiplyImages(ANTSCommand):
97110
"""
98111
Examples
@@ -115,34 +128,40 @@ def _format_arg(self, opt, spec, val):
115128

116129
def _list_outputs(self):
117130
outputs = self._outputs().get()
118-
outputs['output_product_image'] = os.path.abspath(self.inputs.output_product_image)
131+
outputs['output_product_image'] = os.path.abspath(
132+
self.inputs.output_product_image)
119133
return outputs
120134

121135

122136
class JacobianDeterminantInputSpec(ANTSCommandInputSpec):
123137
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False, mandatory=True, position=0, desc='image dimension (2 or 3)')
124-
warp_file = File(argstr='%s', exists=True, mandatory=True, position=1, desc='input warp file')
138+
warp_file = File(argstr='%s', exists=True, mandatory=True,
139+
position=1, desc='input warp file')
125140
output_prefix = File(argstr='%s', genfile=True, hash_files=False, position=2, desc='prefix of the output image filename: PREFIX(log)jacobian.nii.gz')
126-
use_log = traits.Enum(0, 1, argstr='%d', mandatory=False, position=3, desc='log transform the jacobian determinant')
127-
template_mask = File(argstr='%s', exists=True, mandatory=False, position=4, desc='template mask to adjust for head size')
141+
use_log = traits.Enum(0, 1, argstr='%d', mandatory=False, position=3,
142+
desc='log transform the jacobian determinant')
143+
template_mask = File(argstr='%s', exists=True, mandatory=False, position=4,
144+
desc='template mask to adjust for head size')
128145
norm_by_total = traits.Enum(0, 1, argstr='%d', mandatory=False, position=5, desc='normalize jacobian by total in mask to adjust for head size')
129146
projection_vector = traits.List(traits.Float(), argstr='%s', sep='x', mandatory=False, position=6, desc='vector to project warp against')
130147

148+
131149
class JacobianDeterminantOutputSpec(TraitedSpec):
132150
jacobian_image = File(exists=True, desc='(log transformed) jacobian image')
133151

152+
134153
class JacobianDeterminant(ANTSCommand):
135154
"""
136155
Examples
137156
--------
138157
>>> from nipype.interfaces.ants import JacobianDeterminant
139158
>>> jacobian = JacobianDeterminant()
140159
>>> jacobian.inputs.dimension = 3
141-
>>> jacobian.inputs.warp_file = 'Sub001_2Warp.nii'
160+
>>> jacobian.inputs.warp_file = 'ants_Warp.nii.gz'
142161
>>> jacobian.inputs.output_prefix = 'Sub001_'
143162
>>> jacobian.inputs.use_log = 1
144163
>>> jacobian.cmdline
145-
'ANTSJacobian 3 Sub001_2Warp.nii.gz Sub001_ 1'
164+
'ANTSJacobian 3 ants_Warp.nii.gz Sub001_ 1'
146165
"""
147166

148167
_cmd = 'ANTSJacobian'
@@ -161,7 +180,9 @@ def _gen_filename(self, name):
161180
def _list_outputs(self):
162181
outputs = self._outputs().get()
163182
if self.inputs.use_log == 1:
164-
outputs['jacobian_image'] = os.path.abspath(self._gen_filename('output_prefix') + 'logjacobian.nii.gz')
183+
outputs['jacobian_image'] = os.path.abspath(
184+
self._gen_filename('output_prefix') + 'logjacobian.nii.gz')
165185
else:
166-
outputs['jacobian_image'] = os.path.abspath(self._gen_filename('output_prefix') + 'jacobian.nii.gz')
186+
outputs['jacobian_image'] = os.path.abspath(
187+
self._gen_filename('output_prefix') + 'jacobian.nii.gz')
167188
return outputs

0 commit comments

Comments
 (0)