Skip to content

Commit eee9148

Browse files
author
David Ellis
committed
FIX: Cleans up freesurfer MNI Bias Correction
1 parent 7594442 commit eee9148

File tree

1 file changed

+9
-64
lines changed

1 file changed

+9
-64
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
13701370
# mandatory
13711371
in_file = File(exists=True, mandatory=True, argstr="--i %s",
13721372
desc="input volume. Input can be any format accepted by mri_convert.")
1373-
out_file = File(mandatory=False, argstr="--o %s", name_source=['in_file'], name_template='%s_output',
1374-
hash_files=False, keep_extension=True,
1373+
out_file = File(argstr="--o %s", name_source=['in_file'],
1374+
name_template='%s_output', hash_files=False, keep_extension=True,
13751375
desc="output volume. Output can be any format accepted by mri_convert. " +
13761376
"If the output format is COR, then the directory must exist.")
13771377
# optional
@@ -1383,19 +1383,19 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
13831383
desc="Passes Np as argument of the -iterations flag of nu_correct. This is different " +
13841384
"than the --n flag above. Default is not to pass nu_correct the -iterations flag.")
13851385
distance = traits.Int(argstr="--distance %d", desc="N3 -distance option")
1386-
no_rescale = traits.Bool(False, argstr="--no-rescale",
1386+
no_rescale = traits.Bool(argstr="--no-rescale",
13871387
desc="do not rescale so that global mean of output == input global mean")
1388-
mask = File(exists=True, mandatory=False, argstr="--mask %s",
1388+
mask = File(exists=True, argstr="--mask %s",
13891389
desc="brainmask volume. Input can be any format accepted by mri_convert.")
1390-
transform = File(exists=True, mandatory=False, argstr="--uchar %s",
1390+
transform = File(exists=True, argstr="--uchar %s",
13911391
desc="tal.xfm. Use mri_make_uchar instead of conforming")
1392-
stop = traits.Float(argstr="--stop %f", mandatory=False,
1392+
stop = traits.Float(argstr="--stop %f",
13931393
desc="Convergence threshold below which iteration stops (suggest 0.01 to 0.0001)")
1394-
shrink = traits.Int(argstr="--shrink %d", mandatory=False,
1394+
shrink = traits.Int(argstr="--shrink %d",
13951395
desc="Shrink parameter for finer sampling (default is 4)")
13961396

13971397
class MNIBiasCorrectionOutputSpec(TraitedSpec):
1398-
out_file = File(exists=True, desc="output volume")
1398+
out_file = File(desc="output volume")
13991399

14001400

14011401
class MNIBiasCorrection(FSCommand):
@@ -1413,12 +1413,11 @@ class MNIBiasCorrection(FSCommand):
14131413
>>> from nipype.interfaces.freesurfer import MNIBiasCorrection
14141414
>>> correct = MNIBiasCorrection()
14151415
>>> correct.inputs.in_file = "norm.mgz"
1416-
>>> correct.inputs.out_file = "out.mgz"
14171416
>>> correct.inputs.iterations = 6
14181417
>>> correct.inputs.protocol_iterations = 1000
14191418
>>> correct.inputs.distance = 50
14201419
>>> correct.cmdline
1421-
'mri_nu_correct.mni --distance 50 --i norm.mgz --n 6 --o out.mgz --proto-iters 1000'
1420+
'mri_nu_correct.mni --distance 50 --i norm.mgz --n 6 --o out_output.mgz --proto-iters 1000'
14221421
14231422
References:
14241423
----------
@@ -1431,60 +1430,6 @@ class MNIBiasCorrection(FSCommand):
14311430
input_spec = MNIBiasCorrectionInputSpec
14321431
output_spec = MNIBiasCorrectionOutputSpec
14331432

1434-
def _filename_from_source(self, name, chain=None):
1435-
if chain is None:
1436-
chain = []
1437-
1438-
trait_spec = self.inputs.trait(name)
1439-
retval = getattr(self.inputs, name)
1440-
1441-
if not isdefined(retval) or "%s" in retval:
1442-
if not trait_spec.name_source:
1443-
return retval
1444-
if isdefined(retval) and "%s" in retval:
1445-
name_template = retval
1446-
else:
1447-
name_template = trait_spec.name_template
1448-
if not name_template:
1449-
name_template = "%s_generated"
1450-
1451-
ns = trait_spec.name_source
1452-
while isinstance(ns, list):
1453-
if len(ns) > 1:
1454-
iflogger.warn('Only one name_source per trait is allowed')
1455-
ns = ns[0]
1456-
1457-
if not isinstance(ns, six.string_types):
1458-
raise ValueError(('name_source of \'%s\' trait sould be an '
1459-
'input trait name') % name)
1460-
1461-
if isdefined(getattr(self.inputs, ns)):
1462-
name_source = ns
1463-
source = getattr(self.inputs, name_source)
1464-
while isinstance(source, list):
1465-
source = source[0]
1466-
1467-
# special treatment for files
1468-
try:
1469-
_, base, ext = split_filename(source) # get file extension
1470-
except AttributeError:
1471-
base = source
1472-
else:
1473-
if name in chain:
1474-
raise NipypeInterfaceError(
1475-
'Mutually pointing name_sources')
1476-
1477-
chain.append(name)
1478-
base = self._filename_from_source(ns, chain)
1479-
1480-
chain = None
1481-
retval = name_template % base
1482-
if trait_spec.keep_extension and ext:
1483-
return retval + ext
1484-
return self._overload_extension(retval, name)
1485-
1486-
return retval
1487-
14881433
def _list_outputs(self):
14891434
outputs = self._outputs().get()
14901435
outputs["out_file"] = os.path.abspath(self.inputs.out_file)

0 commit comments

Comments
 (0)