nipype
nipype copied to clipboard
Optional mask file of ants.ConvertScalarImageToRGB a default value of "none" may cause workflow to crash
Summary
The ants.ConvertScalarImageToRGB
wraps the cmdline tool ConvertScalarImageToRGB
, which takes mainly positional arguments. Some of the positional arguments are optional, such as the mask file,
so to omit the mask_file
, a string value of "none"
must be formatted as the 3rd argument.
The inputspec is correct in setting mask_file as an optional argument with a default_value of "none"
:
mask_image = traits.File(
"none", argstr="%s", exists=True,desc="mask image", position=3, usedefault=True
)
However, if the optional mask_image
is not specified, nipype will in some cases throw a traits.trait_errors.TraitError
, since the file "none"
does not exist. Interestingly, this error is only thrown in some cases such as when incoorporating and running the node in a multiprocess workflow (see provided snippet).
Actual behavior
Running the provided snippet:
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 148, in __init__
mp_context=mp_context,
TypeError: __init__() got an unexpected keyword argument 'initializer'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.6/concurrent/futures/process.py", line 169, in _process_worker
call_item = call_queue.get(block=True)
File "/usr/lib/python3.6/multiprocessing/queues.py", line 113, in get
return _ForkingPickler.loads(res)
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/traits/has_traits.py", line 1341, in __setstate__
self.trait_set(trait_change_notify=trait_change_notify, **state)
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/traits/has_traits.py", line 1434, in trait_set
setattr(self, name, value)
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/traits/trait_types.py", line 1397, in validate
self.error(object, name, value)
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/traits/base_trait_handler.py", line 75, in error
object, name, self.full_info(object, name, value), value
traits.trait_errors.TraitError: The 'mask_image' trait of a ConvertScalarImageToRGBInputSpec instance must be a filename or object implementing the os.PathLike interface, but a value of 'none' <class 'str'> was specified.
exception calling callback for <Future at 0x7f589b682c88 state=finished raised BrokenProcessPool>
Traceback (most recent call last):
File "/usr/lib/python3.6/concurrent/futures/_base.py", line 324, in _invoke_callbacks
callback(self)
File "/homes/hinge/venv/MRI-to-PET/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 159, in _async_callback
result = args.result()
File "/usr/lib/python3.6/concurrent/futures/_base.py", line 425, in result
return self.__get_result()
File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
210806-19:25:59,298 nipype.workflow INFO:
[MultiProc] Running 1 tasks, and 0 jobs ready. Free memory (GB): 6.69/6.89, Free processors: 3/4.
Currently running:
* visualizations.test_node
Expected behavior
I expected this snippet to run without any errors
How to replicate the behavior
See below
Script/Workflow details
from nipype.interfaces.utility.base import IdentityInterface
from nipype.pipeline import Node, Workflow
from nipype.interfaces import ants
inputnode = Node(IdentityInterface(fields=("test_file")),name="inputnode")
## Supply a nifti file as input
inputnode.inputs.test_file = "/homes/hinge/MRI-to-PET/data/processed/TEST/NC0005_001/mr.nii.gz"
_im_to_rgb = ants.ConvertScalarImageToRGB()
_im_to_rgb.inputs.dimension = 3
_im_to_rgb.inputs.colormap = "jet"
_im_to_rgb.inputs.minimum_input = 0
_im_to_rgb.inputs.maximum_input = 1
im_to_rgb = Node(_im_to_rgb, name="test_node")
workflow = Workflow("visualizations")
workflow.connect([
(inputnode,im_to_rgb,[("test_file","input_image")]),
])
## Calling workflow.inputs will yield a similar error
#workflow.inputs
workflow.run(plugin='MultiProc')
## Workflow.run() works fine
#workflow.run()
Platform details:
{'commit_hash': 'cc7b3ae71',
'commit_source': 'repository',
'networkx_version': '2.5',
'nibabel_version': '3.1.1',
'nipype_version': '1.6.1',
'numpy_version': '1.19.5',
'pkg_path': '/homes/hinge/projects/nipype/nipype',
'scipy_version': '1.5.2',
'sys_executable': '/homes/hinge/venv/MRI-to-PET/bin/python',
'sys_platform': 'linux',
'sys_version': '3.6.13 (default, May 3 2021, 02:51:47) \n[GCC 9.3.0]',
'traits_version': '6.2.0'}
Execution environment
Choose one
- My python environment outside container