如何使用NiPype连接两个简单函数?

如何使用NiPype连接两个简单函数?,nipype,Nipype,我正在尝试用NiPype替换我们的内部管道基础设施 作为测试,我想连接到简单函数,其中第一个函数得到一个输入,经过一些计算后返回一个输出,该输出作为输入用于第二个函数: import numpy import nipype.pipeline.engine as pe from nipype.interfaces.utility import Function from pipyTestWheels import * def Connectivity( dtiVolume ): prin

我正在尝试用NiPype替换我们的内部管道基础设施

作为测试,我想连接到简单函数,其中第一个函数得到一个输入,经过一些计算后返回一个输出,该输出作为输入用于第二个函数:

import numpy
import nipype.pipeline.engine as pe
from nipype.interfaces.utility import Function
from pipyTestWheels import *


def Connectivity( dtiVolume ):

  print "  CONNECTIVITY1::START"

  print "reading dti Volume " + dtiVolume

  print ">>> performing connectivity *nom*nom*nom*"

  a = numpy.zeros( ( 1000, 1000 ) )

  print "  CONNECTIVITY1::END"

  trkFile = 'another trk file'

  return trkFile

def RegisterFibers( trkFile ):

  print "  REGISTERFIBERS::START"

  print "reading trk File " + trkFile

  print ">>> performing trkFile registration"

  trkFileRegistered = '/tmp/tracksRegistered.trk'

  print "  REGISTERFIBERS::END"

  return trkFileRegistered


def test():

  ConnectivityNode = pe.Node( name='connectivity', interface=Function( function=Connectivity, input_names=['dtiVolume'], output_names=['trkFile'] ) )
  RegisterFibersNode = pe.Node( name='registerFibers', interface=Function( function=RegisterFibers, input_names=['trkFile'], output_names=['trkFileRegistered'] ) )

  pipeline = pe.Workflow( name='testWf' )
  pipeline.add_nodes( [ConnectivityNode, RegisterFibersNode] )
  pipeline.run( dtiVolume='safsafa' )
我得到以下错误:

Traceback (most recent call last):
  File "pipyTestNipype.py", line 65, in <module>
    test()
  File "pipyTestNipype.py", line 46, in test
    pipeline.run( dtiVolume='safsafa' )
TypeError: run() got an unexpected keyword argument 'dtiVolume'
回溯(最近一次呼叫最后一次):
文件“pipyTestNipype.py”,第65行,在
测试()
测试中第46行的文件“pipyTestNipype.py”
pipeline.run(dtiVolume='safa')
TypeError:run()获得意外的关键字参数“dtiVolume”
如果我只运行pipeline.run(),则会出现以下错误:

INFO:workflow:['execution', 'logging']
INFO:workflow:Running serially.
INFO:workflow:Executing node registerFibers in dir: /tmp/tmpxpW0lR/testWf/registerFibers
ERROR:workflow:['Node registerFibers failed to run on host ipmi.']
INFO:workflow:Saving crash info to /net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-registerFibers.npz
INFO:workflow:Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py", line 35, in run
    node.run(updatehash=updatehash)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1141, in run
    self._run_interface(execute=True)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1161, in _run_interface
    self._result = self._run_command(execute)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1253, in _run_command
    result = self._interface.run()
  File "/usr/lib/pymodules/python2.7/nipype/interfaces/base.py", line 775, in run
    runtime = self._run_interface(runtime)
  File "/usr/lib/pymodules/python2.7/nipype/interfaces/utility.py", line 382, in _run_interface
    out = function_handle(**args)
TypeError: RegisterFibers() takes exactly 1 argument (0 given)
Interface Function failed to run. 

INFO:workflow:Executing node connectivity in dir: /tmp/tmptN84LP/testWf/connectivity
ERROR:workflow:['Node connectivity failed to run on host ipmi.']
INFO:workflow:Saving crash info to /net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-connectivity.npz
INFO:workflow:Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py", line 35, in run
    node.run(updatehash=updatehash)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1141, in run
    self._run_interface(execute=True)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1161, in _run_interface
    self._result = self._run_command(execute)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 1253, in _run_command
    result = self._interface.run()
  File "/usr/lib/pymodules/python2.7/nipype/interfaces/base.py", line 775, in run
    runtime = self._run_interface(runtime)
  File "/usr/lib/pymodules/python2.7/nipype/interfaces/utility.py", line 382, in _run_interface
    out = function_handle(**args)
TypeError: Connectivity() takes exactly 1 argument (0 given)
Interface Function failed to run. 

INFO:workflow:***********************************
ERROR:workflow:could not run node: testWf.registerFibers
INFO:workflow:crashfile: /net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-registerFibers.npz
ERROR:workflow:could not run node: testWf.connectivity
INFO:workflow:crashfile: /net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-connectivity.npz
INFO:workflow:***********************************
Traceback (most recent call last):
  File "pipyTestNipype.py", line 65, in <module>
    test()
  File "pipyTestNipype.py", line 46, in test
    pipeline.run()
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py", line 467, in run
    runner.run(execgraph, updatehash=updatehash, config=self.config)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py", line 49, in run
    report_nodes_not_run(notrun)
  File "/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/base.py", line 81, in report_nodes_not_run
    raise RuntimeError('Workflow did not execute cleanly. Check log for details')
