Skip to content

Commit 674e9b0

Browse files
author
Fabio Bernardoni
committed
run black on the preprocess.py file to improve formatting
1 parent a57cdc2 commit 674e9b0

File tree

1 file changed

+99
-61
lines changed

1 file changed

+99
-61
lines changed

nipype/interfaces/spm/preprocess.py

Lines changed: 99 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ class FieldMapInputSpec(SPMCommandInputSpec):
4646
desc="one of: calculatevdm, applyvdm",
4747
)
4848
phase_file = File(
49-
#mandatory=True,
49+
# mandatory=True,
5050
exists=True,
5151
copyfile=False,
5252
field="subj.data.presubphasemag.phase",
5353
desc="presubstracted phase file",
5454
)
5555
magnitude_file = File(
56-
#mandatory=True,
56+
# mandatory=True,
5757
exists=True,
5858
copyfile=False,
5959
field="subj.data.presubphasemag.magnitude",
@@ -62,7 +62,7 @@ class FieldMapInputSpec(SPMCommandInputSpec):
6262
echo_times = traits.Tuple(
6363
traits.Float,
6464
traits.Float,
65-
#mandatory=True,
65+
# mandatory=True,
6666
field="subj.defaults.defaultsval.et",
6767
desc="short and long echo times",
6868
)
@@ -169,7 +169,7 @@ class FieldMapInputSpec(SPMCommandInputSpec):
169169
epi_file = File(
170170
copyfile=False,
171171
exists=True,
172-
#mandatory=True,
172+
# mandatory=True,
173173
field="subj.session.epi",
174174
desc="EPI to unwarp",
175175
)
@@ -196,59 +196,78 @@ class FieldMapInputSpec(SPMCommandInputSpec):
196196
)
197197

198198
in_files = InputMultiObject(
199-
traits.Either(ImageFileSPM(exists=True),
200-
traits.List(ImageFileSPM(exists=True))),
201-
field='data.scans',mandatory=True,
199+
traits.Either(
200+
ImageFileSPM(exists=True), traits.List(ImageFileSPM(exists=True))
201+
),
202+
field="data.scans",
203+
mandatory=True,
202204
copyfile=True,
203-
desc='list of filenames to apply the vdm to')
205+
desc="list of filenames to apply the vdm to",
206+
)
204207
vdmfile = File(
205-
field='data.vdmfile',
206-
desc='Voxel displacement map to use',mandatory=True,
207-
copyfile=True)
208+
field="data.vdmfile",
209+
desc="Voxel displacement map to use",
210+
mandatory=True,
211+
copyfile=True,
212+
)
208213
distortion_direction = traits.Int(
209-
2, field='roptions.pedir', desc='phase encode direction input data have been acquired with',
210-
usedefault=True)
214+
2,
215+
field="roptions.pedir",
216+
desc="phase encode direction input data have been acquired with",
217+
usedefault=True,
218+
)
211219
write_which = traits.ListInt(
212220
[2, 1],
213-
field='roptions.which',
221+
field="roptions.which",
214222
minlen=2,
215223
maxlen=2,
216224
usedefault=True,
217-
desc='determines which images to apply vdm to')
225+
desc="determines which images to apply vdm to",
226+
)
218227
interpolation = traits.Int(
219-
4, field='roptions.rinterp', desc='phase encode direction input data have been acquired with',
220-
usedefault=True)
228+
4,
229+
field="roptions.rinterp",
230+
desc="phase encode direction input data have been acquired with",
231+
usedefault=True,
232+
)
221233
reslice_interp = traits.Range(
222234
low=0,
223235
high=7,
224-
field='roptions.rinterp',
225-
desc='degree of b-spline used for interpolation')
236+
field="roptions.rinterp",
237+
desc="degree of b-spline used for interpolation",
238+
)
226239
write_wrap = traits.List(
227240
traits.Int(),
228241
minlen=3,
229242
maxlen=3,
230-
field='roptions.wrap',
231-
desc=('Check if interpolation should wrap in [x,y,z]'))
243+
field="roptions.wrap",
244+
desc=("Check if interpolation should wrap in [x,y,z]"),
245+
)
232246
write_mask = traits.Bool(
233-
field='roptions.mask', desc='True/False mask time series images')
247+
field="roptions.mask", desc="True/False mask time series images"
248+
)
234249
out_prefix = traits.String(
235-
'u',
236-
field='roptions.prefix',
250+
"u",
251+
field="roptions.prefix",
237252
usedefault=True,
238-
desc='fieldmap corrected output prefix')
253+
desc="fieldmap corrected output prefix",
254+
)
239255

240256

241257
class FieldMapOutputSpec(TraitedSpec):
242258
vdm = File(exists=True, desc="voxel difference map")
243259

244260
out_files = OutputMultiPath(
245261
traits.Either(traits.List(File(exists=True)), File(exists=True)),
246-
desc=('If jobtype is applyvdm, '
247-
'these will be the fieldmap corrected files.'
248-
' Otherwise, they will be copies '
249-
'of in_files that have had their '
250-
'headers rewritten.'))
251-
mean_image = File(exists=True, desc='Mean image')
262+
desc=(
263+
"If jobtype is applyvdm, "
264+
"these will be the fieldmap corrected files."
265+
" Otherwise, they will be copies "
266+
"of in_files that have had their "
267+
"headers rewritten."
268+
),
269+
)
270+
mean_image = File(exists=True, desc="Mean image")
252271

