Skip to content

Commit 22ef063

Browse files
committed
fix: spm_realign code to handle 3d files without registering to mean
1 parent b38ddc0 commit 22ef063

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

nipype/interfaces/spm/preprocess.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class RealignInputSpec(SPMCommandInputSpec):
120120
desc='gaussian smoothing kernel width')
121121
separation = traits.Range(low=0.0, field='eoptions.sep',
122122
desc='sampling separation in mm')
123-
register_to_mean = traits.Bool(field='eoptions.rtm',
123+
register_to_mean = traits.Bool(True, field='eoptions.rtm',
124+
mandatory=True, usedefault=True,
124125
desc='Indicate whether realignment is done to the mean image')
125126
weight_img = File(exists=True, field='eoptions.weight',
126127
desc='filename of weighting image')
@@ -213,14 +214,26 @@ def _list_outputs(self):
213214
outputs['mean_image'] = fname_presuffix(first_image, prefix='mean')
214215

215216
if resliced_all:
217+
reg_to_mean = self.inputs.register_to_mean
216218
outputs['realigned_files'] = []
217-
for imgf in filename_to_list(self.inputs.in_files):
219+
for idx, imgf in enumerate(filename_to_list(self.inputs.in_files)):
218220
realigned_run = []
219-
if isinstance(imgf,list):
220-
for inner_imgf in filename_to_list(imgf):
221-
realigned_run.append(fname_presuffix(inner_imgf, prefix=self.inputs.out_prefix))
221+
if isinstance(imgf, list):
222+
for i, inner_imgf in enumerate(filename_to_list(imgf)):
223+
newfile = fname_presuffix(inner_imgf,
224+
prefix=self.inputs.out_prefix)
225+
if os.path.exists(newfile):
226+
realigned_run.append(newfile)
227+
continue
228+
if idx==0 and i == 0 and not reg_to_mean and \
229+
func_is_3d(inner_imgf):
230+
realigned_run.append(fname_presuffix(inner_imgf,
231+
prefix=''))
222232
else:
223-
realigned_run = fname_presuffix(imgf, prefix=self.inputs.out_prefix)
233+
realigned_run = fname_presuffix(imgf,
234+
prefix=self.inputs.out_prefix)
235+
if idx==0 and not reg_to_mean and func_is_3d(imgf):
236+
realigned_run = fname_presuffix(imgf, prefix='')
224237
outputs['realigned_files'].append(realigned_run)
225238
return outputs
226239

0 commit comments

Comments
 (0)