RuntimeError: Workflow did not execute cleanly. Check log for details
INFO:workflow:['execution','logging']
信息:工作流:连续运行。
信息:工作流:在dir:/tmp/tmpxpW0lR/testWf/registerFibers中执行节点registerFibers
错误:工作流:[“节点注册表文件未能在主机ipmi上运行”。]
信息:工作流:将崩溃信息保存到/net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-registerFibers.npz
信息:工作流:回溯(最近一次呼叫最后一次):
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py”,第35行,正在运行
运行(updatehash=updatehash)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1141行,正在运行
self.\u运行\u接口(execute=True)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1161行,在运行界面中
self.\u结果=self.\u运行\u命令(执行)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1253行,在_run_命令中
结果=self.\u interface.run()
文件“/usr/lib/pymodules/python2.7/nipype/interfaces/base.py”,第775行,正在运行
运行时=自我运行界面(运行时)
文件“/usr/lib/pymodules/python2.7/nipype/interfaces/utility.py”,第382行,在运行界面中
out=函数\句柄(**args)
TypeError:RegisterFibers()正好接受1个参数(给定0)
接口函数无法运行。
信息:工作流:在目录中执行节点连接:/tmp/tmptN84LP/testWf/connectivity
错误:工作流:[“节点连接无法在主机ipmi上运行”。]
信息:工作流:将崩溃信息保存到/net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-connectivity.npz
信息:工作流:回溯(最近一次呼叫最后一次):
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py”,第35行,正在运行
运行(updatehash=updatehash)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1141行,正在运行
self.\u运行\u接口(execute=True)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1161行,在运行界面中
self.\u结果=self.\u运行\u命令(执行)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第1253行,在_run_命令中
结果=self.\u interface.run()
文件“/usr/lib/pymodules/python2.7/nipype/interfaces/base.py”,第775行,正在运行
运行时=自我运行界面(运行时)
文件“/usr/lib/pymodules/python2.7/nipype/interfaces/utility.py”,第382行,在运行界面中
out=函数\句柄(**args)
TypeError:Connectivity()正好接受1个参数(给定0)
接口函数无法运行。
信息:工作流:***********************************
错误:工作流:无法运行节点:testWf.registerFibers
信息:工作流:crashfile:/net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-registerFibers.npz
错误:工作流:无法运行节点:testWf.connectivity
信息:工作流:crashfile:/net/pretoria/local_mount/space/pretoria/2/chb/users/daniel.haehn/Projects/scripts/crash-20120215-101717-daniel.haehn-connectivity.npz
信息:工作流:***********************************
回溯(最近一次呼叫最后一次):
文件“pipyTestNipype.py”,第65行,在
测试()
测试中第46行的文件“pipyTestNipype.py”
管道运行()
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/engine.py”,第467行,正在运行
runner.run(execgraph,updatehash=updatehash,config=self.config)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/linear.py”,第49行,正在运行
报告节点未运行(未运行)
文件“/usr/lib/pymodules/python2.7/nipype/pipeline/plugins/base.py”,第81行,报告中的节点未运行
raise RUNTIMERROR('工作流未干净地执行。有关详细信息,请检查日志')
运行时错误:工作流未干净执行。查看日志以了解详细信息
我该怎么办

谢谢

试试这个:

import nipype.pipeline.engine as pe
from nipype.interfaces.utility import Function


def Connectivity(dtiVolume):
    import numpy
    print "  CONNECTIVITY1::START"
    print "reading dti Volume " + dtiVolume
    print ">>> performing connectivity *nom*nom*nom*"
    a = numpy.zeros((1000, 1000))
    print "  CONNECTIVITY1::END"
    trkFile = 'another trk file'
    return trkFile


def RegisterFibers(trkFile):
    print "  REGISTERFIBERS::START"
    print "reading trk File " + trkFile
    print ">>> performing trkFile registration"
    trkFileRegistered = '/tmp/tracksRegistered.trk'
    print "  REGISTERFIBERS::END"
    return trkFileRegistered


def test():
    ConnectivityNode = pe.Node(name='connectivity', interface=Function(function=Connectivity, input_names=['dtiVolume'], output_names=['trkFile']))
    ConnectivityNode.inputs.dtiVolume = 'safsafa'
    RegisterFibersNode = pe.Node(name='registerFibers', interface=Function(function=RegisterFibers, input_names=['trkFile'], output_names=['trkFileRegistered']))

    pipeline = pe.Workflow(name='testWf')
    pipeline.connect(ConnectivityNode, 'trkFile', RegisterFibersNode, 'trkFile')
    pipeline.run()
基本上,您没有将两个节点连接在一起,而是尝试将输入设置为run()方法的参数,而不是在节点级别进行设置。希望这有帮助。

试试这个:

import nipype.pipeline.engine as pe
from nipype.interfaces.utility import Function


def Connectivity(dtiVolume):
    import numpy
    print "  CONNECTIVITY1::START"
    print "reading dti Volume " + dtiVolume
    print ">>> performing connectivity *nom*nom*nom*"
    a = numpy.zeros((1000, 1000))
    print "  CONNECTIVITY1::END"
    trkFile = 'another trk file'
    return trkFile


def RegisterFibers(trkFile):
    print "  REGISTERFIBERS::START"
    print "reading trk File " + trkFile
    print ">>> performing trkFile registration"
    trkFileRegistered = '/tmp/tracksRegistered.trk'
    print "  REGISTERFIBERS::END"
    return trkFileRegistered


def test():
    ConnectivityNode = pe.Node(name='connectivity', interface=Function(function=Connectivity, input_names=['dtiVolume'], output_names=['trkFile']))
    ConnectivityNode.inputs.dtiVolume = 'safsafa'
    RegisterFibersNode = pe.Node(name='registerFibers', interface=Function(function=RegisterFibers, input_names=['trkFile'], output_names=['trkFileRegistered']))

    pipeline = pe.Workflow(name='testWf')
    pipeline.connect(ConnectivityNode, 'trkFile', RegisterFibersNode, 'trkFile')
    pipeline.run()
基本上,您没有将两个节点连接在一起,而是尝试将输入设置为run()方法的参数,而不是在节点级别进行设置。希望这有帮助