Skip to content

Commit 37c5296

Browse files
committed
PEP8 compliance for preproc (85%)
1 parent e643da4 commit 37c5296

File tree

1 file changed

+93
-66
lines changed

1 file changed

+93
-66
lines changed

nipype/interfaces/spm/preprocess.py

Lines changed: 93 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ def _parse_inputs(self):
353353
"""validate spm coregister options if set to None ignore
354354
"""
355355
if self.inputs.jobtype == "write":
356-
einputs = super(Coregister, self)._parse_inputs(skip=('jobtype', 'apply_to_files'))
356+
einputs = (super(Coregister, self)
357+
._parse_inputs(skip=('jobtype', 'apply_to_files')))
357358
else:
358359
einputs = super(Coregister, self)._parse_inputs(skip=('jobtype'))
359360
jobtype = self.inputs.jobtype
@@ -371,11 +372,14 @@ def _list_outputs(self):
371372
if isdefined(self.inputs.apply_to_files):
372373
outputs['coregistered_files'] = []
373374
for imgf in filename_to_list(self.inputs.apply_to_files):
374-
outputs['coregistered_files'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix))
375+
(outputs['coregistered_files']
376+
.append(fname_presuffix(imgf,
377+
prefix=self.inputs.out_prefix)))
375378

376379
outputs['coregistered_source'] = []
377380
for imgf in filename_to_list(self.inputs.source):
378-
outputs['coregistered_source'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix))
381+
(outputs['coregistered_source']
382+
.append(fname_presuffix(imgf, prefix=self.inputs.out_prefix)))
379383

380384
return outputs
381385

