Skip to content

reduce number of SPM calls #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,34 +925,36 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
""" Raises an exception on version mismatch
"""
unavailable_traits = []
version = LooseVersion(str(self.version))
if not version:
return
# check minimum version
check = dict(min_ver=lambda t: t is not None)
names = trait_object.trait_names(**check)
for name in names:
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
if min_ver > version:
unavailable_traits.append(name)
if not isdefined(getattr(trait_object, name)):
continue
if raise_exception:
raise Exception('Trait %s (%s) (version %s < required %s)' %
(name, self.__class__.__name__,
version, min_ver))
check = dict(max_ver=lambda t: t is not None)
names = trait_object.trait_names(**check)
for name in names:
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
if max_ver < version:
unavailable_traits.append(name)
if not isdefined(getattr(trait_object, name)):
continue
if raise_exception:
raise Exception('Trait %s (%s) (version %s > required %s)' %
(name, self.__class__.__name__,
version, max_ver))

if names:
version = LooseVersion(str(self.version))
if not version:
return
for name in names:
min_ver = LooseVersion(str(trait_object.traits()[name].min_ver))
if min_ver > version:
unavailable_traits.append(name)
if not isdefined(getattr(trait_object, name)):
continue
if raise_exception:
raise Exception('Trait %s (%s) (version %s < required %s)' %
(name, self.__class__.__name__,
version, min_ver))
check = dict(max_ver=lambda t: t is not None)
names = trait_object.trait_names(**check)
for name in names:
max_ver = LooseVersion(str(trait_object.traits()[name].max_ver))
if max_ver < version:
unavailable_traits.append(name)
if not isdefined(getattr(trait_object, name)):
continue
if raise_exception:
raise Exception('Trait %s (%s) (version %s > required %s)' %
(name, self.__class__.__name__,
version, max_ver))
return unavailable_traits

def _run_wrapper(self, runtime):
Expand Down
37 changes: 22 additions & 15 deletions nipype/interfaces/spm/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,19 @@ class Segment(SPMCommand):

"""

_local_version = SPMCommand().version
if _local_version and '12.' in _local_version:
_jobtype = 'tools'
_jobname = 'oldseg'
else:
_jobtype = 'spatial'
_jobname = 'preproc'

input_spec = SegmentInputSpec
output_spec = SegmentOutputSpec

def __init__(self, **inputs):
_local_version = SPMCommand().version
if _local_version and '12.' in _local_version:
self._jobtype = 'tools'
self._jobname = 'oldseg'
else:
self._jobtype = 'spatial'
self._jobname = 'preproc'

SPMCommand.__init__(self, **inputs)

def _format_arg(self, opt, spec, val):
"""Convert input to appropriate format for spm
Expand Down Expand Up @@ -894,13 +897,17 @@ class NewSegment(SPMCommand):

input_spec = NewSegmentInputSpec
output_spec = NewSegmentOutputSpec
_local_version = SPMCommand().version
if _local_version and '12.' in _local_version:
_jobtype = 'spatial'
_jobname = 'preproc'
else:
_jobtype = 'tools'
_jobname = 'preproc8'

def __init__(self, **inputs):
_local_version = SPMCommand().version
if _local_version and '12.' in _local_version:
self._jobtype = 'spatial'
self._jobname = 'preproc'
else:
self._jobtype = 'tools'
self._jobname = 'preproc8'

SPMCommand.__init__(self, **inputs)

def _format_arg(self, opt, spec, val):
"""Convert input to appropriate format for spm
Expand Down
16 changes: 8 additions & 8 deletions nipype/interfaces/spm/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ def test_normalize12_list_outputs():
@skipif(no_spm)
def test_segment():
if spm.Info.version()['name'] == "SPM12":
yield assert_equal, spm.Segment._jobtype, 'tools'
yield assert_equal, spm.Segment._jobname, 'oldseg'
yield assert_equal, spm.Segment()._jobtype, 'tools'
yield assert_equal, spm.Segment()._jobname, 'oldseg'
else:
yield assert_equal, spm.Segment._jobtype, 'spatial'
yield assert_equal, spm.Segment._jobname, 'preproc'
yield assert_equal, spm.Segment()._jobtype, 'spatial'
yield assert_equal, spm.Segment()._jobname, 'preproc'

@skipif(no_spm)
def test_newsegment():
if spm.Info.version()['name'] == "SPM12":
yield assert_equal, spm.NewSegment._jobtype, 'spatial'
yield assert_equal, spm.NewSegment._jobname, 'preproc'
yield assert_equal, spm.NewSegment()._jobtype, 'spatial'
yield assert_equal, spm.NewSegment()._jobname, 'preproc'
else:
yield assert_equal, spm.NewSegment._jobtype, 'tools'
yield assert_equal, spm.NewSegment._jobname, 'preproc8'
yield assert_equal, spm.NewSegment()._jobtype, 'tools'
yield assert_equal, spm.NewSegment()._jobname, 'preproc8'


def test_smooth():
Expand Down
10 changes: 9 additions & 1 deletion nipype/testing/data/pyscript.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
fprintf(1,'Executing %s at %s:\n',mfilename,datestr(now));
ver,
try,a=1;
try,
if isempty(which('spm')),
throw(MException('SPMCheck:NotFound','SPM not in matlab path'));
end;
spm_path = spm('dir');
[name, version] = spm('ver');
fprintf(1, 'NIPYPE path:%s|name:%s|release:%s', spm_path, name, version);
exit;

,catch ME,
fprintf(2,'MATLAB code threw an exception:\n');
fprintf(2,'%s\n',ME.message);
Expand Down