NIPY logo

Table Of Contents

Previous topic

algorithms.rapidart

Next topic

interfaces.freesurfer

This Page

interfaces.base

Module: interfaces.base

Inheritance diagram for nipype.interfaces.base:

digraph inheritancebf445f24e6 { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "base.InterfaceResult" [shape=ellipse,URL="#nipype.interfaces.base.InterfaceResult",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "base.Bunch" [shape=ellipse,URL="#nipype.interfaces.base.Bunch",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "base.Interface" [shape=ellipse,URL="#nipype.interfaces.base.Interface",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "base.CommandLine" [shape=ellipse,URL="#nipype.interfaces.base.CommandLine",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "base.Interface" -> "base.CommandLine" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Package contains interfaces for using existing functionality in other packages

Exaples FSL, matlab/SPM , afni

Requires Packages to be installed

Classes

Bunch

class nipype.interfaces.base.Bunch(*args, **kwargs)

Bases: object

Dictionary-like class that provides attribute-style access to it’s items.

A Bunch is a simple container that stores it’s items as class attributes. Internally all items are stored in a dictionary and the class exposes several of the dictionary methods.

Notes

The Bunch pattern came from the Python Cookbook:

[1]A. Martelli, D. Hudgeon, “Collecting a Bunch of Named Items”, Python Cookbook, 2nd Ed, Chapter 4.18, 2005.

Examples

>>> from nipype.interfaces.base import Bunch
>>> inputs = Bunch(infile='subj.nii', fwhm=6.0, register_to_mean=True)
>>> inputs
Bunch(fwhm=6.0, infile='subj.nii', register_to_mean=True)
>>> inputs.register_to_mean = False
>>> inputs
Bunch(fwhm=6.0, infile='subj.nii', register_to_mean=False)
__init__(*args, **kwargs)
dictcopy()
returns a deep copy of existing Bunch as a dictionary
get(*args)
Support dictionary get() functionality
iteritems()
iterates over bunch attributes as key,value pairs
update(*args, **kwargs)

update existing attribute, or create new attribute

Note: update is very much like HasTraits.set

CommandLine

class nipype.interfaces.base.CommandLine(*args, **inputs)

Bases: nipype.interfaces.base.Interface

Encapsulate a command-line function along with the arguments and options.

Provides a convenient mechanism to build a command line with it’s arguments and options incrementally. A CommandLine object can be reused, and it’s arguments and options updated. The CommandLine class is the base class for all nipype.interfaces classes.

Parameters:

args : string

A string representing the command and it’s arguments.

inputs : mapping

key value pairs that populate a Bunch()

Attributes:

args : list

The command, it’s arguments and options store in a list of strings. [‘ls’, ‘-al’] These are added to command line string first

inputs : Bunch of key,value inputs

The only valid key for CommandLine is args Other keys are not recognized in CommandLine, and require parsing in subclasses if there are args=[‘ls’,’-al’] These are added to command line string before simple positional args

Returns :

——- :

cmd : CommandLine

A CommandLine object that can be run and/or updated.

Notes

When subclassing CommandLine, you will generally override at least:
_compile_command, and run

Also quite possibly __init__ but generally not _runner

Examples

>>> from nipype.interfaces.base import CommandLine
>>> cmd = CommandLine('echo')
>>> cmd.cmdline
'echo'
>>> res = cmd.run(None, 'foo')
>>> print res.runtime.stdout
foo
<BLANKLINE>

You could pass arguments in the following ways and all result in the same command. >>> lscmd = CommandLine(‘ls’, ‘-l’, ‘-t’) >>> lscmd.cmdline ‘ls -l -t’ >>> lscmd = CommandLine(‘ls -l -t’) >>> lscmd.cmdline ‘ls -l -t’ >>> lscmd = CommandLine(args=[‘ls’, ‘-l’, ‘-t’]) >>> lscmd.cmdline ‘ls -l -t’

__init__(*args, **inputs)
aggregate_outputs()

Called to populate outputs

Currently, search for discussion of this on private e-mails between Dav and Satra (ugh!). This needs to get in here!

cmdline
get_input_info()

Provides information about file inputs to copy or link to cwd.

Notes

see spm.Realign.get_input_info

run(cwd=None, *args, **inputs)

Execute the command.

Parameters:

cwd : path

Where do we effectively execute this command? (default: os.getcwd())

args : list

additional arguments that will be appended to inputs.args

inputs : mapping

additional key,value pairs will update inputs it will overwrite existing key, value pairs

Returns:

results : InterfaceResult Object

A Bunch object with a copy of self in interface

Interface

class nipype.interfaces.base.Interface(*args, **inputs)

Bases: object

This is the template for Interface objects.

It provides no functionality. It defines the necessary attributes and methods all Interface objects should have.

Everything in inputs should also be a possible (explicit?) argument to .__init__()

__init__(*args, **inputs)
Initialize command with given args and inputs.
aggregate_outputs()

Called to populate outputs

Currently, search for discussion of this on private e-mails between Dav and Satra (ugh!). This needs to get in here!

run(cwd=None)
Execute the command.

InterfaceResult

class nipype.interfaces.base.InterfaceResult(interface, runtime, outputs=None)

Bases: object

Object that contains the results of running a particular Interface.

Attributes:

interface : object

A copy of the Interface that was run to generate this result.

outputs : Bunch

An Interface specific Bunch that contains all possible files that are generated by the interface. The outputs are used as the inputs to another node in when interfaces are used in the pipeline.

runtime : Bunch

Contains attributes that describe the runtime environment when the Interface was run. Contains the attributes:

  • cmdline : The command line string that was executed
  • cwd : The directory the cmdline was executed in.
  • stdout : The output of running the cmdline.
  • stderr : Any error messages output from running cmdline.
  • returncode : The code returned from running the cmdline.
__init__(interface, runtime, outputs=None)

Function

nipype.interfaces.base.load_template(name)

Load a template from the script_templates directory

Parameters:

name : str

The name of the file to load

Returns:

template : string.Template