Skip to content

Commit ad2baf7

Browse files
committed
Handle output filenames correctly, add undocumented options
1 parent cdaf422 commit ad2baf7

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

nipype/interfaces/freesurfer/tests/test_auto_MRIsExpand.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def test_MRIsExpand_inputs():
1010
mandatory=True,
1111
position=-2,
1212
),
13+
dt=dict(argstr='-T %g',
14+
),
1315
environ=dict(nohash=True,
1416
usedefault=True,
1517
),
@@ -20,16 +22,29 @@ def test_MRIsExpand_inputs():
2022
mandatory=True,
2123
position=-3,
2224
),
23-
out_file=dict(argstr='%s',
24-
name_source='in_file',
25-
name_template='%s.expanded',
25+
navgs=dict(argstr='-navgs %d %d',
26+
),
27+
nsurfaces=dict(argstr='-N %d',
28+
),
29+
out_name=dict(argstr='%s',
2630
position=-1,
31+
usedefault=True,
32+
),
33+
pial=dict(argstr='-pial %s',
34+
),
35+
smooth_averages=dict(argstr='-A %d',
36+
),
37+
spring=dict(argstr='-S %g',
2738
),
2839
subjects_dir=dict(),
2940
terminal_output=dict(nohash=True,
3041
),
3142
thickness=dict(argstr='-thickness',
3243
),
44+
thickness_name=dict(argstr='-thickness_name %s',
45+
),
46+
write_iterations=dict(argstr='-W %d',
47+
),
3348
)
3449
inputs = MRIsExpand.input_spec()
3550

nipype/interfaces/freesurfer/utils.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,19 +2882,47 @@ def _list_outputs(self):
28822882

28832883

28842884
class MRIsExpandInputSpec(FSTraitedSpec):
2885+
# Input spec derived from
2886+
# https://github.com/freesurfer/freesurfer/blob/102e053/mris_expand/mris_expand.c
28852887
in_file = File(
28862888
exists=True, mandatory=True, argstr='%s', position=-3,
28872889
desc='Surface to expand')
28882890
distance = traits.Float(
28892891
mandatory=True, argstr='%g', position=-2,
28902892
desc='Distance in mm or fraction of cortical thickness')
2891-
out_file = File(
2892-
argstr='%s', position=-1,
2893-
name_template='%s.expanded', name_source='in_file',
2894-
desc='Output surface file')
2893+
out_name = traits.Str(
2894+
'expanded', argstr='%s', position=-1, usedefault=True,
2895+
desc=('Output surface file\n'
2896+
'If missing "lh." or "rh.", derive from `in_file`'))
28952897
thickness = traits.Bool(
28962898
argstr='-thickness',
28972899
desc='Expand by fraction of cortical thickness, not mm')
2900+
thickness_name = traits.Str(
2901+
argstr="-thickness_name %s",
2902+
desc=('Name of thickness file (implicit: "thickness")\n'
2903+
'If no path, uses directory of `in_file`\n'
2904+
'If missing "lh." or "rh.", derive from `in_file`'))
2905+
navgs = traits.Tuple(
2906+
traits.Int, traits.Int,
2907+
argstr='-navgs %d %d',
2908+
desc=('Tuple of (n_averages, min_averages) parameters '
2909+
'(implicit: (16, 0))'))
2910+
pial = traits.Str(
2911+
argstr='-pial %s',
2912+
desc=('Name of pial file (implicit: "pial")\n'
2913+
'If no path, uses directory of `in_file`\n'
2914+
'If missing "lh." or "rh.", derive from `in_file`'))
2915+
spring = traits.Float(argstr='-S %g', desc="Spring term (implicit: 0.05)")
2916+
dt = traits.Float(argstr='-T %g', desc='dt (implicit: 0.25)')
2917+
write_iterations = traits.Int(
2918+
argstr='-W %d',
2919+
desc='Write snapshots of expansion every N iterations')
2920+
smooth_averages = traits.Int(
2921+
argstr='-A %d',
2922+
desc='Smooth surface with N iterations after expansion')
2923+
nsurfaces = traits.Int(
2924+
argstr='-N %d',
2925+
desc='Number of surfacces to write during expansion')
28982926

28992927

29002928
class MRIsExpandOutputSpec(TraitedSpec):
@@ -2920,3 +2948,20 @@ class MRIsExpand(FSCommand):
29202948
_cmd = 'mris_expand'
29212949
input_spec = MRIsExpandInputSpec
29222950
output_spec = MRIsExpandOutputSpec
2951+
2952+
def _format_arg(self, name, spec, value):
2953+
if name == 'out_name':
2954+
value = self._list_outputs()['out_file']
2955+
return super(MRIsExpand, self)._format_arg(name, spec, value)
2956+
2957+
def _list_outputs(self):
2958+
outputs = self._outputs().get()
2959+
# Mimic FreeSurfer output filename derivation, but in local directory
2960+
# if no path specified
2961+
out_file = self.inputs.out_name
2962+
path, base = os.path.split(out_file)
2963+
if all((path == '', not base.startswith('lh.'),
2964+
not base.startswith('rh.'))):
2965+
out_file = self.inputs.in_file[:3] + base
2966+
outputs["out_file"] = os.path.abspath(out_file)
2967+
return outputs

0 commit comments

Comments
 (0)