@@ -391,11 +395,11 @@ class NormalizeInputSpec(SPMCommandInputSpec):
391395
mandatory=True, copyfile=True)
392396
jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True,
393397
desc='Estimate, Write or do both')
394-
apply_to_files = InputMultiPath(traits.Either(File(exists=True),
395-
traits.List(File(exists=True))),
396-
field='subj.resample',
397-
desc='files to apply transformation to',
398-
copyfile=True)
398+
apply_to_files = InputMultiPath(
399+
traits.Either(File(exists=True), traits.List(File(exists=True))),
400+
field='subj.resample',
401+
desc='files to apply transformation to',
402+
copyfile=True)
399403
parameter_file = File(field='subj.matname', mandatory=True,
400404
xor=['source', 'template'],
401405
desc='normalization parameter file*_sn.mat',
@@ -502,7 +506,8 @@ def _parse_inputs(self):
502506
if jobtype in ['estwrite', 'write']:
503507
if not isdefined(self.inputs.apply_to_files):
504508
if isdefined(self.inputs.source):
505-
einputs[0]['subj']['resample'] = scans_for_fname(self.inputs.source)
509+
einputs[0]['subj']['resample'] = scans_for_fname(
510+
self.inputs.source)
506511
return [{'%s' % (jobtype): einputs[0]}]
507512

508513
def _list_outputs(self):
@@ -512,10 +517,10 @@ def _list_outputs(self):
512517
if jobtype.startswith('est'):
513518
outputs['normalization_parameters'] = []
514519
for imgf in filename_to_list(self.inputs.source):
515-
outputs['normalization_parameters'].append(fname_presuffix(imgf,
516-
suffix='_sn.mat',
517-
use_ext=False))
518-
outputs['normalization_parameters'] = list_to_filename(outputs['normalization_parameters'])
520+
outputs['normalization_parameters'].append(
521+
fname_presuffix(imgf, suffix='_sn.mat', use_ext=False))
522+
outputs['normalization_parameters'] = list_to_filename(
523+
outputs['normalization_parameters'])
519524

520525
if self.inputs.jobtype == "estimate":
521526
if isdefined(self.inputs.apply_to_files):
@@ -540,8 +545,8 @@ def _list_outputs(self):
540545
if isdefined(self.inputs.source):
541546
outputs['normalized_source'] = []
542547
for imgf in filename_to_list(self.inputs.source):
543-
outputs['normalized_source'].append(fname_presuffix(imgf,
544-
prefix=prefixNorm))
548+
outputs['normalized_source'].append(
549+
fname_presuffix(imgf, prefix=prefixNorm))
545550

546551
return outputs
547552

@@ -552,11 +557,11 @@ class Normalize12InputSpec(SPMCommandInputSpec):
552557
'with'),
553558
xor=['deformation_file'],
554559
mandatory=True, copyfile=True)
555-
apply_to_files = InputMultiPath(traits.Either(File(exists=True),
556-
traits.List(File(exists=True))),
557-
field='subj.resample',
558-
desc='files to apply transformation to',
559-
copyfile=True)
560+
apply_to_files = InputMultiPath(
561+
traits.Either(File(exists=True), traits.List(File(exists=True))),
562+
field='subj.resample',
563+
desc='files to apply transformation to',
564+
copyfile=True)
560565
deformation_file = File(field='subj.def', mandatory=True,
561566
xor=['image_to_align', 'tpm'],
562567
desc=('file y_*.nii containing 3 deformation '
@@ -661,8 +666,8 @@ def _format_arg(self, opt, spec, val):
661666
def _parse_inputs(self, skip=()):
662667
"""validate spm normalize options if set to None ignore
663668
"""
664-
einputs = super(Normalize12, self)._parse_inputs(skip=('jobtype',
665-
'apply_to_files'))
669+
einputs = super(Normalize12, self)._parse_inputs(
670+
skip=('jobtype', 'apply_to_files'))
666671
if isdefined(self.inputs.apply_to_files):
667672
inputfiles = deepcopy(self.inputs.apply_to_files)
668673
if isdefined(self.inputs.image_to_align):
@@ -672,7 +677,8 @@ def _parse_inputs(self, skip=()):
672677
if jobtype in ['estwrite', 'write']:
673678
if not isdefined(self.inputs.apply_to_files):
674679
if isdefined(self.inputs.image_to_align):
675-
einputs[0]['subj']['resample'] = scans_for_fname(self.inputs.image_to_align)
680+
einputs[0]['subj']['resample'] = scans_for_fname(
681+
self.inputs.image_to_align)
676682
return [{'%s' % (jobtype): einputs[0]}]
677683

678684
def _list_outputs(self):
@@ -682,15 +688,16 @@ def _list_outputs(self):
682688
if jobtype.startswith('est'):
683689
outputs['deformation_field'] = []
684690
for imgf in filename_to_list(self.inputs.image_to_align):
685-
outputs['deformation_field'].append(fname_presuffix(imgf,
686-
prefix='y_'))
687-
outputs['deformation_field'] = list_to_filename(outputs['deformation_field'])
691+
outputs['deformation_field'].append(
692+
fname_presuffix(imgf, prefix='y_'))
693+
outputs['deformation_field'] = list_to_filename(
694+
outputs['deformation_field'])
688695

689696
if self.inputs.jobtype == "estimate":
690697
if isdefined(self.inputs.apply_to_files):
691698
outputs['normalized_files'] = self.inputs.apply_to_files
692-
outputs['normalized_image'] = fname_presuffix(self.inputs.image_to_align,
693-
prefix='w')
699+
outputs['normalized_image'] = fname_presuffix(
700+
self.inputs.image_to_align, prefix='w')
694701
elif 'write' in self.inputs.jobtype:
695702
outputs['normalized_files'] = []
696703
if isdefined(self.inputs.apply_to_files):
@@ -702,8 +709,8 @@ def _list_outputs(self):
702709
run = [fname_presuffix(f, prefix='w')]
703710
outputs['normalized_files'].extend(run)
704711
if isdefined(self.inputs.image_to_align):
705-
outputs['normalized_image'] = fname_presuffix(self.inputs.image_to_align,
706-
prefix='w')
712+
outputs['normalized_image'] = fname_presuffix(
713+
self.inputs.image_to_align, prefix='w')
707714

708715
return outputs
709716

@@ -745,7 +752,8 @@ class SegmentInputSpec(SPMCommandInputSpec):
745752
Native + Modulated + Unmodulated: [True,True,True],
746753
Modulated + Unmodulated Normalised: [True,True,False]""")
747754
save_bias_corrected = traits.Bool(field='output.biascor',
748-
desc='True/False produce a bias corrected image')
755+
desc=('True/False produce a bias '
756+
'corrected image'))
749757
clean_masks = traits.Enum('no', 'light', 'thorough',
750758
field='output.cleanup',
751759
desc=("clean using estimated brain mask "
@@ -861,9 +869,8 @@ def _list_outputs(self):
861869
('native', '')]):
862870
if getattr(self.inputs, outtype)[idx]:
863871
outfield = '%s_%s_image' % (image, tissue)
864-
outputs[outfield] = fname_presuffix(f,
865-
prefix='%sc%d' % (prefix,
866-
tidx + 1))
872+
outputs[outfield] = fname_presuffix(
873+
f, prefix='%sc%d' % (prefix, tidx + 1))
867874
if isdefined(self.inputs.save_bias_corrected) and \
868875
self.inputs.save_bias_corrected:
869876
outputs['bias_corrected_image'] = fname_presuffix(f, prefix='m')
@@ -877,22 +884,25 @@ def _list_outputs(self):
877884
class NewSegmentInputSpec(SPMCommandInputSpec):
878885
channel_files = InputMultiPath(File(exists=True),
879886
desc="A list of files to be segmented",
880-
field='channel', copyfile=False, mandatory=True)
887+
field='channel', copyfile=False,
888+
mandatory=True)
881889
channel_info = traits.Tuple(traits.Float(), traits.Float(),
882890
traits.Tuple(traits.Bool, traits.Bool),
883891
desc="""A tuple with the following fields:
884892
- bias reguralisation (0-10)
885893
- FWHM of Gaussian smoothness of bias
886894
- which maps to save (Corrected, Field) - a tuple of two boolean values""",
887895
field='channel')
888-
tissues = traits.List(traits.Tuple(traits.Tuple(File(exists=True), traits.Int()), traits.Int(),
889-
traits.Tuple(traits.Bool, traits.Bool), traits.Tuple(traits.Bool, traits.Bool)),
890-
desc="""A list of tuples (one per tissue) with the following fields:
896+
tissues = traits.List(
897+
traits.Tuple(traits.Tuple(File(exists=True), traits.Int()),
898+
traits.Int(), traits.Tuple(traits.Bool, traits.Bool),
899+
traits.Tuple(traits.Bool, traits.Bool)),
900+
desc="""A list of tuples (one per tissue) with the following fields:
891901
- tissue probability map (4D), 1-based index to frame
892902
- number of gaussians
893903
- which maps to save [Native, DARTEL] - a tuple of two boolean values
894904
- which maps to save [Unmodulated, Modulated] - a tuple of two boolean values""",
895-
field='tissue')
905+
field='tissue')
896906
affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none',
897907
field='warp.affreg',
898908
desc='mni, eastern, subj, none ')
@@ -978,7 +988,7 @@ def _format_arg(self, opt, spec, val):
978988
"""
979989

980990
if opt in ['channel_files', 'channel_info']:
981-
# structure have to be recreated, because of some weird traits error
991+
# structure have to be recreated because of some weird traits error
982992
new_channel = {}
983993
new_channel['vols'] = scans_for_fnames(self.inputs.channel_files)
984994
if isdefined(self.inputs.channel_info):
@@ -1032,29 +1042,39 @@ def _list_outputs(self):
10321042
if isdefined(self.inputs.tissues):
10331043
for i, tissue in enumerate(self.inputs.tissues):
10341044
if tissue[2][0]:
1035-
outputs['native_class_images'][i].append(os.path.join(pth, "c%d%s.nii" % (i + 1, base)))
1045+
outputs['native_class_images'][i].append(
1046+
os.path.join(pth, "c%d%s.nii" % (i + 1, base)))
10361047
if tissue[2][1]:
1037-
outputs['dartel_input_images'][i].append(os.path.join(pth, "rc%d%s.nii" % (i + 1, base)))
1048+
outputs['dartel_input_images'][i].append(
1049+
os.path.join(pth, "rc%d%s.nii" % (i + 1, base)))
10381050
if tissue[3][0]:
1039-
outputs['normalized_class_images'][i].append(os.path.join(pth, "wc%d%s.nii" % (i + 1, base)))
1051+
outputs['normalized_class_images'][i].append(
1052+
os.path.join(pth, "wc%d%s.nii" % (i + 1, base)))
10401053
if tissue[3][1]:
1041-
outputs['modulated_class_images'][i].append(os.path.join(pth, "mwc%d%s.nii" % (i + 1, base)))
1054+
outputs['modulated_class_images'][i].append(
1055+
os.path.join(pth, "mwc%d%s.nii" % (i + 1, base)))
10421056
else:
10431057
for i in range(n_classes):
1044-
outputs['native_class_images'][i].append(os.path.join(pth, "c%d%s.nii" % (i + 1, base)))
1045-
outputs['transformation_mat'].append(os.path.join(pth, "%s_seg8.mat" % base))
1058+
outputs['native_class_images'][i].append(
1059+
os.path.join(pth, "c%d%s.nii" % (i + 1, base)))
1060+
outputs['transformation_mat'].append(
1061+
os.path.join(pth, "%s_seg8.mat" % base))
10461062

10471063
if isdefined(self.inputs.write_deformation_fields):
10481064
if self.inputs.write_deformation_fields[0]:
1049-
outputs['inverse_deformation_field'].append(os.path.join(pth, "iy_%s.nii" % base))
1065+
outputs['inverse_deformation_field'].append(
1066+
os.path.join(pth, "iy_%s.nii" % base))
10501067
if self.inputs.write_deformation_fields[1]:
1051-
outputs['forward_deformation_field'].append(os.path.join(pth, "y_%s.nii" % base))
1068+
outputs['forward_deformation_field'].append(
1069+
os.path.join(pth, "y_%s.nii" % base))
10521070

10531071
if isdefined(self.inputs.channel_info):
10541072
if self.inputs.channel_info[2][0]:
1055-
outputs['bias_corrected_images'].append(os.path.join(pth, "m%s.nii" % (base)))
1073+
outputs['bias_corrected_images'].append(
1074+
os.path.join(pth, "m%s.nii" % (base)))
10561075
if self.inputs.channel_info[2][1]:
1057-
outputs['bias_field_images'].append(os.path.join(pth, "BiasField_%s.nii" % (base)))
1076+
outputs['bias_field_images'].append(
1077+
os.path.join(pth, "BiasField_%s.nii" % (base)))
10581078
return outputs
10591079

10601080

@@ -1131,7 +1151,8 @@ class DARTELInputSpec(SPMCommandInputSpec):
11311151
desc='Prefix for template')
11321152
regularization_form = traits.Enum('Linear', 'Membrane', 'Bending',
11331153
field='warp.settings.rform',
1134-
desc='Form of regularization energy term')
1154+
desc=('Form of regularization energy '
1155+
'term'))
11351156
iteration_parameters = traits.List(traits.Tuple(traits.Range(1, 10),
11361157
traits.Tuple(traits.Float,
11371158
traits.Float,
@@ -1220,14 +1241,18 @@ def _list_outputs(self):
12201241
outputs = self._outputs().get()
12211242
outputs['template_files'] = []
12221243
for i in range(6):
1223-
outputs['template_files'].append(os.path.realpath('%s_%d.nii' % (self.inputs.template_prefix, i + 1)))
1224-
outputs['final_template_file'] = os.path.realpath('%s_6.nii' % self.inputs.template_prefix)
1244+
outputs['template_files'].append(
1245+
os.path.realpath(
1246+
'%s_%d.nii' % (self.inputs.template_prefix, i + 1)))
1247+
outputs['final_template_file'] = os.path.realpath(
1248+
'%s_6.nii' % self.inputs.template_prefix)
12251249
outputs['dartel_flow_fields'] = []
12261250
for filename in self.inputs.image_files[0]:
12271251
pth, base, ext = split_filename(filename)
1228-
outputs['dartel_flow_fields'].append(os.path.realpath('u_%s_%s%s' % (base,
1229-
self.inputs.template_prefix,
1230-
ext)))
1252+
outputs['dartel_flow_fields'].append(
1253+
os.path.realpath('u_%s_%s%s' % (base,
1254+
self.inputs.template_prefix,
1255+
ext)))
12311256
return outputs
12321257

12331258

@@ -1313,7 +1338,8 @@ def _format_arg(self, opt, spec, val):
13131338
def _list_outputs(self):
13141339
outputs = self._outputs().get()
13151340
pth, base, ext = split_filename(self.inputs.template_file)
1316-
outputs['normalization_parameter_file'] = os.path.realpath(base + '_2mni.mat')
1341+
outputs['normalization_parameter_file'] = os.path.realpath(
1342+
base + '_2mni.mat')
13171343
outputs['normalized_files'] = []
13181344
prefix = "w"
13191345
if isdefined(self.inputs.modulate) and self.inputs.modulate:
@@ -1322,9 +1348,8 @@ def _list_outputs(self):
13221348
prefix = 's' + prefix
13231349
for filename in self.inputs.apply_to_files:
13241350
pth, base, ext = split_filename(filename)
1325-
outputs['normalized_files'].append(os.path.realpath('%s%s%s' % (prefix,
1326-
base,
1327-
ext)))
1351+
outputs['normalized_files'].append(
1352+
os.path.realpath('%s%s%s' % (prefix, base, ext)))
13281353

13291354
return outputs
13301355

@@ -1391,11 +1416,11 @@ def _list_outputs(self):
13911416
for filename in self.inputs.image_files:
13921417
pth, base, ext = split_filename(filename)
13931418
if isdefined(self.inputs.modulate) and self.inputs.modulate:
1394-
outputs['warped_files'].append(os.path.realpath('mw%s%s' % (base,
1395-
ext)))
1419+
outputs['warped_files'].append(
1420+
os.path.realpath('mw%s%s' % (base, ext)))
13961421
else:
1397-
outputs['warped_files'].append(os.path.realpath('w%s%s' % (base,
1398-
ext)))
1422+
outputs['warped_files'].append(
1423+
os.path.realpath('w%s%s' % (base, ext)))
13991424
return outputs
14001425

14011426

@@ -1706,7 +1731,8 @@ def _format_arg(self, opt, spec, val):
17061731
elif opt in ['dartel_template']:
17071732
return np.array([val], dtype=object)
17081733
elif opt in ['deformation_field']:
1709-
return super(VBMSegment, self)._format_arg(opt, spec, [int(val[0]), int(val[1])])
1734+
return super(VBMSegment, self)._format_arg(
1735+
opt, spec, [int(val[0]), int(val[1])])
17101736
else:
17111737
return super(VBMSegment, self)._format_arg(opt, spec, val)
17121738

@@ -1717,4 +1743,5 @@ def _parse_inputs(self):
17171743
einputs[0]['estwrite']['extopts']['dartelwarp'] = {'normlow': 1}
17181744
return einputs
17191745
else:
1720-
return super(VBMSegment, self)._parse_inputs(skip=('spatial_normalization'))
1746+
return super(VBMSegment, self)._parse_inputs(
1747+
skip=('spatial_normalization'))

0 commit comments

Comments
 (0)