nipype
nipype copied to clipboard
Nipype does not work with in_channel inputs for SPM
trafficstars
Summary
I am not able to create workflows for nipype objects that as an input that in_channel instead of in_files. However, if the SPM function takes an in_files the program works fine. This makes it impossible to connect nodes in a workflow.
Actual behavior
It appears that the script is trying to find the nifti file in a place that does not exist instead of the correct path. See Error below:
210818-16:25:57,759 nipype.workflow INFO:
Workflow preproc settings: ['check', 'execution', 'logging', 'monitoring']
210818-16:25:57,765 nipype.workflow INFO:
Running serially.
210818-16:25:57,765 nipype.workflow INFO:
[Node] Setting-up "preproc.realign" in "/home/tonnar/VBM/preproc/realign".
210818-16:25:57,767 nipype.workflow WARNING:
[Node] Error on "preproc.realign" (/home/tonnar/VBM/preproc/realign)
210818-16:25:57,769 nipype.workflow ERROR:
Node realign failed to run on host tonnars-computer.
210818-16:25:57,770 nipype.workflow ERROR:
Saving crash info to /home/tonnar/VBM/crash-20210818-162557-tonnar-realign-98f5acfc-4500-4c12-96ef-1992dd848f93.pklz
Traceback (most recent call last):
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/pipeline/plugins/linear.py", line 45, in run
node.run(updatehash=updatehash)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
result = self._run_interface(execute=True)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
return self._run_command(execute)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 715, in _run_command
self._copyfiles_to_wd(execute=execute)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 817, in _copyfiles_to_wd
setattr(self.inputs, info["key"], newfiles)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 425, in validate
value = super(MultiObject, self).validate(objekt, name, newvalue)
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/trait_types.py", line 2515, in validate
return TraitListObject(self, object, name, value)
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/trait_list_object.py", line 582, in __init__
super().__init__(
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/trait_list_object.py", line 213, in __init__
super().__init__(self.item_validator(item) for item in iterable)
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/trait_list_object.py", line 213, in <genexpr>
super().__init__(self.item_validator(item) for item in iterable)
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/trait_list_object.py", line 865, in _item_validator
return trait_validator(object, self.name, value)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
value = super(File, self).validate(objekt, name, value, return_pathlike=True)
File "/home/tonnar/.local/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
self.error(objekt, name, str(value))
File "/home/tonnar/.local/lib/python3.9/site-packages/traits/base_trait_handler.py", line 74, in error
raise TraitError(
traits.trait_errors.TraitError: Each element of the 'channel_files' trait of a NewSegmentInputSpec instance must be a pathlike object or string representing an existing file, but a value of '/home/tonnar/VBM/preproc/realign/somefuncrun.nii' <class 'str'> was specified.
When creating this crashfile, the results file corresponding
to the node could not be found.
210818-16:25:57,771 nipype.workflow INFO:
***********************************
210818-16:25:57,771 nipype.workflow ERROR:
could not run node: preproc.realign
210818-16:25:57,771 nipype.workflow INFO:
crashfile: /home/tonnar/VBM/crash-20210818-162557-tonnar-realign-98f5acfc-4500-4c12-96ef-1992dd848f93.pklz
210818-16:25:57,771 nipype.workflow INFO:
***********************************
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_6662/1992093865.py in <module>
1 workflow.add_nodes([smoother, realigner])
2 workflow.connect(realigner, 'native_class_images', smoother, 'in_files')
----> 3 workflow.run()
~/.local/lib/python3.9/site-packages/nipype/pipeline/engine/workflows.py in run(self, plugin, plugin_args, updatehash)
636 if str2bool(self.config["execution"]["create_report"]):
637 self._write_report_info(self.base_dir, self.name, execgraph)
--> 638 runner.run(execgraph, updatehash=updatehash, config=self.config)
639 datestr = datetime.utcnow().strftime("%Y%m%dT%H%M%S")
640 if str2bool(self.config["execution"]["write_provenance"]):
~/.local/lib/python3.9/site-packages/nipype/pipeline/plugins/linear.py in run(self, graph, config, updatehash)
67
68 os.chdir(old_wd) # Return wherever we were before
---> 69 report_nodes_not_run(notrun)
~/.local/lib/python3.9/site-packages/nipype/pipeline/plugins/tools.py in report_nodes_not_run(notrun)
94 logger.debug(subnode._id)
95 logger.info("***********************************")
---> 96 raise RuntimeError(
97 ("Workflow did not execute cleanly. " "Check log for details")
98 )
RuntimeError: Workflow did not execute cleanly. Check log for details
Expected behavior
I expected the code to work just fine and run as it would. If you change the script to the exact tutorial the code runs correctly. However, like mentioned in the title if the code takes an in_channel input it does not work such as NewSegement or DARTEL.
How to replicate the behavior
You simply need to have the first file not have the absolute path.
Script/Workflow details
import nipype.interfaces.spm as spm # the spm interfaces
import nipype.pipeline.engine as pe # the workflow and node wrappers
realigner = pe.Node(interface=spm.NewSegment(), name='realign')
realigner.inputs.channel_files = ['somefuncrun.nii']
smoother = pe.Node(interface=spm.Smooth(fwhm=6), name='smooth')
workflow = pe.Workflow(name='preproc')
workflow.base_dir = '.'
workflow.add_nodes([smoother, realigner])
workflow.connect(realigner, 'native_class_images', smoother, 'in_files')
workflow.run()
Platform details:
{'commit_hash': '0289137',
'commit_source': 'installation',
'networkx_version': '2.6.2',
'nibabel_version': '3.2.1',
'nipype_version': '1.6.1',
'numpy_version': '1.21.1',
'pkg_path': '/home/tonnar/.local/lib/python3.9/site-packages/nipype',
'scipy_version': '1.7.0',
'sys_executable': '/home/tonnar/miniconda3/envs/FEOBV/bin/python',
'sys_platform': 'linux',
'sys_version': '3.9.6 | packaged by conda-forge | (default, Jul 11 2021, '
'03:39:48) \n'
'[GCC 9.3.0]',
'traits_version': '6.2.0'}
Execution environment
Jupyter Lab
Choose one
- Container [Tag: ???]
- My python environment inside container [Base Tag: ???]
- My python environment outside container