Skip to content

Commit e25da04

Browse files
committed
Merge pull request #1205 from chrisfilo/fix/spm
reduce number of SPM calls
2 parents a461ad3 + 97cc7d3 commit e25da04

File tree

4 files changed

+66
-49
lines changed

4 files changed

+66
-49
lines changed

nipype/interfaces/base.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -925,34 +925,36 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
925925
""" Raises an exception on version mismatch
926926
"""
927927
unavailable_traits = []
928-
version = LooseVersion(str(self.version))
929-
if not version:
930-
return
931928
# check minimum version
932929
check = dict(min_ver=lambda t: t is not None)
933930
names = trait_object.trait_names(**check)
934-
for name in names:
935-
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
936-
if min_ver > version:
937-
unavailable_traits.append(name)
938-
if not isdefined(getattr(trait_object, name)):
939-
continue
940-
if raise_exception:
941-
raise Exception('Trait %s (%s) (version %s < required %s)' %
942-
(name, self.__class__.__name__,
943-
version, min_ver))
944-
check = dict(max_ver=lambda t: t is not None)
945-
names = trait_object.trait_names(**check)
946-
for name in names:
947-
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
948-
if max_ver < version:
949-
unavailable_traits.append(name)
950-
if not isdefined(getattr(trait_object, name)):
951-
continue
952-
if raise_exception:
953-
raise Exception('Trait %s (%s) (version %s > required %s)' %
954-
(name, self.__class__.__name__,
955-
version, max_ver))
931+
932+
if names:
933+
version = LooseVersion(str(self.version))
934+
if not version:
935+
return
936+
for name in names:
937+
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
938+
if min_ver > version:
939+
unavailable_traits.append(name)
940+
if not isdefined(getattr(trait_object, name)):
941+
continue
942+
if raise_exception:
943+
raise Exception('Trait %s (%s) (version %s < required %s)' %
944+
(name, self.__class__.__name__,
945+
version, min_ver))
946+
check = dict(max_ver=lambda t: t is not None)
947+
names = trait_object.trait_names(**check)
948+
for name in names:
949+
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
950+
if max_ver < version:
951+
unavailable_traits.append(name)
952+
if not isdefined(getattr(trait_object, name)):
953+
continue
954+
if raise_exception:
955+
raise Exception('Trait %s (%s) (version %s > required %s)' %
956+
(name, self.__class__.__name__,
957+
version, max_ver))
956958
return unavailable_traits
957959

958960
def _run_wrapper(self, runtime):

nipype/interfaces/spm/preprocess.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -763,16 +763,19 @@ class Segment(SPMCommand):
763763
764764
"""
765765

766-
_local_version = SPMCommand().version
767-
if _local_version and '12.' in _local_version:
768-
_jobtype = 'tools'
769-
_jobname = 'oldseg'
770-
else:
771-
_jobtype = 'spatial'
772-
_jobname = 'preproc'
773-
774766
input_spec = SegmentInputSpec
775767
output_spec = SegmentOutputSpec
768+
769+
def __init__(self, **inputs):
770+
_local_version = SPMCommand().version
771+
if _local_version and '12.' in _local_version:
772+
self._jobtype = 'tools'
773+
self._jobname = 'oldseg'
774+
else:
775+
self._jobtype = 'spatial'
776+
self._jobname = 'preproc'
777+
778+
SPMCommand.__init__(self, **inputs)
776779

777780
def _format_arg(self, opt, spec, val):
778781
"""Convert input to appropriate format for spm
@@ -891,13 +894,17 @@ class NewSegment(SPMCommand):
891894

892895
input_spec = NewSegmentInputSpec
893896
output_spec = NewSegmentOutputSpec
894-
_local_version = SPMCommand().version
895-
if _local_version and '12.' in _local_version:
896-
_jobtype = 'spatial'
897-
_jobname = 'preproc'
898-
else:
899-
_jobtype = 'tools'
900-
_jobname = 'preproc8'
897+
898+
def __init__(self, **inputs):
899+
_local_version = SPMCommand().version
900+
if _local_version and '12.' in _local_version:
901+
self._jobtype = 'spatial'
902+
self._jobname = 'preproc'
903+
else:
904+
self._jobtype = 'tools'
905+
self._jobname = 'preproc8'
906+
907+
SPMCommand.__init__(self, **inputs)
901908

902909
def _format_arg(self, opt, spec, val):
903910
"""Convert input to appropriate format for spm

nipype/interfaces/spm/tests/test_preprocess.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ def test_normalize12_list_outputs():
106106
@skipif(no_spm)
107107
def test_segment():
108108
if spm.Info.version()['name'] == "SPM12":
109-
yield assert_equal, spm.Segment._jobtype, 'tools'
110-
yield assert_equal, spm.Segment._jobname, 'oldseg'
109+
yield assert_equal, spm.Segment()._jobtype, 'tools'
110+
yield assert_equal, spm.Segment()._jobname, 'oldseg'
111111
else:
112-
yield assert_equal, spm.Segment._jobtype, 'spatial'
113-
yield assert_equal, spm.Segment._jobname, 'preproc'
112+
yield assert_equal, spm.Segment()._jobtype, 'spatial'
113+
yield assert_equal, spm.Segment()._jobname, 'preproc'
114114

115115
@skipif(no_spm)
116116
def test_newsegment():
117117
if spm.Info.version()['name'] == "SPM12":
118-
yield assert_equal, spm.NewSegment._jobtype, 'spatial'
119-
yield assert_equal, spm.NewSegment._jobname, 'preproc'
118+
yield assert_equal, spm.NewSegment()._jobtype, 'spatial'
119+
yield assert_equal, spm.NewSegment()._jobname, 'preproc'
120120
else:
121-
yield assert_equal, spm.NewSegment._jobtype, 'tools'
122-
yield assert_equal, spm.NewSegment._jobname, 'preproc8'
121+
yield assert_equal, spm.NewSegment()._jobtype, 'tools'
122+
yield assert_equal, spm.NewSegment()._jobname, 'preproc8'
123123

124124

125125
def test_smooth():

nipype/testing/data/pyscript.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
fprintf(1,'Executing %s at %s:\n',mfilename,datestr(now));
22
ver,
3-
try,a=1;
3+
try,
4+
if isempty(which('spm')),
5+
throw(MException('SPMCheck:NotFound','SPM not in matlab path'));
6+
end;
7+
spm_path = spm('dir');
8+
[name, version] = spm('ver');
9+
fprintf(1, 'NIPYPE path:%s|name:%s|release:%s', spm_path, name, version);
10+
exit;
11+
412
,catch ME,
513
fprintf(2,'MATLAB code threw an exception:\n');
614
fprintf(2,'%s\n',ME.message);

0 commit comments

Comments
 (0)