Skip to content

Commit 71e2140

Browse files
committed
fix+enh: now supply custom flags + write_residuals
1 parent f92a333 commit 71e2140

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

nipype/interfaces/spm/model.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,27 @@ def _list_outputs(self):
179179

180180
class EstimateModelInputSpec(SPMCommandInputSpec):
181181
spm_mat_file = File(exists=True, field='spmmat',
182-
desc='absolute path to SPM.mat',
183-
copyfile=True,
184-
mandatory=True)
185-
estimation_method = traits.Dict(traits.Enum('Classical', 'Bayesian2',
186-
'Bayesian'),
187-
field='method',
188-
desc=('Classical, Bayesian2, '
189-
'Bayesian (dict)'),
190-
mandatory=True)
191-
flags = traits.Str(desc='optional arguments (opt)')
182+
copyfile=True, mandatory=True,
183+
desc='Absolute path to SPM.mat')
184+
estimation_method = traits.Dict(
185+
traits.Enum('Classical', 'Bayesian2', 'Bayesian'),
186+
field='method', mandatory=True,
187+
desc=('Dictionary of either Classical: 1, Bayesian: 1, '
188+
'or Bayesian2: 1 (dict)'))
189+
write_residuals = traits.Bool(field='write_residuals',
190+
desc="Write individual residual images")
191+
flags = traits.Dict(desc='Additional arguments')
192192

193193

194194
class EstimateModelOutputSpec(TraitedSpec):
195195
mask_image = File(exists=True,
196-
desc='binary mask to constrain estimation')
196+
desc='binary mask to constrain estimation')
197197
beta_images = OutputMultiPath(File(exists=True),
198-
desc='design parameter estimates')
198+
desc='design parameter estimates')
199199
residual_image = File(exists=True,
200-
desc='Mean-squared image of the residuals')
200+
desc='Mean-squared image of the residuals')
201+
residual_images = OutputMultiPath(File(exists=True),
202+
desc="individual residual images (requires `write_residuals`")
201203
RPVimage = File(exists=True, desc='Resels per voxel image')
202204
spm_mat_file = File(exists=True, desc='Updated SPM mat file')
203205

@@ -225,7 +227,7 @@ def _format_arg(self, opt, spec, val):
225227
return np.array([str(val)], dtype=object)
226228
if opt == 'estimation_method':
227229
if isinstance(val, (str, bytes)):
228-
return {'%s' % val: 1}
230+
return {'{}'.format(val): 1}
229231
else:
230232
return val
231233
return super(EstimateModel, self)._format_arg(opt, spec, val)
@@ -235,7 +237,8 @@ def _parse_inputs(self):
235237
"""
236238
einputs = super(EstimateModel, self)._parse_inputs(skip=('flags'))
237239
if isdefined(self.inputs.flags):
238-
einputs[0].update(self.inputs.flags)
240+
einputs[0].update({flag: val for (flag, val) in
241+
self.inputs.flags.items()})
239242
return einputs
240243

241244
def _list_outputs(self):
@@ -262,6 +265,9 @@ def _list_outputs(self):
262265
rpv = os.path.join(pth, 'RPV.nii')
263266
else:
264267
rpv = os.path.join(pth, 'RPV.img')
268+
if self.inputs.write_residuals:
269+
outres = [x for x in glob(os.path.join(pth, 'Res_*'))]
270+
outputs['residual_images'] = outres
265271
outputs['RPVimage'] = rpv
266272
spm = os.path.join(pth, 'SPM.mat')
267273
outputs['spm_mat_file'] = spm

nipype/interfaces/spm/tests/test_auto_EstimateModel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def test_EstimateModel_inputs():
2323
use_v8struct=dict(min_ver='8',
2424
usedefault=True,
2525
),
26+
write_residuals=dict(field='write_residuals',
27+
),
2628
)
2729
inputs = EstimateModel.input_spec()
2830

@@ -36,6 +38,7 @@ def test_EstimateModel_outputs():
3638
beta_images=dict(),
3739
mask_image=dict(),
3840
residual_image=dict(),
41+
residual_images=dict(),
3942
spm_mat_file=dict(),
4043
)
4144
outputs = EstimateModel.output_spec()

0 commit comments

Comments
 (0)