253272

254273
class FieldMap(SPMCommand):
@@ -283,75 +302,94 @@ class FieldMap(SPMCommand):
283302
def _format_arg(self, opt, spec, val):
284303
"""Convert input to appropriate format for spm"""
285304

286-
if ((self.inputs.jobtype == "calculatevdm") and (opt in ['phase_file', 'magnitude_file', 'anat_file', 'epi_file'])):
305+
if (self.inputs.jobtype == "calculatevdm") and (
306+
opt in ["phase_file", "magnitude_file", "anat_file", "epi_file"]
307+
):
287308
return scans_for_fname(ensure_list(val))
288309

289-
if ((self.inputs.jobtype == "applyvdm") and (opt =='in_files')):
310+
if (self.inputs.jobtype == "applyvdm") and (opt == "in_files"):
290311
return scans_for_fnames(ensure_list(val))
291-
if ((self.inputs.jobtype == "applyvdm") and (opt =='vdmfile')):
312+
if (self.inputs.jobtype == "applyvdm") and (opt == "vdmfile"):
292313
return scans_for_fname(ensure_list(val))
293314
return super(FieldMap, self)._format_arg(opt, spec, val)
294315

295-
296316
def _parse_inputs(self):
297317
"""validate spm fieldmap options if set to None ignore"""
298318

299319
if self.inputs.jobtype == "applyvdm":
300-
einputs = (super(FieldMap, self)
301-
._parse_inputs(skip=('jobtype','phase_file', 'magnitude_file',
302-
'echo_times', 'blip_direction',
303-
'total_readout_time','maskbrain',
304-
'epifm','jacobian_modulation',
305-
'method','unwarp_fwhm','pad','ws',
306-
'template','mask_fwhm','nerode','ndilate',
307-
'thresh','reg','epi_file','matchvdm',
308-
'sessname','writeunwarped',
309-
'anat_file','matchanat')))
320+
einputs = super(FieldMap, self)._parse_inputs(
321+
skip=(
322+
"jobtype",
323+
"phase_file",
324+
"magnitude_file",
325+
"echo_times",
326+
"blip_direction",
327+
"total_readout_time",
328+
"maskbrain",
329+
"epifm",
330+
"jacobian_modulation",
331+
"method",
332+
"unwarp_fwhm",
333+
"pad",
334+
"ws",
335+
"template",
336+
"mask_fwhm",
337+
"nerode",
338+
"ndilate",
339+
"thresh",
340+
"reg",
341+
"epi_file",
342+
"matchvdm",
343+
"sessname",
344+
"writeunwarped",
345+
"anat_file",
346+
"matchanat",
347+
)
348+
)
310349

311350
else:
312-
einputs = (super(FieldMap, self)
313-
._parse_inputs(skip=('jobtype','in_files', 'vdmfile')))
351+
einputs = super(FieldMap, self)._parse_inputs(
352+
skip=("jobtype", "in_files", "vdmfile")
353+
)
314354
jobtype = self.inputs.jobtype
315355

316-
return [{'%s' % (jobtype): einputs[0]}]
317-
356+
return [{"%s" % (jobtype): einputs[0]}]
318357

319358
def _list_outputs(self):
320359
outputs = self._outputs().get()
321360
jobtype = self.inputs.jobtype
322-
resliced_all = self.inputs.write_which[0] > 0
361+
resliced_all = self.inputs.write_which[0] > 0
323362
resliced_mean = self.inputs.write_which[1] > 0
324363
if jobtype == "calculatevdm":
325-
outputs['vdm'] = fname_presuffix(self.inputs.phase_file, prefix='vdm5_sc')
364+
outputs["vdm"] = fname_presuffix(self.inputs.phase_file, prefix="vdm5_sc")
326365
elif jobtype == "applyvdm":
327366
if resliced_mean:
328367
if isinstance(self.inputs.in_files[0], list):
329368
first_image = self.inputs.in_files[0][0]
330369
else:
331370
first_image = self.inputs.in_files[0]
332-
outputs['mean_image'] = fname_presuffix(
333-
first_image, prefix='meanu')
371+
outputs["mean_image"] = fname_presuffix(first_image, prefix="meanu")
334372

335373
if resliced_all:
336-
outputs['out_files'] = []
374+
outputs["out_files"] = []
337375
for idx, imgf in enumerate(ensure_list(self.inputs.in_files)):
338376
appliedvdm_run = []
339377
if isinstance(imgf, list):
340378
for i, inner_imgf in enumerate(ensure_list(imgf)):
341-
newfile = fname_presuffix(inner_imgf,
342-
prefix=self.inputs.out_prefix)
379+
newfile = fname_presuffix(
380+
inner_imgf, prefix=self.inputs.out_prefix
381+
)
343382
appliedvdm_run.append(newfile)
344383
else:
345-
appliedvdm_run = fname_presuffix(imgf,
346-
prefix=self.inputs.out_prefix)
347-
outputs['out_files'].append(appliedvdm_run)
384+
appliedvdm_run = fname_presuffix(
385+
imgf, prefix=self.inputs.out_prefix
386+
)
387+
outputs["out_files"].append(appliedvdm_run)
348388
return outputs
349389

350-
351390
return outputs
352391

353392

354-
355393
class SliceTimingInputSpec(SPMCommandInputSpec):
356394
in_files = InputMultiPath(
357395
traits.Either(

0 commit comments

Comments
 (0)