From 6a330bbb64129f1fdd113c4e34ef6ea0fa5c4ba0 Mon Sep 17 00:00:00 2001 From: Chris Filo Gorgolewski Date: Wed, 25 Jul 2012 21:53:07 +0100 Subject: [PATCH 1/4] Make all Booleans to be formated as 1,0 in SPM --- nipype/interfaces/spm/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/spm/base.py b/nipype/interfaces/spm/base.py index 7525655d9b..7d29a7a625 100644 --- a/nipype/interfaces/spm/base.py +++ b/nipype/interfaces/spm/base.py @@ -253,8 +253,10 @@ def _list_outputs(self): def _format_arg(self, opt, spec, val): """Convert input to appropriate format for SPM.""" - - return val + if spec.is_trait_type(traits.Bool): + return int(val) + else: + return val def _parse_inputs(self, skip=()): spmdict = {} From 08528555da11ab0828850b0aa2e1cf37b0082804 Mon Sep 17 00:00:00 2001 From: Chris Filo Gorgolewski Date: Thu, 26 Jul 2012 19:45:54 +0100 Subject: [PATCH 2/4] call super --- 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 ffa1fd59f8..1de853800e 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -411,7 +411,7 @@ def _format_arg(self, opt, spec, val): if opt in ['write_wrap']: if len(val) != 3: raise ValueError('%s must have 3 elements' % opt) - return val + return super(Normalize, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm realign options if set to None ignore From 2c42ff4f5a3e14fc337818f669db149b9e8448f2 Mon Sep 17 00:00:00 2001 From: Chris Filo Gorgolewski Date: Sat, 28 Jul 2012 20:22:03 +0100 Subject: [PATCH 3/4] Call super for all SPM _format_args() --- nipype/interfaces/spm/model.py | 8 +++----- nipype/interfaces/spm/preprocess.py | 24 ++++++++---------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/nipype/interfaces/spm/model.py b/nipype/interfaces/spm/model.py index cd7ce07b2e..c2213fad4b 100644 --- a/nipype/interfaces/spm/model.py +++ b/nipype/interfaces/spm/model.py @@ -117,7 +117,7 @@ def _format_arg(self, opt, spec, val): return [val] else: return val - return val + return super(Level1Design, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm realign options if set to None ignore @@ -200,7 +200,7 @@ def _format_arg(self, opt, spec, val): return {'%s' % val: 1} else: return val - return val + return super(EstimateModel, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm realign options if set to None ignore @@ -747,7 +747,7 @@ def _format_arg(self, opt, spec, val): outdict[mapping[key]] = keyval outlist.append(outdict) return outlist - return val + return super(FactorialDesign, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm realign options if set to None ignore @@ -893,8 +893,6 @@ def _format_arg(self, opt, spec, val): """ if opt in ['in_files']: return np.array(val, dtype=object) - if opt in ['include_intercept']: - return int(val) if opt in ['user_covariates']: outlist = [] mapping = {'name': 'cname', 'vector': 'c', diff --git a/nipype/interfaces/spm/preprocess.py b/nipype/interfaces/spm/preprocess.py index 1de853800e..6b56debe14 100644 --- a/nipype/interfaces/spm/preprocess.py +++ b/nipype/interfaces/spm/preprocess.py @@ -87,7 +87,7 @@ def _format_arg(self, opt, spec, val): return scans_for_fnames(filename_to_list(val), keep4d=False, separate_sessions=True) - return val + return super(SliceTiming, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() @@ -177,9 +177,7 @@ def _format_arg(self, opt, spec, val): return scans_for_fnames(val, keep4d=True, separate_sessions=True) - if opt == 'register_to_mean': # XX check if this is necessary - return int(val) - return val + return super(Realign, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm realign options if set to None ignore @@ -296,7 +294,7 @@ def _format_arg(self, opt, spec, val): return scans_for_fnames(val+self.inputs.apply_to_files) else: return scans_for_fnames(val) - return val + return super(Coregister, self)._format_arg(opt, spec, val) def _parse_inputs(self): """validate spm coregister options if set to None ignore @@ -560,13 +558,11 @@ def _format_arg(self, opt, spec, val): return scans_for_fname(val) if 'output_type' in opt: return [int(v) for v in val] - if opt == 'save_bias_corrected': - return int(val) if opt == 'mask_image': return scans_for_fname(val) if opt == 'clean_masks': return clean_masks_dict[val] - return val + return super(Segment, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() @@ -785,10 +781,8 @@ def _format_arg(self, opt, spec, val): return [val[0], val[0], val[0]] else: return val - if opt == 'implicit_masking': - return int(val) - return val + return super(Smooth, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() @@ -879,7 +873,7 @@ def _format_arg(self, opt, spec, val): new_param['its'] = val[2] return [new_param] else: - return val + return super(DARTEL, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() @@ -965,10 +959,8 @@ def _format_arg(self, opt, spec, val): return val else: return [val, val, val] - elif opt == 'modulate': - return int(val) else: - return val + return super(DARTELNorm2MNI, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() @@ -1040,7 +1032,7 @@ def _format_arg(self, opt, spec, val): if opt in ['flowfield_files']: return scans_for_fnames(val, keep4d=True) else: - return val + return super(CreateWarped, self)._format_arg(opt, spec, val) def _list_outputs(self): outputs = self._outputs().get() From 5628919b515bdde80c2112cd9312054c62b4601a Mon Sep 17 00:00:00 2001 From: Chris Filo Gorgolewski Date: Tue, 4 Sep 2012 15:14:24 +0200 Subject: [PATCH 4/4] Added a test for SPM bool conversion. --- nipype/interfaces/spm/tests/test_base.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/tests/test_base.py b/nipype/interfaces/spm/tests/test_base.py index 731038c819..55c3af29a3 100644 --- a/nipype/interfaces/spm/tests/test_base.py +++ b/nipype/interfaces/spm/tests/test_base.py @@ -11,6 +11,8 @@ import nipype.interfaces.spm.base as spm from nipype.interfaces.spm import no_spm import nipype.interfaces.matlab as mlab +from nipype.interfaces.spm.base import SPMCommandInputSpec +from nipype.interfaces.base import traits try: matlab_cmd = os.environ['MATLABCMD'] @@ -121,7 +123,19 @@ class TestClass(spm.SPMCommand): out = dc._generate_job(prefix='test', contents=contents) yield assert_equal, out, 'test.onsets = {...\n[1, 2, 3, 4];...\n};\n' - +def test_bool(): + class TestClassInputSpec(SPMCommandInputSpec): + test_in = include_intercept = traits.Bool(field='testfield') + + class TestClass(spm.SPMCommand): + input_spec = TestClassInputSpec + _jobtype = 'jobtype' + _jobname = 'jobname' + dc = TestClass() # dc = derived_class + dc.inputs.test_in = True + out = dc._make_matlab_command(dc._parse_inputs()) + yield assert_equal, out.find('jobs{1}.jobtype{1}.jobname{1}.testfield = 1;') > 0, 1 + def test_make_matlab_command(): class TestClass(spm.SPMCommand): _jobtype = 'jobtype'