From 1adac29834a29a47765d97b3ae34a91fa99764a1 Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 16:29:41 -0400 Subject: [PATCH 01/15] test commit for build --- nipype/interfaces/spm/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/base.py b/nipype/interfaces/spm/base.py index 0ca470d0ed..d264492499 100644 --- a/nipype/interfaces/spm/base.py +++ b/nipype/interfaces/spm/base.py @@ -476,7 +476,8 @@ def _make_matlab_command(self, contents, postscript=None): end\n """ if self.mlab.inputs.mfile: - if isdefined(self.inputs.use_v8struct) and self.inputs.use_v8struct: + if (isdefined(self.inputs.use_v8struct) and + self.inputs.use_v8struct): mscript += self._generate_job('jobs{1}.spm.%s.%s' % (self.jobtype, self.jobname), contents[0]) From 78e29502cb38c50dd05b4053e1077841abb5543f Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 16:44:57 -0400 Subject: [PATCH 02/15] PEP8 compliance for base.py --- nipype/interfaces/spm/base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/spm/base.py b/nipype/interfaces/spm/base.py index d264492499..6a066288c3 100644 --- a/nipype/interfaces/spm/base.py +++ b/nipype/interfaces/spm/base.py @@ -14,13 +14,10 @@ spm.SPMCommand().version """ +# Standard library imports from __future__ import print_function from builtins import range from builtins import object - -__docformat__ = 'restructuredtext' - -# Standard library imports import os from copy import deepcopy @@ -38,6 +35,8 @@ from ... import logging logger = logging.getLogger('interface') +__docformat__ = 'restructuredtext' + def func_is_3d(in_file): """Checks if input functional files are 3d.""" @@ -216,7 +215,8 @@ class SPMCommandInputSpec(BaseInterfaceInputSpec): usedefault=True) use_mcr = traits.Bool(desc='Run m-code using SPM MCR') use_v8struct = traits.Bool(True, min_ver='8', usedefault=True, - desc=('Generate SPM8 and higher compatible jobs') + desc=('Generate SPM8 and higher ' + 'compatible jobs') ) @@ -483,8 +483,8 @@ def _make_matlab_command(self, contents, postscript=None): contents[0]) else: if self.jobname in ['st', 'smooth', 'preproc', 'preproc8', - 'fmri_spec', 'fmri_est', 'factorial_design', - 'defs']: + 'fmri_spec', 'fmri_est', + 'factorial_design', 'defs']: # parentheses mscript += self._generate_job('jobs{1}.%s{1}.%s(1)' % (self.jobtype, self.jobname), From 9c2911eb877115e28f123aecad2589ef73b0139b Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 17:26:59 -0400 Subject: [PATCH 03/15] PEP8 compliance for model.py (90%) --- nipype/interfaces/spm/model.py | 296 ++++++++++++++++++++++----------- 1 file changed, 196 insertions(+), 100 deletions(-) diff --git a/nipype/interfaces/spm/model.py b/nipype/interfaces/spm/model.py index 2a3472a648..5883dccda2 100644 --- a/nipype/interfaces/spm/model.py +++ b/nipype/interfaces/spm/model.py @@ -11,8 +11,6 @@ """ -__docformat__ = 'restructuredtext' - # Standard library imports import os from glob import glob @@ -30,11 +28,14 @@ from ...utils.filemanip import (filename_to_list, list_to_filename, split_filename) from ... import logging + logger = logging.getLogger('interface') +__docformat__ = 'restructuredtext' class Level1DesignInputSpec(SPMCommandInputSpec): - spm_mat_dir = Directory(exists=True, field='dir', desc='directory to store SPM.mat file (opt)') + spm_mat_dir = Directory(exists=True, field='dir', + desc='directory to store SPM.mat file (opt)') timing_units = traits.Enum('secs', 'scans', field='timing.units', desc='units for specification of onsets', mandatory=True) @@ -42,14 +43,19 @@ class Level1DesignInputSpec(SPMCommandInputSpec): desc='Interscan interval in secs', mandatory=True) microtime_resolution = traits.Int(field='timing.fmri_t', - desc='Number of time-bins per scan in secs (opt)') + desc=('Number of time-bins per scan ' + 'in secs (opt)')) microtime_onset = traits.Float(field='timing.fmri_t0', - desc='The onset/time-bin in seconds for alignment (opt)') + desc=('The onset/time-bin in seconds for ' + 'alignment (opt)')) session_info = traits.Any(field='sess', - desc='Session specific information generated by ``modelgen.SpecifyModel``', + desc=('Session specific information generated ' + 'by ``modelgen.SpecifyModel``'), mandatory=True) factor_info = traits.List(traits.Dict(traits.Enum('name', 'levels')), - field='fact', desc='Factor specific information file (opt)') + field='fact', + desc=('Factor specific information ' + 'file (opt)')) bases = traits.Dict(traits.Enum('hrf', 'fourier', 'fourier_han', 'gamma', 'fir'), field='bases', desc=""" dict {'name':{'basesparam1':val,...}} @@ -69,9 +75,13 @@ class Level1DesignInputSpec(SPMCommandInputSpec): Number of basis functions """, mandatory=True) volterra_expansion_order = traits.Enum(1, 2, field='volt', - desc='Model interactions - yes:1, no:2') - global_intensity_normalization = traits.Enum('none', 'scaling', field='global', - desc='Global intensity normalization - scaling or none') + desc=('Model interactions - ' + 'yes:1, no:2')) + global_intensity_normalization = traits.Enum('none', 'scaling', + field='global', + desc=('Global intensity ' + 'normalization - ' + 'scaling or none')) mask_image = File(exists=True, field='mask', desc='Image for explicitly masking the analysis') mask_threshold = traits.Either(traits.Enum('-Inf'), traits.Float(), @@ -126,9 +136,11 @@ def _format_arg(self, opt, spec, val): def _parse_inputs(self): """validate spm realign options if set to None ignore """ - einputs = super(Level1Design, self)._parse_inputs(skip=('mask_threshold')) + einputs = super(Level1Design, self)._parse_inputs( + skip=('mask_threshold')) for sessinfo in einputs[0]['sess']: - sessinfo['scans'] = scans_for_fnames(filename_to_list(sessinfo['scans']), keep4d=False) + sessinfo['scans'] = scans_for_fnames( + filename_to_list(sessinfo['scans']), keep4d=False) if not isdefined(self.inputs.spm_mat_dir): einputs[0]['dir'] = np.array([str(os.getcwd())], dtype=object) return einputs @@ -142,15 +154,19 @@ def _make_matlab_command(self, content): # SPM doesn't handle explicit masking properly, especially # when you want to use the entire mask image postscript = "load SPM;\n" - postscript += "SPM.xM.VM = spm_vol('%s');\n" % list_to_filename(self.inputs.mask_image) + postscript += ("SPM.xM.VM = spm_vol('%s');\n" + % list_to_filename(self.inputs.mask_image)) postscript += "SPM.xM.I = 0;\n" postscript += "SPM.xM.T = [];\n" - postscript += "SPM.xM.TH = ones(size(SPM.xM.TH))*(%s);\n" % self.inputs.mask_threshold - postscript += "SPM.xM.xs = struct('Masking', 'explicit masking only');\n" + postscript += ("SPM.xM.TH = ones(size(SPM.xM.TH))*(%s);\n" + % self.inputs.mask_threshold) + postscript += ("SPM.xM.xs = struct('Masking', " + "'explicit masking only');\n") postscript += "save SPM SPM;\n" else: postscript = None - return super(Level1Design, self)._make_matlab_command(content, postscript=postscript) + return super(Level1Design, self)._make_matlab_command( + content, postscript=postscript) def _list_outputs(self): outputs = self._outputs().get() @@ -160,20 +176,26 @@ def _list_outputs(self): class EstimateModelInputSpec(SPMCommandInputSpec): - spm_mat_file = File(exists=True, field='spmmat', desc='absolute path to SPM.mat', + spm_mat_file = File(exists=True, field='spmmat', + desc='absolute path to SPM.mat', copyfile=True, mandatory=True) - estimation_method = traits.Dict(traits.Enum('Classical', 'Bayesian2', 'Bayesian'), + estimation_method = traits.Dict(traits.Enum('Classical', 'Bayesian2', + 'Bayesian'), field='method', - desc='Classical, Bayesian2, Bayesian (dict)', + desc=('Classical, Bayesian2, ' + 'Bayesian (dict)'), mandatory=True) flags = traits.Str(desc='optional arguments (opt)') class EstimateModelOutputSpec(TraitedSpec): - mask_image = File(exists=True, desc='binary mask to constrain estimation') - beta_images = OutputMultiPath(File(exists=True), desc='design parameter estimates') - residual_image = File(exists=True, desc='Mean-squared image of the residuals') + mask_image = File(exists=True, + desc='binary mask to constrain estimation') + beta_images = OutputMultiPath(File(exists=True), + desc='design parameter estimates') + residual_image = File(exists=True, + desc='Mean-squared image of the residuals') RPVimage = File(exists=True, desc='Resels per voxel image') spm_mat_file = File(exists=True, desc='Updated SPM mat file') @@ -261,26 +283,30 @@ class EstimateContrastInputSpec(SPMCommandInputSpec): traits.List(traits.Float)), traits.Tuple(traits.Str, traits.Enum('F'), - traits.List(traits.Either(traits.Tuple(traits.Str, - traits.Enum('T'), - traits.List(traits.Str), - traits.List(traits.Float)), - traits.Tuple(traits.Str, - traits.Enum('T'), - traits.List(traits.Str), - traits.List(traits.Float), - traits.List(traits.Float)))))), + traits.List(traits.Either( + traits.Tuple(traits.Str, + traits.Enum('T'), + traits.List(traits.Str), + traits.List(traits.Float)), + traits.Tuple(traits.Str, + traits.Enum('T'), + traits.List(traits.Str), + traits.List(traits.Float), + traits.List( + traits.Float)))))), desc="""List of contrasts with each contrast being a list of the form: - [('name', 'stat', [condition list], [weight list], [session list])]. if - session list is None or not provided, all sessions are used. For F - contrasts, the condition list should contain previously defined + [('name', 'stat', [condition list], [weight list], [session list])] + If session list is None or not provided, all sessions are used. For + F contrasts, the condition list should contain previously defined T-contrasts.""", mandatory=True) beta_images = InputMultiPath(File(exists=True), - desc='Parameter estimates of the design matrix', + desc=('Parameter estimates of the ' + 'design matrix'), copyfile=False, mandatory=True) - residual_image = File(exists=True, desc='Mean-squared image of the residuals', + residual_image = File(exists=True, + desc='Mean-squared image of the residuals', copyfile=False, mandatory=True) use_derivs = traits.Bool(desc='use derivatives for estimation', @@ -290,10 +316,14 @@ class EstimateContrastInputSpec(SPMCommandInputSpec): class EstimateContrastOutputSpec(TraitedSpec): - con_images = OutputMultiPath(File(exists=True), desc='contrast images from a t-contrast') - spmT_images = OutputMultiPath(File(exists=True), desc='stat images from a t-contrast') - ess_images = OutputMultiPath(File(exists=True), desc='contrast images from an F-contrast') - spmF_images = OutputMultiPath(File(exists=True), desc='stat images from an F-contrast') + con_images = OutputMultiPath(File(exists=True), + desc='contrast images from a t-contrast') + spmT_images = OutputMultiPath(File(exists=True), + desc='stat images from a t-contrast') + ess_images = OutputMultiPath(File(exists=True), + desc='contrast images from an F-contrast') + spmF_images = OutputMultiPath(File(exists=True), + desc='stat images from an F-contrast') spm_mat_file = File(exists=True, desc='Updated SPM mat file') @@ -336,41 +366,52 @@ def _make_matlab_command(self, _): contrasts[i].sessions = cont[4] script = "% generated by nipype.interfaces.spm\n" script += "spm_defaults;\n" - script += "jobs{1}.stats{1}.con.spmmat = {'%s'};\n" % self.inputs.spm_mat_file + script += ("jobs{1}.stats{1}.con.spmmat = {'%s'};\n" + % self.inputs.spm_mat_file) script += "load(jobs{1}.stats{1}.con.spmmat{:});\n" script += "SPM.swd = '%s';\n" % os.getcwd() script += "save(jobs{1}.stats{1}.con.spmmat{:},'SPM');\n" script += "names = SPM.xX.name;\n" # get names for columns - if isdefined(self.inputs.group_contrast) and self.inputs.group_contrast: + if (isdefined(self.inputs.group_contrast) and + self.inputs.group_contrast): script += "condnames=names;\n" else: if self.inputs.use_derivs: script += "pat = 'Sn\([0-9]*\) (.*)';\n" else: - script += "pat = 'Sn\([0-9]*\) (.*)\*bf\(1\)|Sn\([0-9]*\) .*\*bf\([2-9]\)|Sn\([0-9]*\) (.*)';\n" + script += ("pat = 'Sn\([0-9]*\) (.*)\*bf\(1\)|Sn\([0-9]*\) " + ".*\*bf\([2-9]\)|Sn\([0-9]*\) (.*)';\n") script += "t = regexp(names,pat,'tokens');\n" # get sessidx for columns script += "pat1 = 'Sn\(([0-9].*)\)\s.*';\n" script += "t1 = regexp(names,pat1,'tokens');\n" - script += "for i0=1:numel(t),condnames{i0}='';condsess(i0)=0;if ~isempty(t{i0}{1}),condnames{i0} = t{i0}{1}{1};condsess(i0)=str2num(t1{i0}{1}{1});end;end;\n" + script += ("for i0=1:numel(t),condnames{i0}='';condsess(i0)=0;if " + "~isempty(t{i0}{1}),condnames{i0} = t{i0}{1}{1};" + "condsess(i0)=str2num(t1{i0}{1}{1});end;end;\n") # BUILD CONTRAST SESSION STRUCTURE for i, contrast in enumerate(contrasts): if contrast.stat == 'T': - script += "consess{%d}.tcon.name = '%s';\n" % (i + 1, contrast.name) - script += "consess{%d}.tcon.convec = zeros(1,numel(names));\n" % (i + 1) + script += ("consess{%d}.tcon.name = '%s';\n" + % (i + 1, contrast.name)) + script += ("consess{%d}.tcon.convec = zeros(1,numel(names));\n" + % (i + 1)) for c0, cond in enumerate(contrast.conditions): - script += "idx = strmatch('%s',condnames,'exact');\n" % (cond) + script += ("idx = strmatch('%s',condnames,'exact');\n" + % (cond)) script += "if isempty(idx), throw(MException('CondName:Chk', sprintf('Condition %%s not found in design','%s'))); end;\n" % cond if contrast.sessions: for sno, sw in enumerate(contrast.sessions): - script += "sidx = find(condsess(idx)==%d);\n" % (sno + 1) + script += ("sidx = find(condsess(idx)==%d);\n" + % (sno + 1)) script += "consess{%d}.tcon.convec(idx(sidx)) = %f;\n" % (i + 1, sw * contrast.weights[c0]) else: - script += "consess{%d}.tcon.convec(idx) = %f;\n" % (i + 1, contrast.weights[c0]) + script += ("consess{%d}.tcon.convec(idx) = %f;\n" + % (i + 1, contrast.weights[c0])) for i, contrast in enumerate(contrasts): if contrast.stat == 'F': - script += "consess{%d}.fcon.name = '%s';\n" % (i + 1, contrast.name) + script += ("consess{%d}.fcon.name = '%s';\n" + % (i + 1, contrast.name)) for cl0, fcont in enumerate(contrast.conditions): try: tidx = cname.index(fcont[0]) @@ -380,7 +421,8 @@ def _make_matlab_command(self, _): "to the F contrasts") script += "consess{%d}.fcon.convec{%d} = consess{%d}.tcon.convec;\n" % (i + 1, cl0 + 1, tidx + 1) script += "jobs{1}.stats{1}.con.consess = consess;\n" - script += "if strcmp(spm('ver'),'SPM8'), spm_jobman('initcfg');jobs=spm_jobman('spm5tospm8',{jobs});end\n" + script += ("if strcmp(spm('ver'),'SPM8'), spm_jobman('initcfg');" + "jobs=spm_jobman('spm5tospm8',{jobs});end\n") script += "spm_jobman('run',jobs);" return script @@ -414,16 +456,37 @@ def _list_outputs(self): class ThresholdInputSpec(SPMCommandInputSpec): - spm_mat_file = File(exists=True, desc='absolute path to SPM.mat', copyfile=True, mandatory=True) - stat_image = File(exists=True, desc='stat image', copyfile=False, mandatory=True) - contrast_index = traits.Int(mandatory=True, desc='which contrast in the SPM.mat to use') - use_fwe_correction = traits.Bool(True, usedefault=True, desc="whether to use FWE (Bonferroni) correction for initial threshold (height_threshold_type has to be set to p-value)") - use_topo_fdr = traits.Bool(True, usedefault=True, desc="whether to use FDR over cluster extent probabilities") - height_threshold = traits.Float(0.05, usedefault=True, desc="value for initial thresholding (defining clusters)") - height_threshold_type = traits.Enum('p-value', 'stat', usedefault=True, desc="Is the cluster forming threshold a stat value or p-value?") - extent_fdr_p_threshold = traits.Float(0.05, usedefault=True, desc='p threshold on FDR corrected cluster size probabilities') - extent_threshold = traits.Int(0, usedefault=True, desc="Minimum cluster size in voxels") - force_activation = traits.Bool(False, usedefault=True, desc="In case no clusters survive the topological inference step this will pick a culster with the highes sum of t-values. Use with care.") + spm_mat_file = File(exists=True, desc='absolute path to SPM.mat', + copyfile=True, mandatory=True) + stat_image = File(exists=True, desc='stat image', + copyfile=False, mandatory=True) + contrast_index = traits.Int(mandatory=True, + desc='which contrast in the SPM.mat to use') + use_fwe_correction = traits.Bool(True, usedefault=True, + desc=('whether to use FWE (Bonferroni) ' + 'correction for initial threshold ' + '(height_threshold_type has to be ' + 'set to p-value)')) + use_topo_fdr = traits.Bool(True, usedefault=True, + desc=('whether to use FDR over cluster extent ' + 'probabilities')) + height_threshold = traits.Float(0.05, usedefault=True, + desc=('value for initial thresholding ' + '(defining clusters)')) + height_threshold_type = traits.Enum('p-value', 'stat', usedefault=True, + desc=('Is the cluster forming ' + 'threshold a stat value or ' + 'p-value?')) + extent_fdr_p_threshold = traits.Float(0.05, usedefault=True, + desc=('p threshold on FDR corrected ' + 'cluster size probabilities')) + extent_threshold = traits.Int(0, usedefault=True, + desc='Minimum cluster size in voxels') + force_activation = traits.Bool(False, usedefault=True, + desc=('In case no clusters survive the ' + 'topological inference step this ' + 'will pick a culster with the highes ' + 'sum of t-values. Use with care.')) class ThresholdOutputSpec(TraitedSpec): @@ -478,9 +541,11 @@ def _make_matlab_command(self, _): script += "force_activation = 1;\n" else: script += "force_activation = 0;\n" - script += "cluster_extent_p_fdr_thr = %f;\n" % self.inputs.extent_fdr_p_threshold + script += ("cluster_extent_p_fdr_thr = %f;\n" + % self.inputs.extent_fdr_p_threshold) script += "stat_filename = '%s';\n" % self.inputs.stat_image - script += "height_threshold_type = '%s';\n" % self.inputs.height_threshold_type + script += ("height_threshold_type = '%s';\n" + % self.inputs.height_threshold_type) script += "extent_threshold = %d;\n" % self.inputs.extent_threshold script += "load %s;\n" % self.inputs.spm_mat_file @@ -581,13 +646,17 @@ def aggregate_outputs(self, runtime=None): setattr(outputs, 'pre_topo_fdr_map', self._gen_pre_topo_map_filename()) for line in runtime.stdout.split('\n'): if line.startswith("activation_forced = "): - setattr(outputs, 'activation_forced', line[len("activation_forced = "):].strip() == "1") + setattr(outputs, 'activation_forced', + line[len("activation_forced = "):].strip() == "1") elif line.startswith("n_clusters = "): - setattr(outputs, 'n_clusters', int(line[len("n_clusters = "):].strip())) + setattr(outputs, 'n_clusters', + int(line[len("n_clusters = "):].strip())) elif line.startswith("pre_topo_n_clusters = "): - setattr(outputs, 'pre_topo_n_clusters', int(line[len("pre_topo_n_clusters = "):].strip())) + setattr(outputs, 'pre_topo_n_clusters', + int(line[len("pre_topo_n_clusters = "):].strip())) elif line.startswith("cluster_forming_thr = "): - setattr(outputs, 'cluster_forming_thr', float(line[len("cluster_forming_thr = "):].strip())) + setattr(outputs, 'cluster_forming_thr', + float(line[len("cluster_forming_thr = "):].strip())) return outputs def _list_outputs(self): @@ -598,11 +667,17 @@ def _list_outputs(self): class ThresholdStatisticsInputSpec(SPMCommandInputSpec): - spm_mat_file = File(exists=True, desc='absolute path to SPM.mat', copyfile=True, mandatory=True) - stat_image = File(exists=True, desc='stat image', copyfile=False, mandatory=True) - contrast_index = traits.Int(mandatory=True, desc='which contrast in the SPM.mat to use') - height_threshold = traits.Float(desc="stat value for initial thresholding (defining clusters)", mandatory=True) - extent_threshold = traits.Int(0, usedefault=True, desc="Minimum cluster size in voxels") + spm_mat_file = File(exists=True, desc='absolute path to SPM.mat', + copyfile=True, mandatory=True) + stat_image = File(exists=True, desc='stat image', + copyfile=False, mandatory=True) + contrast_index = traits.Int(mandatory=True, + desc='which contrast in the SPM.mat to use') + height_threshold = traits.Float(desc=('stat value for initial ' + 'thresholding (defining clusters)'), + mandatory=True) + extent_threshold = traits.Int(0, usedefault=True, + desc="Minimum cluster size in voxels") class ThresholdStatisticsOutputSpec(TraitedSpec): @@ -615,8 +690,8 @@ class ThresholdStatisticsOutputSpec(TraitedSpec): class ThresholdStatistics(SPMCommand): - '''Given height and cluster size threshold calculate theoretical probabilities - concerning false positives + '''Given height and cluster size threshold calculate theoretical + probabilities concerning false positives Examples -------- @@ -693,8 +768,11 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): setattr(outputs, cur_output, float(line)) cur_output = "" continue - if len(line.split()) != 0 and line.split()[0] in ["clusterwise_P_FDR", "clusterwise_P_RF", "voxelwise_P_Bonf", "voxelwise_P_FDR", - "voxelwise_P_RF", "voxelwise_P_uncor"]: + if (len(line.split()) != 0 and + line.split()[0] in ["clusterwise_P_FDR", + "clusterwise_P_RF", "voxelwise_P_Bonf", + "voxelwise_P_FDR", "voxelwise_P_RF", + "voxelwise_P_uncor"]): cur_output = line.split()[0] continue @@ -702,38 +780,52 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): class FactorialDesignInputSpec(SPMCommandInputSpec): - spm_mat_dir = Directory(exists=True, field='dir', desc='directory to store SPM.mat file (opt)') - # really need to make an alias of InputMultiPath because the inputs below are not Path - covariates = InputMultiPath(traits.Dict(key_trait=traits.Enum('vector', 'name', - 'interaction', 'centering')), + spm_mat_dir = Directory(exists=True, field='dir', + desc='directory to store SPM.mat file (opt)') + # Need to make an alias of InputMultiPath; the inputs below are not Path + covariates = InputMultiPath(traits.Dict( + key_trait=traits.Enum('vector', 'name', 'interaction', 'centering')), field='cov', - desc='covariate dictionary {vector, name, interaction, centering}') + desc=('covariate dictionary {vector, name, ' + 'interaction, centering}')) threshold_mask_none = traits.Bool(field='masking.tm.tm_none', - xor=['threshold_mask_absolute', 'threshold_mask_relative'], + xor=['threshold_mask_absolute', + 'threshold_mask_relative'], desc='do not use threshold masking') threshold_mask_absolute = traits.Float(field='masking.tm.tma.athresh', - xor=['threshold_mask_none', 'threshold_mask_relative'], + xor=['threshold_mask_none', + 'threshold_mask_relative'], desc='use an absolute threshold') threshold_mask_relative = traits.Float(field='masking.tm.tmr.rthresh', - xor=['threshold_mask_absolute', 'threshold_mask_none'], - desc='threshold using a proportion of the global value') + xor=['threshold_mask_absolute', + 'threshold_mask_none'], + desc=('threshold using a ' + 'proportion of the global ' + 'value')) use_implicit_threshold = traits.Bool(field='masking.im', - desc='use implicit mask NaNs or zeros to threshold') + desc=('use implicit mask NaNs or ' + 'zeros to threshold')) explicit_mask_file = File(field='masking.em', # requires cell desc='use an implicit mask file to threshold') global_calc_omit = traits.Bool(field='globalc.g_omit', - xor=['global_calc_mean', 'global_calc_values'], + xor=['global_calc_mean', + 'global_calc_values'], desc='omit global calculation') global_calc_mean = traits.Bool(field='globalc.g_mean', - xor=['global_calc_omit', 'global_calc_values'], + xor=['global_calc_omit', + 'global_calc_values'], desc='use mean for global calculation') - global_calc_values = traits.List(traits.Float, field='globalc.g_user.global_uval', - xor=['global_calc_mean', 'global_calc_omit'], + global_calc_values = traits.List(traits.Float, + field='globalc.g_user.global_uval', + xor=['global_calc_mean', + 'global_calc_omit'], desc='omit global calculation') no_grand_mean_scaling = traits.Bool(field='globalm.gmsca.gmsca_no', - desc='do not perform grand mean scaling') + desc=('do not perform grand mean ' + 'scaling')) global_normalization = traits.Enum(1, 2, 3, field='globalm.glonorm', - desc='global normalization None-1, Proportional-2, ANCOVA-3') + desc=('global normalization None-1, ' + 'Proportional-2, ANCOVA-3')) class FactorialDesignOutputSpec(TraitedSpec): @@ -822,9 +914,11 @@ class TwoSampleTTestDesignInputSpec(FactorialDesignInputSpec): mandatory=True, minlen=2, desc='Group 2 input files') dependent = traits.Bool(field='des.t2.dept', - desc='Are the measurements dependent between levels') + desc=('Are the measurements dependent between ' + 'levels')) unequal_variance = traits.Bool(field='des.t2.variance', - desc='Are the variances equal or unequal between groups') + desc=('Are the variances equal or unequal ' + 'between groups')) class TwoSampleTTestDesign(FactorialDesign): @@ -850,7 +944,8 @@ def _format_arg(self, opt, spec, val): class PairedTTestDesignInputSpec(FactorialDesignInputSpec): - paired_files = traits.List(traits.List(File(exists=True), minlen=2, maxlen=2), + paired_files = traits.List(traits.List(File(exists=True), + minlen=2, maxlen=2), field='des.pt.pair', mandatory=True, minlen=2, desc='List of paired files') @@ -889,11 +984,11 @@ class MultipleRegressionDesignInputSpec(FactorialDesignInputSpec): include_intercept = traits.Bool(True, field='des.mreg.incint', usedefault=True, desc='Include intercept in design') - user_covariates = InputMultiPath(traits.Dict(key_trait=traits.Enum('vector', - 'name', - 'centering')), + user_covariates = InputMultiPath(traits.Dict( + key_trait=traits.Enum('vector', 'name', 'centering')), field='des.mreg.mcov', - desc='covariate dictionary {vector, name, centering}') + desc=('covariate dictionary {vector, ' + 'name, centering}')) class MultipleRegressionDesign(FactorialDesign): @@ -924,4 +1019,5 @@ def _format_arg(self, opt, spec, val): outdict[mapping[key]] = keyval outlist.append(outdict) return outlist - return super(MultipleRegressionDesign, self)._format_arg(opt, spec, val) + return (super(MultipleRegressionDesign, self) + ._format_arg(opt, spec, val)) From 0cb565df81b26f7fd63cf3d89bd28b3557c14a57 Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 17:53:40 -0400 Subject: [PATCH 04/15] PEP8 compliance for model.py (100%) --- nipype/interfaces/spm/model.py | 47 ++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/nipype/interfaces/spm/model.py b/nipype/interfaces/spm/model.py index 5883dccda2..19fe4ab5e6 100644 --- a/nipype/interfaces/spm/model.py +++ b/nipype/interfaces/spm/model.py @@ -399,12 +399,16 @@ def _make_matlab_command(self, _): for c0, cond in enumerate(contrast.conditions): script += ("idx = strmatch('%s',condnames,'exact');\n" % (cond)) - script += "if isempty(idx), throw(MException('CondName:Chk', sprintf('Condition %%s not found in design','%s'))); end;\n" % cond + script += (("if isempty(idx), throw(MException(" + "'CondName:Chk', sprintf('Condition %%s not " + "found in design','%s'))); end;\n") % cond) if contrast.sessions: for sno, sw in enumerate(contrast.sessions): script += ("sidx = find(condsess(idx)==%d);\n" % (sno + 1)) - script += "consess{%d}.tcon.convec(idx(sidx)) = %f;\n" % (i + 1, sw * contrast.weights[c0]) + script += (("consess{%d}.tcon.convec(idx(sidx)) " + "= %f;\n") + % (i + 1, sw * contrast.weights[c0])) else: script += ("consess{%d}.tcon.convec(idx) = %f;\n" % (i + 1, contrast.weights[c0])) @@ -419,7 +423,9 @@ def _make_matlab_command(self, _): Exception("Contrast Estimate: could not get index of" " T contrast. probably not defined prior " "to the F contrasts") - script += "consess{%d}.fcon.convec{%d} = consess{%d}.tcon.convec;\n" % (i + 1, cl0 + 1, tidx + 1) + script += (("consess{%d}.fcon.convec{%d} = " + "consess{%d}.tcon.convec;\n") + % (i + 1, cl0 + 1, tidx + 1)) script += "jobs{1}.stats{1}.con.consess = consess;\n" script += ("if strcmp(spm('ver'),'SPM8'), spm_jobman('initcfg');" "jobs=spm_jobman('spm5tospm8',{jobs});end\n") @@ -578,7 +584,9 @@ def _make_matlab_command(self, _): Zth = Z(Z >= cluster_forming_thr); """ - script += "spm_write_filtered(Zth,XYZth,stat_map_vol.dim',stat_map_vol.mat,'thresholded map', '%s');\n" % self._gen_pre_topo_map_filename() + script += (("spm_write_filtered(Zth,XYZth,stat_map_vol.dim'," + "stat_map_vol.mat,'thresholded map', '%s');\n") + % self._gen_pre_topo_map_filename()) script += """ max_size = 0; max_size_index = 0; @@ -590,7 +598,8 @@ def _make_matlab_command(self, _): else if use_topo_fdr V2R = 1/prod(FWHM(stat_map_vol.dim > 1)); - [uc,Pc,ue] = spm_uc_clusterFDR(cluster_extent_p_fdr_thr,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); + [uc,Pc,ue] = spm_uc_clusterFDR(cluster_extent_p_fdr_thr,df,\ +STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); end voxel_labels = spm_clusters(XYZth); @@ -601,8 +610,10 @@ def _make_matlab_command(self, _): for i = 1:nclusters cluster_size = sum(voxel_labels==i); - if cluster_size > extent_threshold && (~use_topo_fdr || (cluster_size - uc) > -1) - thresholded_XYZ = cat(2, thresholded_XYZ, XYZth(:,voxel_labels == i)); + if cluster_size > extent_threshold && (~use_topo_fdr || \ +(cluster_size - uc) > -1) + thresholded_XYZ = cat(2, thresholded_XYZ, \ +XYZth(:,voxel_labels == i)); thresholded_Z = cat(2, thresholded_Z, Zth(voxel_labels == i)); th_nclusters = th_nclusters + 1; end @@ -636,13 +647,16 @@ def _make_matlab_command(self, _): fprintf('cluster_forming_thr = %f\\n',cluster_forming_thr); """ - script += "spm_write_filtered(thresholded_Z,thresholded_XYZ,stat_map_vol.dim',stat_map_vol.mat,'thresholded map', '%s');\n" % self._gen_thresholded_map_filename() + script += (("spm_write_filtered(thresholded_Z,thresholded_XYZ," + "stat_map_vol.dim',stat_map_vol.mat,'thresholded map'," + " '%s');\n") % self._gen_thresholded_map_filename()) return script def aggregate_outputs(self, runtime=None): outputs = self._outputs() - setattr(outputs, 'thresholded_map', self._gen_thresholded_map_filename()) + setattr(outputs, 'thresholded_map', + self._gen_thresholded_map_filename()) setattr(outputs, 'pre_topo_fdr_map', self._gen_pre_topo_map_filename()) for line in runtime.stdout.split('\n'): if line.startswith("activation_forced = "): @@ -735,7 +749,8 @@ def _make_matlab_command(self, _): voxelwise_P_uncor = (1-spm_Ncdf(cluster_forming_thr)).^n case 'T' VPs = (1 - spm_Tcdf(Zum,df(2))).^n; - voxelwise_P_uncor = (1 - spm_Tcdf(cluster_forming_thr,df(2))).^n + voxelwise_P_uncor = \ +(1 - spm_Tcdf(cluster_forming_thr,df(2))).^n case 'X' VPs = (1-spm_Xcdf(Zum,df(2))).^n; voxelwise_P_uncor = (1-spm_Xcdf(cluster_forming_thr,df(2))).^n @@ -749,14 +764,17 @@ def _make_matlab_command(self, _): V2R = 1/prod(FWHM(stat_map_vol.dim > 1)); -clusterwise_P_RF = spm_P_RF(1,extent_threshold*V2R,cluster_forming_thr,df,STAT,R,n) +clusterwise_P_RF = \ +spm_P_RF(1,extent_threshold*V2R,cluster_forming_thr,df,STAT,R,n) [x,y,z] = ind2sub(size(stat_map_data),(1:numel(stat_map_data))'); XYZ = cat(1, x', y', z'); -[u, CPs, ue] = spm_uc_clusterFDR(0.05,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); +[u, CPs, ue] = \ +spm_uc_clusterFDR(0.05,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); -clusterwise_P_FDR = spm_P_clusterFDR(extent_threshold*V2R,df,STAT,R,n,cluster_forming_thr,CPs') +clusterwise_P_FDR = \ +spm_P_clusterFDR(extent_threshold*V2R,df,STAT,R,n,cluster_forming_thr,CPs') """ return script @@ -962,7 +980,8 @@ class PairedTTestDesign(FactorialDesign): -------- >>> pttest = PairedTTestDesign() - >>> pttest.inputs.paired_files = [['cont1.nii','cont1a.nii'],['cont2.nii','cont2a.nii']] + >>> pttest.inputs.paired_files = [['cont1.nii','cont1a.nii'],\ +['cont2.nii','cont2a.nii']] >>> pttest.run() # doctest: +SKIP """ From 2005b6f31a986f26212bc6bf3c1f34b72bbc298e Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 18:04:12 -0400 Subject: [PATCH 05/15] PEP8 compliance for model.py (100%) V2 --- nipype/interfaces/spm/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/model.py b/nipype/interfaces/spm/model.py index 19fe4ab5e6..e7cbedfc63 100644 --- a/nipype/interfaces/spm/model.py +++ b/nipype/interfaces/spm/model.py @@ -328,7 +328,7 @@ class EstimateContrastOutputSpec(TraitedSpec): class EstimateContrast(SPMCommand): - """use spm_contrasts to estimate contrasts of interest + """Use spm_contrasts to estimate contrasts of interest Examples -------- From 83e55cc35b9ccd96f88228195552b7db8ef0e60f Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 19:09:55 -0400 Subject: [PATCH 06/15] PEP8 compliance for utils.py --- nipype/interfaces/spm/utils.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/nipype/interfaces/spm/utils.py b/nipype/interfaces/spm/utils.py index 452727fa44..a5ddab3e58 100644 --- a/nipype/interfaces/spm/utils.py +++ b/nipype/interfaces/spm/utils.py @@ -3,13 +3,15 @@ import os import numpy as np -from .base import SPMCommandInputSpec, SPMCommand, Info, scans_for_fnames, scans_for_fname +from .base import (SPMCommandInputSpec, SPMCommand, Info, scans_for_fnames, + scans_for_fname) from ..matlab import MatlabCommand from ..base import (TraitedSpec, BaseInterface, BaseInterfaceInputSpec, isdefined, OutputMultiPath, InputMultiPath) from ..base import File, traits -from ...utils.filemanip import split_filename, fname_presuffix, filename_to_list, list_to_filename +from ...utils.filemanip import (split_filename, fname_presuffix, + filename_to_list, list_to_filename) class Analyze2niiInputSpec(SPMCommandInputSpec): @@ -45,7 +47,8 @@ class CalcCoregAffineInputSpec(SPMCommandInputSpec): target = File(exists=True, mandatory=True, desc='target for generating affine transform') moving = File(exists=True, mandatory=True, copyfile=False, - desc='volume transform can be applied to register with target') + desc=('volume transform can be applied to register with ' + 'target')) mat = File(desc='Filename used to store affine matrix') invmat = File(desc='Filename used to store inverse affine matrix') @@ -346,7 +349,8 @@ class ResliceToReferenceOutput(TraitedSpec): class ResliceToReference(SPMCommand): - """ Uses spm to reslice a volume to a target image space or to a provided voxel size and bounding box + """Uses spm to reslice a volume to a target image space or to a provided + voxel size and bounding box Examples -------- @@ -409,10 +413,11 @@ class DicomImportInputSpec(SPMCommandInputSpec): icedims = traits.Bool(False, field='convopts.icedims', usedefault=True, - desc='If image sorting fails, one can try using the additional\ - SIEMENS ICEDims information to create unique filenames.\ - Use this only if there would be multiple volumes with\ - exactly the same file names.') + desc=('If image sorting fails, one can try using ' + 'the additional SIEMENS ICEDims information ' + 'to create unique filenames. Use this only if ' + 'there would be multiple volumes with exactly ' + 'the same file names.')) class DicomImportOutputSpec(TraitedSpec): @@ -468,9 +473,13 @@ def _list_outputs(self): if self.inputs.output_dir_struct == "flat": outputs['out_files'] = glob(os.path.join(od, '*.%s' % ext)) elif self.inputs.output_dir_struct == 'series': - outputs['out_files'] = glob(os.path.join(od, os.path.join('*', '*.%s' % ext))) - elif self.inputs.output_dir_struct in ['patid', 'date_time', 'patname']: - outputs['out_files'] = glob(os.path.join(od, os.path.join('*', '*', '*.%s' % ext))) + outputs['out_files'] = glob( + os.path.join(od, os.path.join('*', '*.%s' % ext))) + elif (self.inputs.output_dir_struct in + ['patid', 'date_time', 'patname']): + outputs['out_files'] = glob( + os.path.join(od, os.path.join('*', '*', '*.%s' % ext))) elif self.inputs.output_dir_struct == 'patid_date': - outputs['out_files'] = glob(os.path.join(od, os.path.join('*', '*', '*', '*.%s' % ext))) + outputs['out_files'] = glob( + os.path.join(od, os.path.join('*', '*', '*', '*.%s' % ext))) return outputs From b81611a91b74b6b7838aa5696c9cdd3b13875edb Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 26 Aug 2016 19:24:31 -0400 Subject: [PATCH 07/15] PEP8 compliance for preprocess.py (5%) --- nipype/interfaces/spm/preprocess.py | 53 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index c1af8d025c..1d2a7e8559 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -47,7 +47,8 @@ class SliceTimingInputSpec(SPMCommandInputSpec): 'calculated as TR-(TR/num_slices)'), mandatory=True) slice_order = traits.List(traits.Int(), field='so', - desc='1-based order in which slices are acquired', + desc=('1-based order in which slices are ' + 'acquired'), mandatory=True) ref_slice = traits.Int(field='refslice', desc='1-based Number of the reference slice', @@ -104,7 +105,8 @@ def _list_outputs(self): filelist = filename_to_list(self.inputs.in_files) for f in filelist: if isinstance(f, list): - run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) for in_f in f] + run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) + for in_f in f] else: run = fname_presuffix(f, prefix=self.inputs.out_prefix) outputs['timecorrected_files'].append(run) @@ -126,7 +128,8 @@ class RealignInputSpec(SPMCommandInputSpec): separation = traits.Range(low=0.0, field='eoptions.sep', desc='sampling separation in mm') register_to_mean = traits.Bool(field='eoptions.rtm', - desc='Indicate whether realignment is done to the mean image') + desc=('Indicate whether realignment is ' + 'done to the mean image')) weight_img = File(exists=True, field='eoptions.weight', desc='filename of weighting image') interp = traits.Range(low=0, high=7, field='eoptions.interp', @@ -138,10 +141,12 @@ class RealignInputSpec(SPMCommandInputSpec): minlen=2, maxlen=2, usedefault=True, desc='determines which images to reslice') write_interp = traits.Range(low=0, high=7, field='roptions.interp', - desc='degree of b-spline used for interpolation') + desc=('degree of b-spline used for ' + 'interpolation')) write_wrap = traits.List(traits.Int(), minlen=3, maxlen=3, field='roptions.wrap', - desc='Check if interpolation should wrap in [x,y,z]') + desc=('Check if interpolation should wrap in ' + '[x,y,z]')) write_mask = traits.Bool(field='roptions.mask', desc='True/False mask output image') out_prefix = traits.String('r', field='roptions.prefix', usedefault=True, @@ -150,20 +155,25 @@ class RealignInputSpec(SPMCommandInputSpec): class RealignOutputSpec(TraitedSpec): mean_image = File(exists=True, desc='Mean image file from the realignment') - modified_in_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)), - File(exists=True)), - desc='Copies of all files passed to in_files.\ - Headers will have been modified to align all\ - images with the first, or optionally to first\ - do that, extract a mean image, and re-align to\ - that mean image.') - realigned_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)), - File(exists=True)), - desc='If jobtype is write or estwrite, these will be the\ - resliced files. Otherwise, they will be copies of\ - in_files that have had their headers rewritten.') + modified_in_files = OutputMultiPath(traits.Either( + traits.List(File(exists=True)), File(exists=True)), + desc=('Copies of all files passed to ' + 'in_files. Headers will have ' + 'been modified to align all ' + 'images with the first, or ' + 'optionally to first do that, ' + 'extract a mean image, and ' + 're-align to that mean image.')) + realigned_files = OutputMultiPath(traits.Either( + traits.List(File(exists=True)), File(exists=True)), + desc=('If jobtype is write or estwrite, ' + 'these will be the resliced files.' + ' Otherwise, they will be copies ' + 'of in_files that have had their ' + 'headers rewritten.')) realignment_parameters = OutputMultiPath(File(exists=True), - desc='Estimated translation and rotation parameters') + desc=('Estimated translation and ' + 'rotation parameters')) class Realign(SPMCommand): @@ -220,10 +230,9 @@ def _list_outputs(self): tmp_imgf = imgf[0] else: tmp_imgf = imgf - outputs['realignment_parameters'].append(fname_presuffix(tmp_imgf, - prefix='rp_', - suffix='.txt', - use_ext=False)) + outputs['realignment_parameters'].append( + fname_presuffix(tmp_imgf, prefix='rp_', suffix='.txt', + use_ext=False)) if not isinstance(imgf, list) and func_is_3d(imgf): break if self.inputs.jobtype == "estimate": From 61d4350115481e092c0d1fe9195746c5c1c6b892 Mon Sep 17 00:00:00 2001 From: Clark Date: Sat, 27 Aug 2016 20:09:04 -0400 Subject: [PATCH 08/15] reverted \ in some docstrings & tests --- nipype/interfaces/spm/model.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/nipype/interfaces/spm/model.py b/nipype/interfaces/spm/model.py index e7cbedfc63..6e098cccc0 100644 --- a/nipype/interfaces/spm/model.py +++ b/nipype/interfaces/spm/model.py @@ -598,8 +598,7 @@ def _make_matlab_command(self, _): else if use_topo_fdr V2R = 1/prod(FWHM(stat_map_vol.dim > 1)); - [uc,Pc,ue] = spm_uc_clusterFDR(cluster_extent_p_fdr_thr,df,\ -STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); + [uc,Pc,ue] = spm_uc_clusterFDR(cluster_extent_p_fdr_thr,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); end voxel_labels = spm_clusters(XYZth); @@ -610,10 +609,8 @@ def _make_matlab_command(self, _): for i = 1:nclusters cluster_size = sum(voxel_labels==i); - if cluster_size > extent_threshold && (~use_topo_fdr || \ -(cluster_size - uc) > -1) - thresholded_XYZ = cat(2, thresholded_XYZ, \ -XYZth(:,voxel_labels == i)); + if cluster_size > extent_threshold && (~use_topo_fdr || (cluster_size - uc) > -1) + thresholded_XYZ = cat(2, thresholded_XYZ, XYZth(:,voxel_labels == i)); thresholded_Z = cat(2, thresholded_Z, Zth(voxel_labels == i)); th_nclusters = th_nclusters + 1; end @@ -749,8 +746,7 @@ def _make_matlab_command(self, _): voxelwise_P_uncor = (1-spm_Ncdf(cluster_forming_thr)).^n case 'T' VPs = (1 - spm_Tcdf(Zum,df(2))).^n; - voxelwise_P_uncor = \ -(1 - spm_Tcdf(cluster_forming_thr,df(2))).^n + voxelwise_P_uncor = (1 - spm_Tcdf(cluster_forming_thr,df(2))).^n case 'X' VPs = (1-spm_Xcdf(Zum,df(2))).^n; voxelwise_P_uncor = (1-spm_Xcdf(cluster_forming_thr,df(2))).^n @@ -764,17 +760,14 @@ def _make_matlab_command(self, _): V2R = 1/prod(FWHM(stat_map_vol.dim > 1)); -clusterwise_P_RF = \ -spm_P_RF(1,extent_threshold*V2R,cluster_forming_thr,df,STAT,R,n) +clusterwise_P_RF = spm_P_RF(1,extent_threshold*V2R,cluster_forming_thr,df,STAT,R,n) [x,y,z] = ind2sub(size(stat_map_data),(1:numel(stat_map_data))'); XYZ = cat(1, x', y', z'); -[u, CPs, ue] = \ -spm_uc_clusterFDR(0.05,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); +[u, CPs, ue] = spm_uc_clusterFDR(0.05,df,STAT,R,n,Z,XYZ,V2R,cluster_forming_thr); -clusterwise_P_FDR = \ -spm_P_clusterFDR(extent_threshold*V2R,df,STAT,R,n,cluster_forming_thr,CPs') +clusterwise_P_FDR = spm_P_clusterFDR(extent_threshold*V2R,df,STAT,R,n,cluster_forming_thr,CPs') """ return script @@ -980,8 +973,7 @@ class PairedTTestDesign(FactorialDesign): -------- >>> pttest = PairedTTestDesign() - >>> pttest.inputs.paired_files = [['cont1.nii','cont1a.nii'],\ -['cont2.nii','cont2a.nii']] + >>> pttest.inputs.paired_files = [['cont1.nii','cont1a.nii'],['cont2.nii','cont2a.nii']] >>> pttest.run() # doctest: +SKIP """ From 58a2c662a1cbe10e0f8684aae1e2a7d7111fda33 Mon Sep 17 00:00:00 2001 From: Clark Date: Sat, 27 Aug 2016 21:07:48 -0400 Subject: [PATCH 09/15] Minor change to restart build... --- nipype/interfaces/spm/preprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 1d2a7e8559..d1f6ea6270 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -472,7 +472,7 @@ def _format_arg(self, opt, spec, val): return super(Normalize, self)._format_arg(opt, spec, val) def _parse_inputs(self): - """validate spm normalize options if set to None ignore + """Validate spm normalize options if set to None ignore """ einputs = super(Normalize, self)._parse_inputs(skip=('jobtype', 'apply_to_files')) From 02e4583479485c60d9ff1a19f1d95d941382ca74 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Sun, 28 Aug 2016 15:24:02 -0400 Subject: [PATCH 10/15] PEP8 compliance for preproc (25%) --- nipype/interfaces/spm/preprocess.py | 88 ++++++++++++++++++----------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index d1f6ea6270..b89d9a1f3d 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -58,9 +58,9 @@ class SliceTimingInputSpec(SPMCommandInputSpec): class SliceTimingOutputSpec(TraitedSpec): - timecorrected_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)), - File(exists=True)), - desc='slice time corrected files') + timecorrected_files = OutputMultiPath( + traits.Either(traits.List(File(exists=True)), File(exists=True)), + desc='slice time corrected files') class SliceTiming(SPMCommand): @@ -237,7 +237,8 @@ def _list_outputs(self): break if self.inputs.jobtype == "estimate": outputs['realigned_files'] = self.inputs.in_files - if self.inputs.jobtype == "estimate" or self.inputs.jobtype == "estwrite": + if (self.inputs.jobtype == "estimate" or + self.inputs.jobtype == "estwrite"): outputs['modified_in_files'] = self.inputs.in_files if self.inputs.jobtype == "write" or self.inputs.jobtype == "estwrite": if isinstance(self.inputs.in_files[0], list): @@ -246,7 +247,8 @@ def _list_outputs(self): first_image = self.inputs.in_files[0] if resliced_mean: - outputs['mean_image'] = fname_presuffix(first_image, prefix='mean') + outputs['mean_image'] = fname_presuffix(first_image, + prefix='mean') if resliced_all: outputs['realigned_files'] = [] @@ -254,12 +256,12 @@ def _list_outputs(self): realigned_run = [] if isinstance(imgf, list): for i, inner_imgf in enumerate(filename_to_list(imgf)): - newfile = fname_presuffix(inner_imgf, - prefix=self.inputs.out_prefix) + newfile = fname_presuffix( + inner_imgf, prefix=self.inputs.out_prefix) realigned_run.append(newfile) else: - realigned_run = fname_presuffix(imgf, - prefix=self.inputs.out_prefix) + realigned_run = fname_presuffix( + imgf, prefix=self.inputs.out_prefix) outputs['realigned_files'].append(realigned_run) return outputs @@ -278,7 +280,8 @@ class CoregisterInputSpec(SPMCommandInputSpec): copyfile=True) cost_function = traits.Enum('mi', 'nmi', 'ecc', 'ncc', field='eoptions.cost_fun', - desc="""cost function, one of: 'mi' - Mutual Information, + desc="""cost function, one of: + 'mi' - Mutual Information, 'nmi' - Normalised Mutual Information, 'ecc' - Entropy Correlation Coefficient, 'ncc' - Normalised Cross Correlation""") @@ -290,10 +293,12 @@ class CoregisterInputSpec(SPMCommandInputSpec): tolerance = traits.List(traits.Float(), field='eoptions.tol', desc='acceptable tolerance for each of 12 params') write_interp = traits.Range(low=0, high=7, field='roptions.interp', - desc='degree of b-spline used for interpolation') + desc=('degree of b-spline used for ' + 'interpolation')) write_wrap = traits.List(traits.Int(), minlen=3, maxlen=3, field='roptions.wrap', - desc='Check if interpolation should wrap in [x,y,z]') + desc=('Check if interpolation should wrap in ' + '[x,y,z]')) write_mask = traits.Bool(field='roptions.mask', desc='True/False mask output image') out_prefix = traits.String('r', field='roptions.prefix', usedefault=True, @@ -331,7 +336,8 @@ class Coregister(SPMCommand): def _format_arg(self, opt, spec, val): """Convert input to appropriate format for spm """ - if opt == 'target' or (opt == 'source' and self.inputs.jobtype != "write"): + if (opt == 'target' or + (opt == 'source' and self.inputs.jobtype != "write")): return scans_for_fnames(filename_to_list(val), keep4d=True) if opt == 'apply_to_files': @@ -360,7 +366,8 @@ def _list_outputs(self): if isdefined(self.inputs.apply_to_files): outputs['coregistered_files'] = self.inputs.apply_to_files outputs['coregistered_source'] = self.inputs.source - elif self.inputs.jobtype == "write" or self.inputs.jobtype == "estwrite": + elif (self.inputs.jobtype == "write" + or self.inputs.jobtype == "estwrite"): if isdefined(self.inputs.apply_to_files): outputs['coregistered_files'] = [] for imgf in filename_to_list(self.inputs.apply_to_files): @@ -391,11 +398,14 @@ class NormalizeInputSpec(SPMCommandInputSpec): copyfile=True) parameter_file = File(field='subj.matname', mandatory=True, xor=['source', 'template'], - desc='normalization parameter file*_sn.mat', copyfile=False) + desc='normalization parameter file*_sn.mat', + copyfile=False) source_weight = File(field='subj.wtsrc', - desc='name of weighting image for source', copyfile=False) + desc='name of weighting image for source', + copyfile=False) template_weight = File(field='eoptions.weight', - desc='name of weighting image for template', copyfile=False) + desc='name of weighting image for template', + copyfile=False) source_image_smoothing = traits.Float(field='eoptions.smosrc', desc='source smoothing') template_image_smoothing = traits.Float(field='eoptions.smoref', @@ -406,9 +416,13 @@ class NormalizeInputSpec(SPMCommandInputSpec): DCT_period_cutoff = traits.Float(field='eoptions.cutoff', desc='Cutoff of for DCT bases') nonlinear_iterations = traits.Int(field='eoptions.nits', - desc='Number of iterations of nonlinear warping') + desc=('Number of iterations of ' + 'nonlinear warping')) nonlinear_regularization = traits.Float(field='eoptions.reg', - desc='the amount of the regularization for the nonlinear part of the normalization') + desc=('the amount of the ' + 'regularization for the ' + 'nonlinear part of the ' + 'normalization')) write_preserve = traits.Bool(field='roptions.preserve', desc='True/False warped images are modulated') write_bounding_box = traits.List(traits.List(traits.Float(), minlen=3, @@ -419,17 +433,20 @@ class NormalizeInputSpec(SPMCommandInputSpec): minlen=3, maxlen=3, desc='3-element list') write_interp = traits.Range(low=0, high=7, field='roptions.interp', - desc='degree of b-spline used for interpolation') + desc=('degree of b-spline used for ' + 'interpolation')) write_wrap = traits.List(traits.Int(), field='roptions.wrap', - desc=('Check if interpolation should wrap in [x,y,z]' - '- list of bools')) + desc=('Check if interpolation should wrap in ' + '[x,y,z] - list of bools')) out_prefix = traits.String('w', field='roptions.prefix', usedefault=True, desc='normalized output prefix') class NormalizeOutputSpec(TraitedSpec): normalization_parameters = OutputMultiPath(File(exists=True), - desc='MAT files containing the normalization parameters') + desc=('MAT files containing ' + 'the normalization ' + 'parameters')) normalized_source = OutputMultiPath(File(exists=True), desc='Normalized source files') normalized_files = OutputMultiPath(File(exists=True), @@ -505,7 +522,8 @@ def _list_outputs(self): outputs['normalized_files'] = self.inputs.apply_to_files outputs['normalized_source'] = self.inputs.source elif 'write' in self.inputs.jobtype: - if isdefined(self.inputs.write_preserve) and self.inputs.write_preserve: + if (isdefined(self.inputs.write_preserve) + and self.inputs.write_preserve): prefixNorm = ''.join(['m', self.inputs.out_prefix]) else: prefixNorm = self.inputs.out_prefix @@ -514,7 +532,8 @@ def _list_outputs(self): filelist = filename_to_list(self.inputs.apply_to_files) for f in filelist: if isinstance(f, list): - run = [fname_presuffix(in_f, prefix=prefixNorm) for in_f in f] + run = [fname_presuffix(in_f, prefix=prefixNorm) + for in_f in f] else: run = [fname_presuffix(f, prefix=prefixNorm)] outputs['normalized_files'].extend(run) @@ -529,7 +548,8 @@ def _list_outputs(self): class Normalize12InputSpec(SPMCommandInputSpec): image_to_align = File(exists=True, field='subj.vol', - desc='file to estimate normalization parameters with', + desc=('file to estimate normalization parameters ' + 'with'), xor=['deformation_file'], mandatory=True, copyfile=True) apply_to_files = InputMultiPath(traits.Either(File(exists=True), @@ -539,8 +559,9 @@ class Normalize12InputSpec(SPMCommandInputSpec): copyfile=True) deformation_file = File(field='subj.def', mandatory=True, xor=['image_to_align', 'tpm'], - desc=('file y_*.nii containing 3 deformation fields ' - 'for the deformation in x, y and z dimension'), + desc=('file y_*.nii containing 3 deformation ' + 'fields for the deformation in x, y and z ' + 'dimension'), copyfile=False) jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True, desc='Estimate, Write or do Both') @@ -551,7 +572,8 @@ class Normalize12InputSpec(SPMCommandInputSpec): 140, 150, 'Inf', field='eoptions.biasfwhm', desc='FWHM of Gaussian smoothness of bias') tpm = File(exists=True, field='eoptions.tpm', - desc='template in form of tissue probablitiy maps to normalize to', + desc=('template in form of tissue probablitiy maps to ' + 'normalize to'), xor=['deformation_file'], copyfile=False) affine_regularization_type = traits.Enum('mni', 'size', 'none', @@ -570,15 +592,17 @@ class Normalize12InputSpec(SPMCommandInputSpec): write_bounding_box = traits.List(traits.List(traits.Float(), minlen=3, maxlen=3), field='woptions.bb', minlen=2, maxlen=2, - desc=('3x2-element list of lists representing ' - 'the bounding box (in mm) to be written')) + desc=('3x2-element list of lists ' + 'representing the bounding box ' + '(in mm) to be written')) write_voxel_sizes = traits.List(traits.Float(), field='woptions.vox', minlen=3, maxlen=3, desc=('3-element list representing the ' 'voxel sizes (in mm) of the written ' 'normalised images')) write_interp = traits.Range(low=0, high=7, field='woptions.interp', - desc='degree of b-spline used for interpolation') + desc=('degree of b-spline used for ' + 'interpolation')) class Normalize12OutputSpec(TraitedSpec): From e643da4555afe9a6f68b89c4efad0c0d0772eaab Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Sun, 28 Aug 2016 15:40:48 -0400 Subject: [PATCH 11/15] PEP8 compliance for preproc (60%) --- nipype/interfaces/spm/preprocess.py | 152 ++++++++++++++++++---------- 1 file changed, 100 insertions(+), 52 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index b89d9a1f3d..fafeeff5b8 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -60,7 +60,7 @@ class SliceTimingInputSpec(SPMCommandInputSpec): class SliceTimingOutputSpec(TraitedSpec): timecorrected_files = OutputMultiPath( traits.Either(traits.List(File(exists=True)), File(exists=True)), - desc='slice time corrected files') + desc='slice time corrected files') class SliceTiming(SPMCommand): @@ -366,8 +366,8 @@ def _list_outputs(self): if isdefined(self.inputs.apply_to_files): outputs['coregistered_files'] = self.inputs.apply_to_files outputs['coregistered_source'] = self.inputs.source - elif (self.inputs.jobtype == "write" - or self.inputs.jobtype == "estwrite"): + elif (self.inputs.jobtype == "write" or + self.inputs.jobtype == "estwrite"): if isdefined(self.inputs.apply_to_files): outputs['coregistered_files'] = [] for imgf in filename_to_list(self.inputs.apply_to_files): @@ -522,8 +522,8 @@ def _list_outputs(self): outputs['normalized_files'] = self.inputs.apply_to_files outputs['normalized_source'] = self.inputs.source elif 'write' in self.inputs.jobtype: - if (isdefined(self.inputs.write_preserve) - and self.inputs.write_preserve): + if (isdefined(self.inputs.write_preserve) and + self.inputs.write_preserve): prefixNorm = ''.join(['m', self.inputs.out_prefix]) else: prefixNorm = self.inputs.out_prefix @@ -607,9 +607,10 @@ class Normalize12InputSpec(SPMCommandInputSpec): class Normalize12OutputSpec(TraitedSpec): deformation_field = OutputMultiPath(File(exists=True), - desc=('NIfTI file containing 3 deformation ' - 'fields for the deformation in ' - 'x, y and z dimension')) + desc=('NIfTI file containing 3 ' + 'deformation fields for the ' + 'deformation in x, y and z ' + 'dimension')) normalized_image = OutputMultiPath(File(exists=True), desc=('Normalized file that needed to ' 'be aligned')) @@ -708,9 +709,11 @@ def _list_outputs(self): class SegmentInputSpec(SPMCommandInputSpec): - data = InputMultiPath(File(exists=True), field='data', desc='one scan per subject', + data = InputMultiPath(File(exists=True), field='data', + desc='one scan per subject', copyfile=False, mandatory=True) - gm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, field='output.GM', + gm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, + field='output.GM', desc="""Options to produce grey matter images: c1*.img, wc1*.img and mwc1*.img. None: [False,False,False], Native Space: [False,False,True], @@ -720,7 +723,8 @@ class SegmentInputSpec(SPMCommandInputSpec): Native + Modulated Normalised: [True,False,True], Native + Modulated + Unmodulated: [True,True,True], Modulated + Unmodulated Normalised: [True,True,False]""") - wm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, field='output.WM', + wm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, + field='output.WM', desc="""Options to produce white matter images: c2*.img, wc2*.img and mwc2*.img. None: [False,False,False], Native Space: [False,False,True], @@ -742,24 +746,36 @@ class SegmentInputSpec(SPMCommandInputSpec): Modulated + Unmodulated Normalised: [True,True,False]""") save_bias_corrected = traits.Bool(field='output.biascor', desc='True/False produce a bias corrected image') - clean_masks = traits.Enum('no', 'light', 'thorough', field='output.cleanup', - desc="clean using estimated brain mask ('no','light','thorough')") + clean_masks = traits.Enum('no', 'light', 'thorough', + field='output.cleanup', + desc=("clean using estimated brain mask " + "('no','light','thorough')")) tissue_prob_maps = traits.List(File(exists=True), field='opts.tpm', - desc='list of gray, white & csf prob. (opt,)') + desc=('list of gray, white & csf prob. ' + '(opt,)')) gaussians_per_class = traits.List(traits.Int(), field='opts.ngaus', - desc='num Gaussians capture intensity distribution') - affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', '', field='opts.regtype', - desc='Possible options: "mni", "eastern", "subj", "none" (no reguralisation), "" (no affine registration)') + desc=('num Gaussians capture intensity ' + 'distribution')) + affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', '', + field='opts.regtype', + desc=('Possible options: "mni", ' + '"eastern", "subj", "none" ' + '(no reguralisation), "" ' + '(no affine registration)')) warping_regularization = traits.Float(field='opts.warpreg', - desc='Controls balance between parameters and data') - warp_frequency_cutoff = traits.Float(field='opts.warpco', desc='Cutoff of DCT bases') - bias_regularization = traits.Enum(0, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, field='opts.biasreg', + desc=('Controls balance between ' + 'parameters and data')) + warp_frequency_cutoff = traits.Float(field='opts.warpco', + desc='Cutoff of DCT bases') + bias_regularization = traits.Enum(0, 0.00001, 0.0001, 0.001, + 0.01, 0.1, 1, 10, field='opts.biasreg', desc='no(0) - extremely heavy (10)') bias_fwhm = traits.Enum(30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 'Inf', field='opts.biasfwhm', desc='FWHM of Gaussian smoothness of bias') sampling_distance = traits.Float(field='opts.samp', - desc='Sampling distance on data for parameter estimation') + desc=('Sampling distance on data for ' + 'parameter estimation')) mask_image = File(exists=True, field='opts.msk', desc='Binary image to restrict parameter estimation ') @@ -767,13 +783,16 @@ class SegmentInputSpec(SPMCommandInputSpec): class SegmentOutputSpec(TraitedSpec): native_gm_image = File(desc='native space grey probability map') normalized_gm_image = File(desc='normalized grey probability map',) - modulated_gm_image = File(desc='modulated, normalized grey probability map') + modulated_gm_image = File(desc=('modulated, normalized grey ' + 'probability map')) native_wm_image = File(desc='native space white probability map') normalized_wm_image = File(desc='normalized white probability map') - modulated_wm_image = File(desc='modulated, normalized white probability map') + modulated_wm_image = File(desc=('modulated, normalized white ' + 'probability map')) native_csf_image = File(desc='native space csf probability map') normalized_csf_image = File(desc='normalized csf probability map') - modulated_csf_image = File(desc='modulated, normalized csf probability map') + modulated_csf_image = File(desc=('modulated, normalized csf ' + 'probability map')) modulated_input_image = File(deprecated='0.10', new_name='bias_corrected_image', desc='bias-corrected version of input image') @@ -874,31 +893,44 @@ class NewSegmentInputSpec(SPMCommandInputSpec): - which maps to save [Native, DARTEL] - a tuple of two boolean values - which maps to save [Unmodulated, Modulated] - a tuple of two boolean values""", field='tissue') - affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', field='warp.affreg', + affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', + field='warp.affreg', desc='mni, eastern, subj, none ') warping_regularization = traits.Float(field='warp.reg', - desc='Aproximate distance between sampling points.') + desc=('Aproximate distance between ' + 'sampling points.')) sampling_distance = traits.Float(field='warp.samp', - desc='Sampling distance on data for parameter estimation') - write_deformation_fields = traits.List(traits.Bool(), minlen=2, maxlen=2, field='warp.write', - desc="Which deformation fields to write:[Inverse, Forward]") + desc=('Sampling distance on data for ' + 'parameter estimation')) + write_deformation_fields = traits.List(traits.Bool(), minlen=2, maxlen=2, + field='warp.write', + desc=("Which deformation fields to " + "write:[Inverse, Forward]")) class NewSegmentOutputSpec(TraitedSpec): - native_class_images = traits.List(traits.List(File(exists=True)), desc='native space probability maps') - dartel_input_images = traits.List(traits.List(File(exists=True)), desc='dartel imported class images') - normalized_class_images = traits.List(traits.List(File(exists=True)), desc='normalized class images') - modulated_class_images = traits.List(traits.List(File(exists=True)), desc='modulated+normalized class images') - transformation_mat = OutputMultiPath(File(exists=True), desc='Normalization transformation') - bias_corrected_images = OutputMultiPath(File(exists=True), desc='bias corrected images') - bias_field_images = OutputMultiPath(File(exists=True), desc='bias field images') + native_class_images = traits.List(traits.List(File(exists=True)), + desc='native space probability maps') + dartel_input_images = traits.List(traits.List(File(exists=True)), + desc='dartel imported class images') + normalized_class_images = traits.List(traits.List(File(exists=True)), + desc='normalized class images') + modulated_class_images = traits.List(traits.List(File(exists=True)), + desc=('modulated+normalized class ' + 'images')) + transformation_mat = OutputMultiPath(File(exists=True), + desc='Normalization transformation') + bias_corrected_images = OutputMultiPath(File(exists=True), + desc='bias corrected images') + bias_field_images = OutputMultiPath(File(exists=True), + desc='bias field images') forward_deformation_field = OutputMultiPath(File(exists=True)) inverse_deformation_field = OutputMultiPath(File(exists=True)) class NewSegment(SPMCommand): - """Use spm_preproc8 (New Segment) to separate structural images into different - tissue classes. Supports multiple modalities. + """Use spm_preproc8 (New Segment) to separate structural images into + different tissue classes. Supports multiple modalities. NOTE: This interface currently supports single channel input only @@ -959,14 +991,18 @@ def _format_arg(self, opt, spec, val): new_tissues = [] for tissue in val: new_tissue = {} - new_tissue['tpm'] = np.array([','.join([tissue[0][0], str(tissue[0][1])])], dtype=object) + new_tissue['tpm'] = np.array([','.join([tissue[0][0], + str(tissue[0][1])])], + dtype=object) new_tissue['ngaus'] = tissue[1] new_tissue['native'] = [int(tissue[2][0]), int(tissue[2][1])] new_tissue['warped'] = [int(tissue[3][0]), int(tissue[3][1])] new_tissues.append(new_tissue) return new_tissues elif opt == 'write_deformation_fields': - return super(NewSegment, self)._format_arg(opt, spec, [int(val[0]), int(val[1])]) + return super(NewSegment, self)._format_arg(opt, spec, + [int(val[0]), + int(val[1])]) else: return super(NewSegment, self)._format_arg(opt, spec, val) @@ -1080,14 +1116,16 @@ def _list_outputs(self): outputs['smoothed_files'] = [] for imgf in filename_to_list(self.inputs.in_files): - outputs['smoothed_files'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix)) + outputs['smoothed_files'].append( + fname_presuffix(imgf, prefix=self.inputs.out_prefix)) return outputs class DARTELInputSpec(SPMCommandInputSpec): image_files = traits.List(traits.List(File(exists=True)), desc="A list of files to be segmented", - field='warp.images', copyfile=False, mandatory=True) + field='warp.images', copyfile=False, + mandatory=True) template_prefix = traits.Str('Template', usedefault=True, field='warp.settings.template', desc='Prefix for template') @@ -1101,8 +1139,8 @@ class DARTELInputSpec(SPMCommandInputSpec): traits.Enum(1, 2, 4, 8, 16, 32, 64, 128, 256, 512), - traits.Enum(0, 0.5, 1, 2, 4, - 8, 16, 32)), + traits.Enum(0, 0.5, 1, 2, + 4, 8, 16, 32)), minlen=3, maxlen=12, field='warp.settings.param', @@ -1124,8 +1162,11 @@ class DARTELInputSpec(SPMCommandInputSpec): class DARTELOutputSpec(TraitedSpec): final_template_file = File(exists=True, desc='final DARTEL template') - template_files = traits.List(File(exists=True), desc='Templates from different stages of iteration') - dartel_flow_fields = traits.List(File(exists=True), desc='DARTEL flow fields') + template_files = traits.List(File(exists=True), + desc=('Templates from different stages of ' + 'iteration')) + dartel_flow_fields = traits.List(File(exists=True), + desc='DARTEL flow fields') class DARTEL(SPMCommand): @@ -1193,7 +1234,8 @@ def _list_outputs(self): class DARTELNorm2MNIInputSpec(SPMCommandInputSpec): template_file = File(exists=True, desc="DARTEL template", - field='mni_norm.template', copyfile=False, mandatory=True) + field='mni_norm.template', copyfile=False, + mandatory=True) flowfield_files = InputMultiPath(File(exists=True), desc="DARTEL flow fields u_rc1*", field='mni_norm.data.subjs.flowfields', @@ -1210,15 +1252,19 @@ class DARTELNorm2MNIInputSpec(SPMCommandInputSpec): desc="Voxel sizes for output file", field='mni_norm.bb') modulate = traits.Bool(field='mni_norm.preserve', - desc="Modulate out images - no modulation preserves concentrations") + desc=("Modulate out images - no modulation " + "preserves concentrations")) fwhm = traits.Either(traits.List(traits.Float(), minlen=3, maxlen=3), traits.Float(), field='mni_norm.fwhm', desc='3-list of fwhm for each dimension') class DARTELNorm2MNIOutputSpec(TraitedSpec): - normalized_files = OutputMultiPath(File(exists=True), desc='Normalized files in MNI space') - normalization_parameter_file = File(exists=True, desc='Transform parameters to MNI space') + normalized_files = OutputMultiPath(File(exists=True), + desc='Normalized files in MNI space') + normalization_parameter_file = File(exists=True, + desc=('Transform parameters to MNI ' + 'space')) class DARTELNorm2MNI(SPMCommand): @@ -1354,7 +1400,8 @@ def _list_outputs(self): class ApplyDeformationFieldInputSpec(SPMCommandInputSpec): - in_files = InputMultiPath(File(exists=True), mandatory=True, field='fnames') + in_files = InputMultiPath(File(exists=True), mandatory=True, + field='fnames') deformation_field = File(exists=True, mandatory=True, field='comp{1}.def') reference_volume = File(exists=True, mandatory=True, field='comp{2}.id.space') @@ -1511,7 +1558,8 @@ class VBMSegmentOuputSpec(TraitedSpec): normalized_class_images = traits.List(traits.List(File(exists=True)), desc='normalized class images') modulated_class_images = traits.List(traits.List(File(exists=True)), - desc='modulated+normalized class images') + desc=('modulated+normalized class ' + 'images')) transformation_mat = OutputMultiPath(File(exists=True), desc='Normalization transformation') From 37c5296370cf65c6423df0687d614a0153955c57 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Sun, 28 Aug 2016 16:09:37 -0400 Subject: [PATCH 12/15] PEP8 compliance for preproc (85%) --- nipype/interfaces/spm/preprocess.py | 159 ++++++++++++++++------------ 1 file changed, 93 insertions(+), 66 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index fafeeff5b8..dca75e1c8d 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -353,7 +353,8 @@ def _parse_inputs(self): """validate spm coregister options if set to None ignore """ if self.inputs.jobtype == "write": - einputs = super(Coregister, self)._parse_inputs(skip=('jobtype', 'apply_to_files')) + einputs = (super(Coregister, self) + ._parse_inputs(skip=('jobtype', 'apply_to_files'))) else: einputs = super(Coregister, self)._parse_inputs(skip=('jobtype')) jobtype = self.inputs.jobtype @@ -371,11 +372,14 @@ def _list_outputs(self): if isdefined(self.inputs.apply_to_files): outputs['coregistered_files'] = [] for imgf in filename_to_list(self.inputs.apply_to_files): - outputs['coregistered_files'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix)) + (outputs['coregistered_files'] + .append(fname_presuffix(imgf, + prefix=self.inputs.out_prefix))) outputs['coregistered_source'] = [] for imgf in filename_to_list(self.inputs.source): - outputs['coregistered_source'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix)) + (outputs['coregistered_source'] + .append(fname_presuffix(imgf, prefix=self.inputs.out_prefix))) return outputs @@ -391,11 +395,11 @@ class NormalizeInputSpec(SPMCommandInputSpec): mandatory=True, copyfile=True) jobtype = traits.Enum('estwrite', 'est', 'write', usedefault=True, desc='Estimate, Write or do both') - apply_to_files = InputMultiPath(traits.Either(File(exists=True), - traits.List(File(exists=True))), - field='subj.resample', - desc='files to apply transformation to', - copyfile=True) + apply_to_files = InputMultiPath( + traits.Either(File(exists=True), traits.List(File(exists=True))), + field='subj.resample', + desc='files to apply transformation to', + copyfile=True) parameter_file = File(field='subj.matname', mandatory=True, xor=['source', 'template'], desc='normalization parameter file*_sn.mat', @@ -502,7 +506,8 @@ def _parse_inputs(self): if jobtype in ['estwrite', 'write']: if not isdefined(self.inputs.apply_to_files): if isdefined(self.inputs.source): - einputs[0]['subj']['resample'] = scans_for_fname(self.inputs.source) + einputs[0]['subj']['resample'] = scans_for_fname( + self.inputs.source) return [{'%s' % (jobtype): einputs[0]}] def _list_outputs(self): @@ -512,10 +517,10 @@ def _list_outputs(self): if jobtype.startswith('est'): outputs['normalization_parameters'] = [] for imgf in filename_to_list(self.inputs.source): - outputs['normalization_parameters'].append(fname_presuffix(imgf, - suffix='_sn.mat', - use_ext=False)) - outputs['normalization_parameters'] = list_to_filename(outputs['normalization_parameters']) + outputs['normalization_parameters'].append( + fname_presuffix(imgf, suffix='_sn.mat', use_ext=False)) + outputs['normalization_parameters'] = list_to_filename( + outputs['normalization_parameters']) if self.inputs.jobtype == "estimate": if isdefined(self.inputs.apply_to_files): @@ -540,8 +545,8 @@ def _list_outputs(self): if isdefined(self.inputs.source): outputs['normalized_source'] = [] for imgf in filename_to_list(self.inputs.source): - outputs['normalized_source'].append(fname_presuffix(imgf, - prefix=prefixNorm)) + outputs['normalized_source'].append( + fname_presuffix(imgf, prefix=prefixNorm)) return outputs @@ -552,11 +557,11 @@ class Normalize12InputSpec(SPMCommandInputSpec): 'with'), xor=['deformation_file'], mandatory=True, copyfile=True) - apply_to_files = InputMultiPath(traits.Either(File(exists=True), - traits.List(File(exists=True))), - field='subj.resample', - desc='files to apply transformation to', - copyfile=True) + apply_to_files = InputMultiPath( + traits.Either(File(exists=True), traits.List(File(exists=True))), + field='subj.resample', + desc='files to apply transformation to', + copyfile=True) deformation_file = File(field='subj.def', mandatory=True, xor=['image_to_align', 'tpm'], desc=('file y_*.nii containing 3 deformation ' @@ -661,8 +666,8 @@ def _format_arg(self, opt, spec, val): def _parse_inputs(self, skip=()): """validate spm normalize options if set to None ignore """ - einputs = super(Normalize12, self)._parse_inputs(skip=('jobtype', - 'apply_to_files')) + einputs = super(Normalize12, self)._parse_inputs( + skip=('jobtype', 'apply_to_files')) if isdefined(self.inputs.apply_to_files): inputfiles = deepcopy(self.inputs.apply_to_files) if isdefined(self.inputs.image_to_align): @@ -672,7 +677,8 @@ def _parse_inputs(self, skip=()): if jobtype in ['estwrite', 'write']: if not isdefined(self.inputs.apply_to_files): if isdefined(self.inputs.image_to_align): - einputs[0]['subj']['resample'] = scans_for_fname(self.inputs.image_to_align) + einputs[0]['subj']['resample'] = scans_for_fname( + self.inputs.image_to_align) return [{'%s' % (jobtype): einputs[0]}] def _list_outputs(self): @@ -682,15 +688,16 @@ def _list_outputs(self): if jobtype.startswith('est'): outputs['deformation_field'] = [] for imgf in filename_to_list(self.inputs.image_to_align): - outputs['deformation_field'].append(fname_presuffix(imgf, - prefix='y_')) - outputs['deformation_field'] = list_to_filename(outputs['deformation_field']) + outputs['deformation_field'].append( + fname_presuffix(imgf, prefix='y_')) + outputs['deformation_field'] = list_to_filename( + outputs['deformation_field']) if self.inputs.jobtype == "estimate": if isdefined(self.inputs.apply_to_files): outputs['normalized_files'] = self.inputs.apply_to_files - outputs['normalized_image'] = fname_presuffix(self.inputs.image_to_align, - prefix='w') + outputs['normalized_image'] = fname_presuffix( + self.inputs.image_to_align, prefix='w') elif 'write' in self.inputs.jobtype: outputs['normalized_files'] = [] if isdefined(self.inputs.apply_to_files): @@ -702,8 +709,8 @@ def _list_outputs(self): run = [fname_presuffix(f, prefix='w')] outputs['normalized_files'].extend(run) if isdefined(self.inputs.image_to_align): - outputs['normalized_image'] = fname_presuffix(self.inputs.image_to_align, - prefix='w') + outputs['normalized_image'] = fname_presuffix( + self.inputs.image_to_align, prefix='w') return outputs @@ -745,7 +752,8 @@ class SegmentInputSpec(SPMCommandInputSpec): Native + Modulated + Unmodulated: [True,True,True], Modulated + Unmodulated Normalised: [True,True,False]""") save_bias_corrected = traits.Bool(field='output.biascor', - desc='True/False produce a bias corrected image') + desc=('True/False produce a bias ' + 'corrected image')) clean_masks = traits.Enum('no', 'light', 'thorough', field='output.cleanup', desc=("clean using estimated brain mask " @@ -861,9 +869,8 @@ def _list_outputs(self): ('native', '')]): if getattr(self.inputs, outtype)[idx]: outfield = '%s_%s_image' % (image, tissue) - outputs[outfield] = fname_presuffix(f, - prefix='%sc%d' % (prefix, - tidx + 1)) + outputs[outfield] = fname_presuffix( + f, prefix='%sc%d' % (prefix, tidx + 1)) if isdefined(self.inputs.save_bias_corrected) and \ self.inputs.save_bias_corrected: outputs['bias_corrected_image'] = fname_presuffix(f, prefix='m') @@ -877,7 +884,8 @@ def _list_outputs(self): class NewSegmentInputSpec(SPMCommandInputSpec): channel_files = InputMultiPath(File(exists=True), desc="A list of files to be segmented", - field='channel', copyfile=False, mandatory=True) + field='channel', copyfile=False, + mandatory=True) channel_info = traits.Tuple(traits.Float(), traits.Float(), traits.Tuple(traits.Bool, traits.Bool), desc="""A tuple with the following fields: @@ -885,14 +893,16 @@ class NewSegmentInputSpec(SPMCommandInputSpec): - FWHM of Gaussian smoothness of bias - which maps to save (Corrected, Field) - a tuple of two boolean values""", field='channel') - tissues = traits.List(traits.Tuple(traits.Tuple(File(exists=True), traits.Int()), traits.Int(), - traits.Tuple(traits.Bool, traits.Bool), traits.Tuple(traits.Bool, traits.Bool)), - desc="""A list of tuples (one per tissue) with the following fields: + tissues = traits.List( + traits.Tuple(traits.Tuple(File(exists=True), traits.Int()), + traits.Int(), traits.Tuple(traits.Bool, traits.Bool), + traits.Tuple(traits.Bool, traits.Bool)), + desc="""A list of tuples (one per tissue) with the following fields: - tissue probability map (4D), 1-based index to frame - number of gaussians - which maps to save [Native, DARTEL] - a tuple of two boolean values - which maps to save [Unmodulated, Modulated] - a tuple of two boolean values""", - field='tissue') + field='tissue') affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', field='warp.affreg', desc='mni, eastern, subj, none ') @@ -978,7 +988,7 @@ def _format_arg(self, opt, spec, val): """ if opt in ['channel_files', 'channel_info']: - # structure have to be recreated, because of some weird traits error + # structure have to be recreated because of some weird traits error new_channel = {} new_channel['vols'] = scans_for_fnames(self.inputs.channel_files) if isdefined(self.inputs.channel_info): @@ -1032,29 +1042,39 @@ def _list_outputs(self): if isdefined(self.inputs.tissues): for i, tissue in enumerate(self.inputs.tissues): if tissue[2][0]: - outputs['native_class_images'][i].append(os.path.join(pth, "c%d%s.nii" % (i + 1, base))) + outputs['native_class_images'][i].append( + os.path.join(pth, "c%d%s.nii" % (i + 1, base))) if tissue[2][1]: - outputs['dartel_input_images'][i].append(os.path.join(pth, "rc%d%s.nii" % (i + 1, base))) + outputs['dartel_input_images'][i].append( + os.path.join(pth, "rc%d%s.nii" % (i + 1, base))) if tissue[3][0]: - outputs['normalized_class_images'][i].append(os.path.join(pth, "wc%d%s.nii" % (i + 1, base))) + outputs['normalized_class_images'][i].append( + os.path.join(pth, "wc%d%s.nii" % (i + 1, base))) if tissue[3][1]: - outputs['modulated_class_images'][i].append(os.path.join(pth, "mwc%d%s.nii" % (i + 1, base))) + outputs['modulated_class_images'][i].append( + os.path.join(pth, "mwc%d%s.nii" % (i + 1, base))) else: for i in range(n_classes): - outputs['native_class_images'][i].append(os.path.join(pth, "c%d%s.nii" % (i + 1, base))) - outputs['transformation_mat'].append(os.path.join(pth, "%s_seg8.mat" % base)) + outputs['native_class_images'][i].append( + os.path.join(pth, "c%d%s.nii" % (i + 1, base))) + outputs['transformation_mat'].append( + os.path.join(pth, "%s_seg8.mat" % base)) if isdefined(self.inputs.write_deformation_fields): if self.inputs.write_deformation_fields[0]: - outputs['inverse_deformation_field'].append(os.path.join(pth, "iy_%s.nii" % base)) + outputs['inverse_deformation_field'].append( + os.path.join(pth, "iy_%s.nii" % base)) if self.inputs.write_deformation_fields[1]: - outputs['forward_deformation_field'].append(os.path.join(pth, "y_%s.nii" % base)) + outputs['forward_deformation_field'].append( + os.path.join(pth, "y_%s.nii" % base)) if isdefined(self.inputs.channel_info): if self.inputs.channel_info[2][0]: - outputs['bias_corrected_images'].append(os.path.join(pth, "m%s.nii" % (base))) + outputs['bias_corrected_images'].append( + os.path.join(pth, "m%s.nii" % (base))) if self.inputs.channel_info[2][1]: - outputs['bias_field_images'].append(os.path.join(pth, "BiasField_%s.nii" % (base))) + outputs['bias_field_images'].append( + os.path.join(pth, "BiasField_%s.nii" % (base))) return outputs @@ -1131,7 +1151,8 @@ class DARTELInputSpec(SPMCommandInputSpec): desc='Prefix for template') regularization_form = traits.Enum('Linear', 'Membrane', 'Bending', field='warp.settings.rform', - desc='Form of regularization energy term') + desc=('Form of regularization energy ' + 'term')) iteration_parameters = traits.List(traits.Tuple(traits.Range(1, 10), traits.Tuple(traits.Float, traits.Float, @@ -1220,14 +1241,18 @@ def _list_outputs(self): outputs = self._outputs().get() outputs['template_files'] = [] for i in range(6): - outputs['template_files'].append(os.path.realpath('%s_%d.nii' % (self.inputs.template_prefix, i + 1))) - outputs['final_template_file'] = os.path.realpath('%s_6.nii' % self.inputs.template_prefix) + outputs['template_files'].append( + os.path.realpath( + '%s_%d.nii' % (self.inputs.template_prefix, i + 1))) + outputs['final_template_file'] = os.path.realpath( + '%s_6.nii' % self.inputs.template_prefix) outputs['dartel_flow_fields'] = [] for filename in self.inputs.image_files[0]: pth, base, ext = split_filename(filename) - outputs['dartel_flow_fields'].append(os.path.realpath('u_%s_%s%s' % (base, - self.inputs.template_prefix, - ext))) + outputs['dartel_flow_fields'].append( + os.path.realpath('u_%s_%s%s' % (base, + self.inputs.template_prefix, + ext))) return outputs @@ -1313,7 +1338,8 @@ def _format_arg(self, opt, spec, val): def _list_outputs(self): outputs = self._outputs().get() pth, base, ext = split_filename(self.inputs.template_file) - outputs['normalization_parameter_file'] = os.path.realpath(base + '_2mni.mat') + outputs['normalization_parameter_file'] = os.path.realpath( + base + '_2mni.mat') outputs['normalized_files'] = [] prefix = "w" if isdefined(self.inputs.modulate) and self.inputs.modulate: @@ -1322,9 +1348,8 @@ def _list_outputs(self): prefix = 's' + prefix for filename in self.inputs.apply_to_files: pth, base, ext = split_filename(filename) - outputs['normalized_files'].append(os.path.realpath('%s%s%s' % (prefix, - base, - ext))) + outputs['normalized_files'].append( + os.path.realpath('%s%s%s' % (prefix, base, ext))) return outputs @@ -1391,11 +1416,11 @@ def _list_outputs(self): for filename in self.inputs.image_files: pth, base, ext = split_filename(filename) if isdefined(self.inputs.modulate) and self.inputs.modulate: - outputs['warped_files'].append(os.path.realpath('mw%s%s' % (base, - ext))) + outputs['warped_files'].append( + os.path.realpath('mw%s%s' % (base, ext))) else: - outputs['warped_files'].append(os.path.realpath('w%s%s' % (base, - ext))) + outputs['warped_files'].append( + os.path.realpath('w%s%s' % (base, ext))) return outputs @@ -1706,7 +1731,8 @@ def _format_arg(self, opt, spec, val): elif opt in ['dartel_template']: return np.array([val], dtype=object) elif opt in ['deformation_field']: - return super(VBMSegment, self)._format_arg(opt, spec, [int(val[0]), int(val[1])]) + return super(VBMSegment, self)._format_arg( + opt, spec, [int(val[0]), int(val[1])]) else: return super(VBMSegment, self)._format_arg(opt, spec, val) @@ -1717,4 +1743,5 @@ def _parse_inputs(self): einputs[0]['estwrite']['extopts']['dartelwarp'] = {'normlow': 1} return einputs else: - return super(VBMSegment, self)._parse_inputs(skip=('spatial_normalization')) + return super(VBMSegment, self)._parse_inputs( + skip=('spatial_normalization')) From 258d7726decbab9bef1bf5f66bec63ccdf914d60 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Sun, 28 Aug 2016 16:18:51 -0400 Subject: [PATCH 13/15] Fix dstrings in preproc, no class descptrs tho (95%) --- nipype/interfaces/spm/preprocess.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index dca75e1c8d..b759ff32b8 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -732,7 +732,9 @@ class SegmentInputSpec(SPMCommandInputSpec): Modulated + Unmodulated Normalised: [True,True,False]""") wm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, field='output.WM', - desc="""Options to produce white matter images: c2*.img, wc2*.img and mwc2*.img. + desc=""" + Options to produce white matter images: \ +c2*.img, wc2*.img and mwc2*.img. None: [False,False,False], Native Space: [False,False,True], Unmodulated Normalised: [False,True,False], @@ -741,8 +743,10 @@ class SegmentInputSpec(SPMCommandInputSpec): Native + Modulated Normalised: [True,False,True], Native + Modulated + Unmodulated: [True,True,True], Modulated + Unmodulated Normalised: [True,True,False]""") - csf_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, field='output.CSF', - desc="""Options to produce CSF images: c3*.img, wc3*.img and mwc3*.img. + csf_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, + field='output.CSF', + desc=""" + Options to produce CSF images: c3*.img, wc3*.img and mwc3*.img. None: [False,False,False], Native Space: [False,False,True], Unmodulated Normalised: [False,True,False], @@ -891,7 +895,8 @@ class NewSegmentInputSpec(SPMCommandInputSpec): desc="""A tuple with the following fields: - bias reguralisation (0-10) - FWHM of Gaussian smoothness of bias - - which maps to save (Corrected, Field) - a tuple of two boolean values""", + - which maps to save (Corrected, Field) - \ +a tuple of two boolean values""", field='channel') tissues = traits.List( traits.Tuple(traits.Tuple(File(exists=True), traits.Int()), @@ -900,8 +905,10 @@ class NewSegmentInputSpec(SPMCommandInputSpec): desc="""A list of tuples (one per tissue) with the following fields: - tissue probability map (4D), 1-based index to frame - number of gaussians - - which maps to save [Native, DARTEL] - a tuple of two boolean values - - which maps to save [Unmodulated, Modulated] - a tuple of two boolean values""", + - which maps to save [Native, DARTEL] - \ +a tuple of two boolean values + - which maps to save [Unmodulated, Modulated] - \ +a tuple of two boolean values""", field='tissue') affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', field='warp.affreg', @@ -1174,7 +1181,8 @@ class DARTELInputSpec(SPMCommandInputSpec): optimization_parameters = traits.Tuple(traits.Float, traits.Range(1, 8), traits.Range(1, 8), field='warp.settings.optim', - desc="""Optimization settings a tuple + desc=""" + Optimization settings a tuple - LM regularization - cycles of multigrid solver - relaxation iterations @@ -1679,12 +1687,15 @@ def _list_outputs(self): # normalized space if getattr(self.inputs, '%s_normalized' % tis): outputs['normalized_class_images'][i].append( - os.path.join(pth, "w%sp%d%s.nii" % (dartel_px, i + 1, base))) + os.path.join(pth, + "w%sp%d%s.nii" % (dartel_px, + i + 1, base))) if getattr(self.inputs, '%s_modulated_normalized' % tis) == 1: outputs['modulated_class_images'][i].append(os.path.join( pth, "mw%sp%d%s.nii" % (dartel_px, i + 1, base))) - elif getattr(self.inputs, '%s_modulated_normalized' % tis) == 2: + elif getattr(self.inputs, + '%s_modulated_normalized' % tis) == 2: outputs['normalized_class_images'][i].append(os.path.join( pth, "m0w%sp%d%s.nii" % (dartel_px, i + 1, base))) From cf49830251336216b4eb59e720e18e7032f9ffc0 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Mon, 29 Aug 2016 00:28:46 -0400 Subject: [PATCH 14/15] Reverted docstring fixes in preproc --- nipype/interfaces/spm/preprocess.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index b759ff32b8..fa0b6b8882 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -733,8 +733,7 @@ class SegmentInputSpec(SPMCommandInputSpec): wm_output_type = traits.List(traits.Bool(), minlen=3, maxlen=3, field='output.WM', desc=""" - Options to produce white matter images: \ -c2*.img, wc2*.img and mwc2*.img. + Options to produce white matter images: c2*.img, wc2*.img and mwc2*.img. None: [False,False,False], Native Space: [False,False,True], Unmodulated Normalised: [False,True,False], @@ -875,8 +874,8 @@ def _list_outputs(self): outfield = '%s_%s_image' % (image, tissue) outputs[outfield] = fname_presuffix( f, prefix='%sc%d' % (prefix, tidx + 1)) - if isdefined(self.inputs.save_bias_corrected) and \ - self.inputs.save_bias_corrected: + if (isdefined(self.inputs.save_bias_corrected) + and self.inputs.save_bias_corrected): outputs['bias_corrected_image'] = fname_presuffix(f, prefix='m') t_mat = fname_presuffix(f, suffix='_seg_sn.mat', use_ext=False) outputs['transformation_mat'] = t_mat @@ -895,8 +894,7 @@ class NewSegmentInputSpec(SPMCommandInputSpec): desc="""A tuple with the following fields: - bias reguralisation (0-10) - FWHM of Gaussian smoothness of bias - - which maps to save (Corrected, Field) - \ -a tuple of two boolean values""", + - which maps to save (Corrected, Field) - a tuple of two boolean values""", field='channel') tissues = traits.List( traits.Tuple(traits.Tuple(File(exists=True), traits.Int()), @@ -905,10 +903,8 @@ class NewSegmentInputSpec(SPMCommandInputSpec): desc="""A list of tuples (one per tissue) with the following fields: - tissue probability map (4D), 1-based index to frame - number of gaussians - - which maps to save [Native, DARTEL] - \ -a tuple of two boolean values - - which maps to save [Unmodulated, Modulated] - \ -a tuple of two boolean values""", + - which maps to save [Native, DARTEL] - a tuple of two boolean values + - which maps to save [Unmodulated, Modulated] - a tuple of two boolean values""", field='tissue') affine_regularization = traits.Enum('mni', 'eastern', 'subj', 'none', field='warp.affreg', From 8424b80fcc4f6f2897eb1f211b75a46f0d239e78 Mon Sep 17 00:00:00 2001 From: Clark Date: Mon, 29 Aug 2016 08:45:21 -0400 Subject: [PATCH 15/15] Additional preproc cleanup & line 255 fix --- nipype/interfaces/spm/preprocess.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 54bcfa4f05..2aa4821205 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -9,11 +9,9 @@ >>> os.chdir(datadir) """ -from builtins import range - -__docformat__ = 'restructuredtext' # Standard library imports +from builtins import range from copy import deepcopy import os @@ -29,6 +27,8 @@ from ...utils.filemanip import (fname_presuffix, filename_to_list, list_to_filename, split_filename) +__docformat__ = 'restructuredtext' + class SliceTimingInputSpec(SPMCommandInputSpec): in_files = InputMultiPath(traits.Either(traits.List(File(exists=True)), @@ -252,7 +252,8 @@ def _list_outputs(self): if resliced_all: outputs['realigned_files'] = [] - for idx, imgf in enumerate(filename_to_list(self.inputs.in_files)): + for idx, imgf in enumerate( + filename_to_list(self.inputs.in_files)): realigned_run = [] if isinstance(imgf, list): for i, inner_imgf in enumerate(filename_to_list(imgf)): @@ -612,7 +613,6 @@ class Normalize12InputSpec(SPMCommandInputSpec): desc='Normalized output prefix') - class Normalize12OutputSpec(TraitedSpec): deformation_field = OutputMultiPath(File(exists=True), desc=('NIfTI file containing 3 ' @@ -877,8 +877,8 @@ def _list_outputs(self): outfield = '%s_%s_image' % (image, tissue) outputs[outfield] = fname_presuffix( f, prefix='%sc%d' % (prefix, tidx + 1)) - if (isdefined(self.inputs.save_bias_corrected) - and self.inputs.save_bias_corrected): + if (isdefined(self.inputs.save_bias_corrected) and + self.inputs.save_bias_corrected): outputs['bias_corrected_image'] = fname_presuffix(f, prefix='m') t_mat = fname_presuffix(f, suffix='_seg_sn.mat', use_ext=False) outputs['transformation_mat'] = t_mat