美文网首页脑核磁共振数据处理——fMRI
Nipype学习笔记(4)——Nipype中的错误与调试

Nipype学习笔记(4)——Nipype中的错误与调试

作者: 韧心222 | 来源:发表于2018-07-06 10:40 被阅读12次

    8.Nipype中的Error

    编写一两段程序,要是不出现几个错误,简直都对不起程序猿/程序媛这个光荣的名号了。教程中给出了若干种可能,以我自身为例就遇到过其中的绝大多数。在计算过程中,尽管Nipype会给出一部分的错误信息,比如:

    180514-09:15:24,87 workflow INFO:
         Workflow preprocWF settings: ['check', 'execution', 'logging', 'monitoring']
    180514-09:15:24,92 workflow INFO:
         Running serially.
    180514-09:15:24,93 workflow INFO:
         [Node] Setting-up "preprocWF.selectfiles" in "/home/neuro/nipype_tutorial/notebooks/working_dir/preprocWF/selectfiles".
    180514-09:15:24,97 workflow INFO:
         [Node] Running "selectfiles" ("nipype.interfaces.io.SelectFiles")
    180514-09:15:24,105 workflow WARNING:
         [Node] Error on "preprocWF.selectfiles" (/home/neuro/nipype_tutorial/notebooks/working_dir/preprocWF/selectfiles)
    180514-09:15:24,108 workflow ERROR:
         Node selectfiles failed to run on host 7eb1beccba8f.
    180514-09:15:24,111 workflow ERROR:
         Saving crash info to /home/neuro/nipype_tutorial/notebooks/crash-20180514-091524-neuro-selectfiles-648d7b9b-092e-479a-b79c-c04ce2ba5774.pklz
    Traceback (most recent call last):
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 44, in run
        node.run(updatehash=updatehash)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 480, in run
        result = self._run_interface(execute=True)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 564, in _run_interface
        return self._run_command(execute)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 644, in _run_command
        result = self._interface.run(cwd=outdir)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 521, in run
        outputs = self.aggregate_outputs(runtime)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 595, in aggregate_outputs
        predicted_outputs = self._list_outputs()
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/io.py", line 1402, in _list_outputs
        raise IOError(msg)
    OSError: No files were found matching func template: /data/ds000114/sub-11/ses-test/func/sub-11_ses-test_task-fingerfootlips_bold.nii.gz
    
    180514-09:15:24,112 workflow INFO:
         ***********************************
    180514-09:15:24,113 workflow ERROR:
         could not run node: preprocWF.selectfiles
    180514-09:15:24,114 workflow INFO:
         crashfile: /home/neuro/nipype_tutorial/notebooks/crash-20180514-091524-neuro-selectfiles-648d7b9b-092e-479a-b79c-c04ce2ba5774.pklz
    180514-09:15:24,114 workflow INFO:
         ***********************************
    RuntimeError: Workflow did not execute cleanly. Check log for details
    

    从直接输出的Error Info中我们可以看到,这是一个OSError,主要是没有文件能够匹配给出的模板。但是,这些信息有时候却不能满足我们的需要。有时我们仍想查看更为具体的Error信息,就可以在命令行中使用如下命令来读取crashfile

    nipypecli crash <crashfile.pklz>
    

    执行之后就会看到:

    File: /home/neuro/nipype_tutorial/notebooks/crash-20180514-091524-neuro-selectfiles-648d7b9b-092e-479a-b79c-c04ce2ba5774.pklz
    Node: preprocWF.selectfiles
    Working directory: /home/neuro/nipype_tutorial/notebooks/working_dir/preprocWF/selectfiles
    
    
    Node inputs:
    
    base_directory = /data/ds000114
    force_lists = False
    ignore_exception = False
    raise_on_empty = True
    sort_filelist = True
    subject_id = sub-11
    
    
    
    Traceback: 
    Traceback (most recent call last):
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 44, in run
        node.run(updatehash=updatehash)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 480, in run
        result = self._run_interface(execute=True)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 564, in _run_interface
        return self._run_command(execute)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 644, in _run_command
        result = self._interface.run(cwd=outdir)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 521, in run
        outputs = self.aggregate_outputs(runtime)
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 595, in aggregate_outputs
        predicted_outputs = self._list_outputs()
      File "/opt/conda/envs/neuro/lib/python3.6/site-packages/nipype/interfaces/io.py", line 1402, in _list_outputs
        raise IOError(msg)
    OSError: No files were found matching func template: /data/ds000114/sub-11/ses-test/func/sub-11_ses-test_task-fingerfootlips_bold.nii.gz
    

    一些更为具体的描述信息,包括节点的输入等,便于我们查找问题。

    此外,通过-r参数,还可以使得崩溃的节点重新运行。(注意,这个我没有试过,只是官方的教程提到了,在这里记录一下)

    如果所使用的模块不存在或没有进行配置,就需要手工来安装并进行配置,对于最常用的SPM可以这样选择不同的版本:

    from nipype.interfaces.matlab import MatlabCommand
    MatlabCommand.set_default_paths('/usr/local/MATLAB/R2017a/toolbox/spm12')
    

    9. Debug

    由于Nipype采用的Pipeline的处理方式,节点内部的操作都是封闭的,因此要想进行调试还是很不容易的。官方给出了一些调试的基本建议,包括:

    1. 从单个被试开始,按照LinearMultiProcSGE的顺序,逐步完善程序
    2. 启用调试模式:
    from nipype import config
    config.enable_debug_mode()
    

    下面这个命令我没搞清楚是啥意思,官方的说法是:as the first import of your nipype script. To enable debug logging use:

    from nipype import logging
    logging.update_logging(config)
    

    可能要通过实践来检验效果了。

    官方还给了一些其他的调试方法和建议,我个人感觉现在用不到,就不记录了,先暂且放下来,以后慢慢消化吧。

    这可能是这个系列的最后一部了,最后这些东西比较杂乱,正常搭建Workflow的时候基本用不到,下一步我想搭建一个类似于Gretna的Workflow,有机会的话把这个Workflow封装一下,做一个小软件。

    相关文章

      网友评论

        本文标题:Nipype学习笔记(4)——Nipype中的错误与调试

        本文链接:https://www.haomeiwen.com/subject/wmhvuftx.html