Skip to content

Fix/vol2surf #1078

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

Closed
wants to merge 3 commits into from
Closed
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
34 changes: 34 additions & 0 deletions nipype/algorithms/tests/test_auto_ErrorMap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from nipype.testing import assert_equal
from nipype.algorithms.metrics import ErrorMap

def test_ErrorMap_inputs():
input_map = dict(ignore_exception=dict(nohash=True,
usedefault=True,
),
in_ref=dict(mandatory=True,
),
in_tst=dict(mandatory=True,
),
mask=dict(),
metric=dict(mandatory=True,
usedefault=True,
),
out_map=dict(),
)
inputs = ErrorMap.input_spec()

for key, metadata in input_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(inputs.traits()[key], metakey), value

def test_ErrorMap_outputs():
output_map = dict(distance=dict(),
out_map=dict(),
)
outputs = ErrorMap.output_spec()

for key, metadata in output_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(outputs.traits()[key], metakey), value

46 changes: 46 additions & 0 deletions nipype/algorithms/tests/test_auto_Overlap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from nipype.testing import assert_equal
from nipype.algorithms.misc import Overlap

def test_Overlap_inputs():
input_map = dict(bg_overlap=dict(mandatory=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
mask_volume=dict(),
out_file=dict(usedefault=True,
),
vol_units=dict(mandatory=True,
usedefault=True,
),
volume1=dict(mandatory=True,
),
volume2=dict(mandatory=True,
),
weighting=dict(usedefault=True,
),
)
inputs = Overlap.input_spec()

for key, metadata in input_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(inputs.traits()[key], metakey), value

def test_Overlap_outputs():
output_map = dict(dice=dict(),
diff_file=dict(),
jaccard=dict(),
labels=dict(),
roi_di=dict(),
roi_ji=dict(),
roi_voldiff=dict(),
volume_difference=dict(),
)
outputs = Overlap.output_spec()

for key, metadata in output_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(outputs.traits()[key], metakey), value

6 changes: 3 additions & 3 deletions nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,9 @@ def _terminal_output_update(self):
def set_default_terminal_output(cls, output_type):
"""Set the default terminal output for CommandLine Interfaces.

This method is used to set default terminal output for
CommandLine Interfaces. However, setting this will not
update the output type for any existing instances. For these,
This method is used to set default terminal output for
CommandLine Interfaces. However, setting this will not
update the output type for any existing instances. For these,
assign the <instance>.inputs.terminal_output.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_SampleToSurface_inputs():
),
subject_id=dict(),
subjects_dir=dict(),
surf_reg=dict(argstr='--surfreg',
surf_reg=dict(argstr='--surfreg %s',
requires=['target_subject'],
),
surface=dict(argstr='--surf %s',
Expand Down
6 changes: 3 additions & 3 deletions nipype/interfaces/freesurfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class SampleToSurfaceInputSpec(FSTraitedSpec):
subject_id = traits.String(desc="subject id")
target_subject = traits.String(argstr="--trgsubject %s",
desc="sample to surface of different subject than source")
surf_reg = traits.Bool(argstr="--surfreg", requires=["target_subject"],
desc="use surface registration to target subject")
surf_reg = traits.String(argstr="--surfreg %s", requires=["target_subject"],
desc="registration surface to target subject (default sphere.reg)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in such a case, you may want to explicitly set the default value of the traits to sphere.reg

surf_reg = traits.String('sphere.reg', ..., usedefault=True)

ico_order = traits.Int(argstr="--icoorder %d", requires=["target_subject"],
desc="icosahedron order when target_subject is 'ico'")

Expand Down Expand Up @@ -1276,4 +1276,4 @@ def _gen_outfilename(self):
return os.path.abspath(self.inputs.out_file)
else:
_, name, ext = split_filename(self.inputs.in_file)
return os.path.abspath(name + '_smoothed' + ext)
return os.path.abspath(name + '_smoothed' + ext)
Binary file modified nipype/testing/data/von_errmap.nii.gz
Binary file not shown.
14 changes: 7 additions & 7 deletions nipype/utils/nipype_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def add_options(parser=None, module=None, function=None):
if parser and module and function:
__import__(module)
interface = getattr(sys.modules[module],function)()

inputs = interface.input_spec()
for name, spec in sorted(interface.inputs.traits(transient=None).items()):
desc = "\n".join(interface._get_trait_desc(inputs, name, spec))[len(name)+2:]
Expand All @@ -33,7 +33,7 @@ def add_options(parser=None, module=None, function=None):
def run_instance(interface, options):
if interface:
print "setting function inputs"

for input_name, _ in interface.inputs.items():
if getattr(options, input_name) != None:
value = getattr(options, input_name)
Expand All @@ -48,23 +48,23 @@ def run_instance(interface, options):
value)
except ValueError, e:
print "Error when setting the value of %s: '%s'"%(input_name, str(e))

print interface.inputs
res = interface.run()
print res.outputs
print res.outputs


def main(argv):

if len(argv) == 2 and not argv[1].startswith("-"):
listClasses(argv[1])
sys.exit(0)

parser = argparse.ArgumentParser(description='Nipype interface runner', prog=argv[0])
parser.add_argument("module", type=str, help="Module name")
parser.add_argument("interface", type=str, help="Interface name")
parsed = parser.parse_args(args=argv[1:3])

_, prog = os.path.split(argv[0])
interface_parser = argparse.ArgumentParser(description="Run %s"%parsed.interface, prog=" ".join([prog] + argv[1:3]))
interface_parser, interface = add_options(interface_parser, parsed.module, parsed.interface)
Expand Down
28 changes: 14 additions & 14 deletions nipype/utils/tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ def test_main_returns_2_on_empty(self):
with self.assertRaises(SystemExit) as cm:
with capture_sys_output() as (stdout, stderr):
nipype_cmd.main(['nipype_cmd'])

exit_exception = cm.exception
self.assertEqual(exit_exception.code, 2)
self.assertEqual(stderr.getvalue(),

self.assertEqual(stderr.getvalue(),
"""usage: nipype_cmd [-h] module interface
nipype_cmd: error: too few arguments
""")
self.assertEqual(stdout.getvalue(), '')

def test_main_returns_0_on_help(self):
with self.assertRaises(SystemExit) as cm:
with capture_sys_output() as (stdout, stderr):
nipype_cmd.main(['nipype_cmd', '-h'])

exit_exception = cm.exception
self.assertEqual(exit_exception.code, 0)

self.assertEqual(stderr.getvalue(), '')
self.assertEqual(stdout.getvalue(),
"""usage: nipype_cmd [-h] module interface
Expand All @@ -53,15 +53,15 @@ def test_main_returns_0_on_help(self):
optional arguments:
-h, --help show this help message and exit
""")

def test_list_nipy_interfacesp(self):
with self.assertRaises(SystemExit) as cm:
with capture_sys_output() as (stdout, stderr):
nipype_cmd.main(['nipype_cmd', 'nipype.interfaces.nipy'])

exit_exception = cm.exception
self.assertEqual(exit_exception.code, 0)

self.assertEqual(stderr.getvalue(), '')
self.assertEqual(stdout.getvalue(),
"""Available Interfaces:
Expand All @@ -77,10 +77,10 @@ def test_run_4d_realign_without_arguments(self):
with self.assertRaises(SystemExit) as cm:
with capture_sys_output() as (stdout, stderr):
nipype_cmd.main(['nipype_cmd', 'nipype.interfaces.nipy', 'FmriRealign4d'])

exit_exception = cm.exception
self.assertEqual(exit_exception.code, 2)

self.assertEqual(stderr.getvalue(),
"""usage: nipype_cmd nipype.interfaces.nipy FmriRealign4d [-h]
[--between_loops BETWEEN_LOOPS]
Expand All @@ -95,15 +95,15 @@ def test_run_4d_realign_without_arguments(self):
nipype_cmd nipype.interfaces.nipy FmriRealign4d: error: too few arguments
""")
self.assertEqual(stdout.getvalue(), '')

def test_run_4d_realign_help(self):
with self.assertRaises(SystemExit) as cm:
with capture_sys_output() as (stdout, stderr):
nipype_cmd.main(['nipype_cmd', 'nipype.interfaces.nipy', 'FmriRealign4d', '-h'])

exit_exception = cm.exception
self.assertEqual(exit_exception.code, 0)

self.assertEqual(stderr.getvalue(), '')
self.assertTrue("Run FmriRealign4d" in stdout.getvalue())

Expand Down