Repository: nipy/nipype

Issue:
genfile'ed output name "is not remembered" to be used later (in self.aggregate_outputs)?
I am trying on ANTs' LaplacianThickness interface to not specify `output_image` (if I do - another issue, will report separately):

```python
from nipype.interfaces.ants import LaplacianThickness
cort_thick = LaplacianThickness()
d = 'antsCorticalThicknessExample/ResultsT1Only/'
cort_thick.inputs.input_wm = d + 'exampleBrainSegmentationPosteriors3.nii.gz'
cort_thick.inputs.input_gm = d + 'exampleBrainSegmentationPosteriors2.nii.gz'
# cort_thick.inputs.output_image = 'output_thickness.nii.gz'
print(cort_thick.cmdline)
print("Running")
print(cort_thick.run())
```

```shell
$> python nipype-undefined-output.py
LaplacianThickness antsCorticalThicknessExample/ResultsT1Only/exampleBrainSegmentationPosteriors3.nii.gz antsCorticalThicknessExample/ResultsT1Only/exampleBrainSegmentationPosteriors2.nii.gz exampleBrainSegmentationPosteriors3_thickness.nii.gz
Running
181012-13:50:48,584 nipype.interface INFO:
	 stdout 2018-10-12T13:50:48.584522: using tolerance 0.001
...
181012-13:50:48,833 nipype.interface INFO:
	 stdout 2018-10-12T13:50:48.833009: writing exampleBrainSegmentationPosteriors3_thickness.nii.gz
Traceback (most recent call last):
  File "nipype-undefined-output.py", line 9, in <module>
    print(cort_thick.run())
  File "/home/yoh/deb/gits/pkg-exppsy/nipype/nipype/interfaces/base/core.py", line 524, in run
    outputs = self.aggregate_outputs(runtime)
  File "/home/yoh/deb/gits/pkg-exppsy/nipype/nipype/interfaces/base/core.py", line 602, in aggregate_outputs
    predicted_outputs = self._list_outputs()
  File "/home/yoh/deb/gits/pkg-exppsy/nipype/nipype/interfaces/ants/segmentation.py", line 254, in _list_outputs
    (name, self.inputs.output_image, ext)))
TypeError: sequence item 1: expected string or Unicode, _Undefined found

```

# System

```shell
$> python -c "import nipype; from pprint import pprint; pprint(nipype.get_info())"
{'commit_hash': '3ec80655f',
 'commit_source': 'repository',
 'networkx_version': '2.1',
 'nibabel_version': '2.3.1',
 'nipype_version': '1.1.4-dev+g3ec80655f',
 'numpy_version': '1.14.5',
 'pkg_path': '/home/yoh/deb/gits/pkg-exppsy/nipype/nipype',
 'scipy_version': '0.19.1',
 'sys_executable': '/home/yoh/proj/flywheel/gearificator/venvs/dev/bin/python',
 'sys_platform': 'linux2',
 'sys_version': '2.7.14 (default, Sep 17 2017, 18:50:44) \n[GCC 7.2.0]',
 'traits_version': '4.6.0'}
```



Discussion:
actually both issues have the same root, PR is coming

Resolving patch:
diff --git a/nipype/interfaces/ants/segmentation.py b/nipype/interfaces/ants/segmentation.py
--- a/nipype/interfaces/ants/segmentation.py
+++ b/nipype/interfaces/ants/segmentation.py
@@ -249,9 +249,9 @@ def _gen_filename(self, name):
 
     def _list_outputs(self):
         outputs = self._outputs().get()
-        _, name, ext = split_filename(os.path.abspath(self.inputs.input_wm))
-        outputs['output_image'] = os.path.join(os.getcwd(), ''.join(
-            (name, self.inputs.output_image, ext)))
+        if not outputs.get('output_image', None) \
+                or not isdefined(outputs['output_image']):
+            outputs['output_image'] = self._gen_filename('output_image')
         return outputs
 
 


Test patch: