% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Bjarne]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}


\title{nipype Documentation}
\date{April 15, 2011, 14:40 PDT}
\release{0.4.dev}
\author{Neuroimaging in Python team}
\newcommand{\sphinxlogo}{}
\renewcommand{\releasename}{Release}
\makeindex

\makeatletter
\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
    \let\PYG@ul=\relax \let\PYG@tc=\relax%
    \let\PYG@bc=\relax \let\PYG@ff=\relax}
\def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
\def\PYG@toks#1+{\ifx\relax#1\empty\else%
    \PYG@tok{#1}\expandafter\PYG@toks\fi}
\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
    \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}

\def\PYG@tok@gd{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\def\PYG@tok@gu{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\def\PYG@tok@gt{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.25,0.82}{##1}}}
\def\PYG@tok@gs{\let\PYG@bf=\textbf}
\def\PYG@tok@gr{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\def\PYG@tok@cm{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\def\PYG@tok@vg{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\def\PYG@tok@m{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@mh{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@cs{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}\def\PYG@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PYG@tok@ge{\let\PYG@it=\textit}
\def\PYG@tok@vc{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\def\PYG@tok@il{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@go{\def\PYG@tc##1{\textcolor[rgb]{0.19,0.19,0.19}{##1}}}
\def\PYG@tok@cp{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@gi{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\def\PYG@tok@gh{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\def\PYG@tok@ni{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.84,0.33,0.22}{##1}}}
\def\PYG@tok@nl{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.13,0.44}{##1}}}
\def\PYG@tok@nn{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\def\PYG@tok@no{\def\PYG@tc##1{\textcolor[rgb]{0.38,0.68,0.84}{##1}}}
\def\PYG@tok@na{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@nb{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@nc{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\def\PYG@tok@nd{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
\def\PYG@tok@ne{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@nf{\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
\def\PYG@tok@si{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.44,0.63,0.82}{##1}}}
\def\PYG@tok@s2{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@vi{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\def\PYG@tok@nt{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.45}{##1}}}
\def\PYG@tok@nv{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\def\PYG@tok@s1{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@gp{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\def\PYG@tok@sh{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@ow{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@sx{\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\def\PYG@tok@bp{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@c1{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\def\PYG@tok@kc{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@c{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\def\PYG@tok@mf{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@err{\def\PYG@bc##1{\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{##1}}}
\def\PYG@tok@kd{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@ss{\def\PYG@tc##1{\textcolor[rgb]{0.32,0.47,0.09}{##1}}}
\def\PYG@tok@sr{\def\PYG@tc##1{\textcolor[rgb]{0.14,0.33,0.53}{##1}}}
\def\PYG@tok@mo{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@mi{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\def\PYG@tok@kn{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@o{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\def\PYG@tok@kr{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@s{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@kp{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@w{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\def\PYG@tok@kt{\def\PYG@tc##1{\textcolor[rgb]{0.56,0.13,0.00}{##1}}}
\def\PYG@tok@sc{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@sb{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@k{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYG@tok@se{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\def\PYG@tok@sd{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}

\def\PYGZbs{\char`\\}
\def\PYGZus{\char`\_}
\def\PYGZob{\char`\{}
\def\PYGZcb{\char`\}}
\def\PYGZca{\char`\^}
% for compatibility with earlier versions
\def\PYGZat{@}
\def\PYGZlb{[}
\def\PYGZrb{]}
\makeatother

\begin{document}

\maketitle
\tableofcontents
\phantomsection\label{documentation::doc}


Follow this link for: \href{http://www.mit.edu/~satra/nipype-nightly/}{Developer version documentation}

Contents:


\chapter{User Guide}
\label{users/index:user-guide}\label{users/index:documentation}\label{users/index::doc}\label{users/index:users-guide-index}\label{users/index:id1}\begin{quote}\begin{description}
\item[{Release}] \leavevmode
0.4.dev

\item[{Date}] \leavevmode
April 14, 2011, 19:11 PDT

\end{description}\end{quote}


\section{Download and install}
\label{users/install::doc}\label{users/install:download-and-install}\label{users/install:install}
This page covers the necessary steps to install nipype.  Below is a
list of required dependencies, along with additional software
recommendations.


\subsection{Dependencies}
\label{users/install:dependencies}

\subsubsection{Must Have}
\label{users/install:must-have}
\href{http://www.python.org}{Python} 2.5 -2.7

\href{http://www.scipy.org/NumPy}{NumPy} 1.3 - 1.5
\begin{description}
\item[{\href{http://www.scipy.org}{SciPy} 0.7 - 0.9}] \leavevmode
Numpy and Scipy are high-level, optimized scientific computing libraries.

\item[{\href{http://networkx.lanl.gov/}{NetworkX} 1.0 - 1.4}] \leavevmode
Python package for working with complex networks.

\item[{\href{http://pypi.python.org/pypi/simplejson/2.0.9}{simplejson}}] \leavevmode
json is included in Python 2.6, but if you are using Python 2.5 you
will need to install simplejson.

\end{description}

\href{http://www.enthought.com}{Enthought} \href{http://code.enthought.com/projects/traits/}{Traits} 3.2.0 or 3.6.1

\begin{notice}{note}{Note:}
Full distributions such as \href{http://www.pythonxy.com/}{pythonxy} or \href{http://www.enthought.com/products/epd.php}{EPD} provide the above packages.
\end{notice}

{\color{red}\bfseries{}Nibabel\_} (required)


\subsubsection{Strong Recommendations}
\label{users/install:strong-recommendations}\begin{description}
\item[{\href{http://ipython.scipy.org}{IPython} 0.10}] \leavevmode
Interactive python environment. This is necessary for the parallel
components of the pipeline engine.
\begin{itemize}
\item {} 
The IPython.kernel (parallel computing component) has the
following dependencies:
\begin{itemize}
\item {} 
\href{http://twistedmatrix.com/trac/}{Twisted}

\item {} 
zope.interface: which is also a dependecy of Twisted and was
installed automatically for me when I installed Twisted.

\end{itemize}

\end{itemize}

\item[{\href{http://matplotlib.sourceforge.net}{Matplotlib}}] \leavevmode
Python plotting library.

\item[{\href{http://sphinx.pocoo.org/}{Sphinx}}] \leavevmode
Required for building the documentation

\item[{\href{http://www.graphviz.org/}{Graphviz}}] \leavevmode
Required for building the documentation

\end{description}


\subsubsection{Interface Dependencies}
\label{users/install:interface-dependencies}
These are the software packages that nipype.interfaces wraps:
\begin{description}
\item[{\href{http://www.fmrib.ox.ac.uk/fsl}{FSL}}] \leavevmode
4.1.0 or later

\item[{\href{http://www.mathworks.com}{matlab}}] \leavevmode
2008a or later

\item[{\href{http://www.fil.ion.ucl.ac.uk/spm}{SPM}}] \leavevmode
SPM5/8

\item[{\href{http://surfer.nmr.mgh.harvard.edu}{FreeSurfer}}] \leavevmode
FreeSurfer version 4 and higher

\item[{\href{http://afni.nimh.nih.gov/afni}{AFNI}}] \leavevmode
2009\_12\_31\_1431 or later

\item[{\href{http://slicer.org}{Slicer}}] \leavevmode
3.6 or later

\item[{\href{http://nipy.org}{Nipy}}] \leavevmode
0.1.2+20110404 or later (required for doc building)

\item[{\href{http://nipy.sourceforge.net/nitime/}{Nitime}}] \leavevmode
(optional; required for doc building)

\end{description}


\subsection{Download}
\label{users/install:download}
Download the latest release from \href{http://github.com/nipy/nipype}{our github
page.}

To check out the latest development version:

\begin{Verbatim}[commandchars=@\[\]]
git clone git://github.com/nipy/nipype.git
\end{Verbatim}


\subsection{Install}
\label{users/install:id1}
The installation process is similar to other Python packages so it
will be familiar if you have Python experience. Nipype is also hosted on the
PyPi repository so you can do:

\begin{Verbatim}[commandchars=@\[\]]
easy@_install nipype
\end{Verbatim}

or:

\begin{Verbatim}[commandchars=@\[\]]
pip install nipype
\end{Verbatim}


\subsubsection{Debian and Ubuntu}
\label{users/install:debian-and-ubuntu}
Add the \href{http://neuro.debian.org}{NeuroDebian} repository and install
the \code{python-nipype} package using \code{apt-get} or your favourite package manager.


\subsubsection{Max OS X}
\label{users/install:max-os-x}
The easiest way to get nipype running on MacOSX is to install \href{http://www.enthought.com/products/epd.php}{EPD} and then add nibabel
and nipype by executing:

\begin{Verbatim}[commandchars=@\[\]]
easy@_install nibabel
easy@_install nipype
\end{Verbatim}

If you are running a 64 bit version of EPD, you will need to compile
ETS. Instructions for a 64-bit boot mode are available:  \href{https://gist.github.com/845545}{https://gist.github.com/845545}


\subsubsection{From source}
\label{users/install:from-source}
If you downloaded the source distribution named something
like \code{nipype-x.y.tar.gz}, then unpack the tarball, change into the
\code{nipype-x.y} directory and install nipype using:

\begin{Verbatim}[commandchars=@\[\]]
python setup.py install
\end{Verbatim}

\textbf{Note:} Depending on permissions you may need to use \code{sudo}.


\subsection{Testing the install}
\label{users/install:testing-the-install}
The best way to test the install is to run the test suite.  If you
have \href{http://somethingaboutorange.com/mrl/projects/nose}{nose} installed, then do the following:

\begin{Verbatim}[commandchars=@\[\]]
python -c "import nipype; nipype.test()"
\end{Verbatim}

All tests should pass (unless you're missing a dependency). If any tests
fail, please report them on our \href{http://github.com/nipy/nipype/issues}{bug tracker}.

On Debian systems, set the following environment variable before running
tests:

\begin{Verbatim}[commandchars=@\[\]]
export MATLABCMD=@$pathtomatlabdir/bin/@$platform/MATLAB
\end{Verbatim}

where, \$pathtomatlabdir is the path to your matlab installation and
\$platform is the directory referring to x86 or x64 installations
(typically glnxa64 on 64-bit installations).


\section{Configuration File}
\label{users/config_file:configuration-file}\label{users/config_file::doc}\label{users/config_file:config-file}\label{users/config_file:wikipedia-pca}
Some of the system wide options of NiPyPe can be configured using a configuration file. NiPyPe looks for the file in the local folder under the name \code{nipype.cfg} and in \code{\textasciitilde{}/.nipype.cfg} (in this order). If an option will not be specified a default value will be assumed. The file is divided into following sections:


\subsection{Logging}
\label{users/config_file:logging}\begin{description}
\item[{\emph{workflow\_level}}] \leavevmode
How detailed the logs regarding workflow should be (possible values: \code{INFO} and \code{DEBUG}; default value: \code{INFO})

\item[{\emph{filemanip\_level}}] \leavevmode
How detailed the logs regarding file operations (for example overwriting warning) should be (possible values: \code{INFO} and \code{DEBUG}; default value: \code{INFO})

\item[{\emph{interface\_level}}] \leavevmode
How detailed the logs regarding interface execution should be (possible values: \code{INFO} and \code{DEBUG}; default value: \code{INFO})

\item[{\emph{log\_directory}}] \leavevmode
Where to store logs. (string, default value: home directory)

\item[{\emph{log\_size}}] \leavevmode
Size of a single log file. (integer, default value: 254000)

\item[{\emph{log\_rotate}}] \leavevmode
How many rotation should the log file make. (integer, default value: 4)

\end{description}


\subsection{Execution}
\label{users/config_file:execution}\begin{description}
\item[{\emph{plugin}}] \leavevmode\begin{quote}

This defines which execution plugin to use. (possible values:
\end{quote}

\code{Linear}, \code{SGE}, \code{IPython}; default: \code{Linear})

\item[{\emph{stop\_on\_first\_crash}}] \leavevmode
Should the workflow stop upon first node crashing or try to
execute as many nodes as possible? (possible values: \code{true}
and \code{false}; default value: \code{false})

\item[{\emph{stop\_on\_first\_rerun}}] \leavevmode
Should the workflow stop upon first node trying to recompute (by that we mean
rerunning a node that has been run before - this can happen due changed
inputs and/or hash\_method since the last run). (possible values: \code{true}
and \code{false}; default value: \code{false})

\item[{\emph{hash\_method}}] \leavevmode
Should the input files be checked for changes using their
content (slow, but 100\% accurate) or just their size and
modification date (fast, but potentially prone to errors)?
(possible values: \code{content} and \code{timestamp}; default value:
\code{content})

\item[{\emph{single\_thread\_matlab}}] \leavevmode
Should all of the Matlab interfaces (including SPM) use only one
thread? This is useful if you are parallelizing your workflow
using IPython on a single multicore machine. (possible values:
\code{true} and \code{false}; default value: \code{true})

\item[{\emph{display\_variable}}] \leavevmode
What \code{DISPLAY} variable should all command line interfaces be
run with. This is useful if you are using \href{http://www.x.org/archive/X11R7.5/doc/man/man1/Xnest.1.html}{xnest}
or \href{http://www.x.org/archive/X11R6.8.1/doc/Xvfb.1.html}{Xvfb}
and you would like to redirect all spawned windows to
it. (possible values: any X server address; default value: not
set)

\item[{\emph{remove\_unnecessary\_outputs}}] \leavevmode\begin{quote}

This will remove any interface outputs not needed by the
\end{quote}

workflow. If the required outputs from a node changes, rerunning
the workflow will rerun the node. (possible values: \code{true} and
\code{false}; default value: \code{true})

\item[{\emph{use\_relative\_paths}}] \leavevmode
Should the paths stored in results (and used to look for inputs)
be relative or absolute. Relative paths allow moving the whole
working directory around but may cause problems with
symlinks. (possible values: \code{true} and \code{false}; default
value: \code{false})

\item[{\emph{remove\_node\_directories (EXPERIMENTAL)}}] \leavevmode
Removes directories whose outputs have already been used
up. Doesn't work with IdentiInterface or any node that patches
data through (without copying) (possible values: \code{true} and
\code{false}; default value: \code{false})

\end{description}


\subsection{Example}
\label{users/config_file:example}
\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]logging@PYGZrb[]
workflow@_level = DEBUG

@PYGZlb[]execution@PYGZrb[]
stop@_on@_first@_crash = true
hash@_method = timestamp
display@_variable = :1
\end{Verbatim}

You can also directly set config options in your workflow script. An
example is shown below.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.config} \PYG{k+kn}{import} \PYG{n}{config}
\PYG{k+kn}{from} \PYG{n+nn}{StringIO} \PYG{k+kn}{import} \PYG{n}{StringIO}
\PYG{n}{cfg} \PYG{o}{=} \PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s}{"""}
\PYG{l+s}{[logging]}
\PYG{l+s}{      workflow\PYGZus{}level = DEBUG}

\PYG{l+s}{[execution]}
\PYG{l+s}{stop\PYGZus{}on\PYGZus{}first\PYGZus{}crash = false}
\PYG{l+s}{hash\PYGZus{}method = content}
\PYG{l+s}{"""}\PYG{p}{)}

\PYG{n}{config}\PYG{o}{.}\PYG{n}{readfp}\PYG{p}{(}\PYG{n}{cfg}\PYG{p}{)}
\end{Verbatim}


\section{Tutorial : Interfaces}
\label{users/interface_tutorial:tutorial-interfaces}\label{users/interface_tutorial::doc}\label{users/interface_tutorial:interface-tutorial}\label{users/interface_tutorial:wikipedia-pca}

\subsection{Specifying options}
\label{users/interface_tutorial:specifying-options}
The nipype interface modules provide a Python interface to external
packages like \href{http://www.fmrib.ox.ac.uk/fsl}{FSL} and \href{http://www.fil.ion.ucl.ac.uk/spm}{SPM}.  Within the module are a series of Python
classes which wrap specific package functionality.  For example, in
the fsl module, the class \code{nipype.interfaces.fsl.Bet} wraps the
\code{bet} command-line tool.  Using the command-line tool, one would
specify options using flags like \code{-o}, \code{-m}, \code{-f \textless{}f\textgreater{}}, etc...
However, in nipype, options are assigned to Python attributes and can
be specified in the following ways:

Options can be assigned when you first create an interface object:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Options can be assigned through the \code{inputs} attribute:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}
\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Options can be assigned when calling the \code{run} method:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.5}\PYG{p}{)}
\end{Verbatim}


\subsection{Getting Help}
\label{users/interface_tutorial:getting-help}
In \href{http://ipython.scipy.org}{IPython} you can view the docstrings which provide some basic
documentation and examples.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [2]: }\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FAST}\PYG{err}{?}
\PYG{g+go}{Type:               type}
\PYG{g+go}{Base Class: \textless{}type 'type'\textgreater{}}
\PYG{g+go}{String Form:        \textless{}class 'nipype.interfaces.fsl.preprocess.FAST'\textgreater{}}
\PYG{g+go}{Namespace:  Interactive}
\PYG{g+go}{File:               /Users/satra/sp/nipype/interfaces/fsl/preprocess.py}
\PYG{g+go}{Docstring:}
\PYG{g+go}{    Use FSL FAST for segmenting and bias correction.}

\PYG{g+go}{    For complete details, see the {}`FAST Documentation.}
\PYG{g+go}{    \textless{}http://www.fmrib.ox.ac.uk/fsl/fast4/index.html\textgreater{}{}`\PYGZus{}}

\PYG{g+go}{    Examples}
\PYG{g+go}{    --------}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} from nipype.interfaces import fsl}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} from nipype.testing import anatfile}

\PYG{g+go}{    Assign options through the {}`{}`inputs{}`{}` attribute:}

\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} fastr = fsl.FAST()}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} fastr.inputs.in\PYGZus{}files = anatfile}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} out = fastr.run() \#doctest: +SKIP}

\PYG{g+go}{Constructor information:}
\PYG{g+go}{Definition: fsl.FAST(self, **inputs)}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [5]: }\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{err}{?}
\PYG{g+go}{Type:                type}
\PYG{g+go}{Base Class:  \textless{}type 'type'\textgreater{}}
\PYG{g+go}{String Form: \textless{}class 'nipype.interfaces.spm.preprocess.Realign'\textgreater{}}
\PYG{g+go}{Namespace:   Interactive}
\PYG{g+go}{File:                /Users/satra/sp/nipype/interfaces/spm/preprocess.py}
\PYG{g+go}{Docstring:}
\PYG{g+go}{    Use spm\PYGZus{}realign for estimating within modality rigid body alignment}

\PYG{g+go}{    http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=25}

\PYG{g+go}{    Examples}
\PYG{g+go}{    --------}

\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} import nipype.interfaces.spm as spm}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} realign = spm.Realign()}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} realign.inputs.in\PYGZus{}files = 'functional.nii'}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} realign.inputs.register\PYGZus{}to\PYGZus{}mean = True}
\PYG{g+go}{    \textgreater{}\textgreater{}\textgreater{} realign.run() \# doctest: +SKIP}

\PYG{g+go}{Constructor information:}
\PYG{g+go}{Definition:  spm.Realign(self, **inputs)}
\end{Verbatim}

All of the nipype.interfaces classes have an \code{help} method
which provides information on each of the options one can assign.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [6]: }\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{o}{.}\PYG{n}{help}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{Inputs}
\PYG{g+go}{------}

\PYG{g+go}{Mandatory:}
\PYG{g+go}{ in\PYGZus{}file: input file to skull strip}

\PYG{g+go}{Optional:}
\PYG{g+go}{ args: Additional parameters to the command}
\PYG{g+go}{ center: center of gravity in voxels}
\PYG{g+go}{ environ: Environment variables (default=\PYGZob{}\PYGZcb{})}
\PYG{g+go}{ frac: fractional intensity threshold}
\PYG{g+go}{ functional: apply to 4D fMRI data}
\PYG{g+go}{  mutually exclusive: functional, reduce\PYGZus{}bias}
\PYG{g+go}{ mask: create binary mask image}
\PYG{g+go}{ mesh: generate a vtk mesh brain surface}
\PYG{g+go}{ no\PYGZus{}output: Don't generate segmented output}
\PYG{g+go}{ out\PYGZus{}file: name of output skull stripped image}
\PYG{g+go}{ outline: create surface outline image}
\PYG{g+go}{ output\PYGZus{}type: FSL output type}
\PYG{g+go}{ radius: head radius}
\PYG{g+go}{ reduce\PYGZus{}bias: bias field and neck cleanup}
\PYG{g+go}{  mutually exclusive: functional, reduce\PYGZus{}bias}
\PYG{g+go}{ skull: create skull image}
\PYG{g+go}{ threshold: apply thresholding to segmented brain image and mask}
\PYG{g+go}{ vertical\PYGZus{}gradient: vertical gradient in fractional intensity threshold (-1, 1)}

\PYG{g+go}{Outputs}
\PYG{g+go}{-------}
\PYG{g+go}{mask\PYGZus{}file: path/name of binary brain mask (if generated)}
\PYG{g+go}{meshfile: path/name of vtk mesh file (if generated)}
\PYG{g+go}{out\PYGZus{}file: path/name of skullstripped file}
\PYG{g+go}{outline\PYGZus{}file: path/name of outline file (if generated)}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [7]: }\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{o}{.}\PYG{n}{help}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{Inputs}
\PYG{g+go}{------}

\PYG{g+go}{Mandatory:}
\PYG{g+go}{ in\PYGZus{}files: list of filenames to realign}

\PYG{g+go}{Optional:}
\PYG{g+go}{ fwhm: gaussian smoothing kernel width}
\PYG{g+go}{ interp: degree of b-spline used for interpolation}
\PYG{g+go}{ jobtype: one of: estimate, write, estwrite (default=estwrite)}
\PYG{g+go}{ matlab\PYGZus{}cmd: None}
\PYG{g+go}{ mfile: Run m-code using m-file (default=True)}
\PYG{g+go}{ paths: Paths to add to matlabpath}
\PYG{g+go}{ quality: 0.1 = fast, 1.0 = precise}
\PYG{g+go}{ register\PYGZus{}to\PYGZus{}mean: Indicate whether realignment is done to the mean image}
\PYG{g+go}{ separation: sampling separation in mm}
\PYG{g+go}{ weight\PYGZus{}img: filename of weighting image}
\PYG{g+go}{ wrap: Check if interpolation should wrap in [x,y,z]}
\PYG{g+go}{ write\PYGZus{}interp: degree of b-spline used for interpolation}
\PYG{g+go}{ write\PYGZus{}mask: True/False mask output image}
\PYG{g+go}{ write\PYGZus{}which: determines which images to reslice}
\PYG{g+go}{ write\PYGZus{}wrap: Check if interpolation should wrap in [x,y,z]}

\PYG{g+go}{Outputs}
\PYG{g+go}{-------}
\PYG{g+go}{mean\PYGZus{}image: Mean image file from the realignment}
\PYG{g+go}{realigned\PYGZus{}files: Realigned files}
\PYG{g+go}{realignment\PYGZus{}parameters: Estimated translation and rotation parameters}
\end{Verbatim}

Our \emph{interfaces} documentation provides html versions of our
docstrings and includes links to the specific package
documentation. For instance, the \code{nipype.interfaces.fsl.Bet}
docstring has a direct link to the online BET Documentation.


\subsection{FSL interface example}
\label{users/interface_tutorial:fsl-interface-example}
Using \href{http://www.fmrib.ox.ac.uk/fsl}{FSL} to realign a time\_series:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{n}{realigner} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{McFlirt}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{realigner}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{timeseries4D.nii}\PYG{l+s}{'}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{realigner}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\subsection{SPM interface example}
\label{users/interface_tutorial:spm-interface-example}
Using \href{http://www.fil.ion.ucl.ac.uk/spm}{SPM} to realign a time-series:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{k+kn}{from} \PYG{n+nn}{glob} \PYG{k+kn}{import} \PYG{n}{glob}
\PYG{n}{allepi} \PYG{o}{=} \PYG{n}{glob}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{epi*.nii}\PYG{l+s}{'}\PYG{p}{)} \PYG{c}{\# this will return an unsorted list}
\PYG{n}{allepi}\PYG{o}{.}\PYG{n}{sort}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{realigner} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{realigner}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{n}{allepi}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{realigner}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\section{Tutorial : Workflows}
\label{users/pipeline_tutorial:pipeline-tutorial}\label{users/pipeline_tutorial:tutorial-workflows}\label{users/pipeline_tutorial::doc}\label{users/pipeline_tutorial:wikipedia-pca}
This section presents several tutorials on how to setup and use pipelines. Make
sure that you have the requirements satisfied and go through the steps required
for the analysis tutorials.


\subsection{Tutorials}
\label{users/pipeline_tutorial:tutorials}

\subsubsection{Pipeline 101}
\label{users/tutorial_101:tutorial-101}\label{users/tutorial_101::doc}\label{users/tutorial_101:pipeline-101}
A workflow or pipeline is built by connecting processes or nodes to each
other. In the context of nipype, every interface can be treated as a pipeline
node having defined inputs and outputs. Creating a workflow then is a matter
of connecting appropriate outputs to inputs. Currently, workflows are limited
to being directional and cannot have any loops, thereby creating an ordering to
data flow. The following nipype component architecture might help understanding
some of the tutorials presented here.

\includegraphics{componentarchitecture.png}


\paragraph{My first pipeline}
\label{users/tutorial_101:my-first-pipeline}
Although the most trivial workflow consists of a single node, we will
create a workflow with two nodes: a realign node that will send
the realigned functional data to a smoothing node. It is important to note that
setting up a workflow is separate from executing it.

\textbf{1. Import appropriate modules}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}         \PYG{c}{\# the spm interfaces}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}         \PYG{c}{\# the workflow and node wrappers}
\end{Verbatim}

\textbf{2. Define nodes}

Here we take instances of interfaces and make them pipeline compatible by
wrapping them with pipeline specific elements. To determine the inputs and outputs
of a given interface, please see {\hyperref[users/interface_tutorial:interface-tutorial]{\emph{Tutorial : Interfaces}}}. Let's
start with defining a realign node using the interface
\code{nipype.interfaces.spm.Realign}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realigner} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{realign}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{realigner}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{somefuncrun.nii}\PYG{l+s}{'}
\PYG{n}{realigner}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

This would be equivalent to:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realigner} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{n}{infile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{somefuncrun.nii}\PYG{l+s}{'}\PYG{p}{,}
                                          \PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{realign}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

In Pythonic terms, this is saying that interface option in Node accepts
an \emph{instance} of an interface. The inputs to this interface can be set either
later or while initializing the interface.

\begin{notice}{note}{Note:}
In the above example, `somefuncrun.nii' has to exist, otherwise the
commands won't work. A node will check if appropriate inputs are
being supplied.
\end{notice}

Similar to the realigner node, we now set up a smoothing node.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smoother} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{smooth}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Now we have two nodes with their inputs defined. Note that we have not defined
an input file for the smoothing node. This will be done by connecting the
realigner to the smoother in step 5.

\textbf{3. Creating and configuring a workflow}

Here we create an instance of a workflow and indicate that it should operate in
the current directory.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\end{Verbatim}

\textbf{4. Adding nodes to workflows (optional)}

If nodes are going to be connected (see step 5), this step is not
necessary. However, if you would like to run a node by itself without
connecting it to any other node, then you need to add it to the
workflow. For adding nodes, order of nodes is not important.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{add\PYGZus{}nodes}\PYG{p}{(}\PYG{p}{[}\PYG{n}{smoother}\PYG{p}{,} \PYG{n}{realigner}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

This results in a workflow containing two isolated nodes:

\includegraphics{smoothrealignunconnected.png}

\textbf{5. Connecting nodes to each other}

We want to connect the output produced by realignment to the input of
smoothing. This is done as follows.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{realigner}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{smoother}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

or alternatively, a more flexible notation can be used. Although not shown here,
the following notation can be used to connect multiple outputs from one node to
multiple inputs (see step 7 below).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realigner}\PYG{p}{,} \PYG{n}{smoother}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

This results in a workflow containing two connected nodes:

\includegraphics{smoothrealignconnected.png}

\textbf{6. Visualizing the workflow}

The workflow is represented as a directed acyclic graph (DAG) and one
can visualize this using the following command. In fact, the pictures
above were generated using this.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This creates two files graph.dot and graph\_detailed.dot and if
\href{http://www.graphviz.org/}{graphviz} is installed on your system it automatically converts it
to png files. If graphviz is not installed you can take the dot files
and load them in a graphviz visualizer elsewhere. You can specify how detailed
the graph is going to be, by using ``graph2use'' argument which takes the following
options:
\begin{itemize}
\item {} 
orig - creates a top level graph without expanding internal workflow nodes

\item {} 
flat - expands workflow nodes recursively

\item {} 
exec - expands workflows to depict iterables

\end{itemize}

\textbf{7. Extend it}

Now that you have seen a basic pipeline let's add another node to the
above pipeline.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}
\PYG{n}{artdetect} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{artdetect}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{artdetect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences}  \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n+nb+bp}{False}\PYG{p}{]}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}norm} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realigner}\PYG{p}{,} \PYG{n}{artdetect}\PYG{p}{,}
                   \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}
                  \PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

\begin{notice}{note}{Note:}
a) How an alternative form of connect was used to connect multiple
output fields from the realign node to corresponding input
fields of the artifact detection node.

b) The current visualization only shows connected input and
output ports. It does not show all the parameters that you have
set for a node.
\end{notice}

This results in

\includegraphics{threecomponentpipe.png}

\textbf{8. Execute the workflow}

Assuming that \textbf{somefuncrun.nii} is actually a file or you've
replaced it with an appropriate one, you can run the pipeline with:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This should create a folder called preproc in your current directory,
inside which are three folders: realign, smooth and artdetect (the names
of the nodes). The outputs of these routines are in these folders.


\subsubsection{Pipeline 102}
\label{users/tutorial_102:tutorial-102}\label{users/tutorial_102::doc}\label{users/tutorial_102:pipeline-102}\label{users/tutorial_102:wikipedia-pca}
Now that you know how to construct a workflow and execute it, we will go
into more advanced concepts. This tutorial focuses on
\code{nipype.pipeline.engine.Workflow}
\code{nipype.pipeline.engine.Node} and
\code{nipype.pipeline.engine.MapNode}.

A workflow is a \textbf{directed acyclic graph (DAG)} consisting of nodes
which can be of type \emph{Workflow}, \emph{Node} or \emph{MapNode}. Workflows can
be re-used and hierarchical workflows can be easily constructed.


\paragraph{`name' : the mandatory keyword arg}
\label{users/tutorial_102:name-the-mandatory-keyword-arg}
When instantiating a Workflow, Node or MapNode, a \emph{name} has to be
provided. For any given level of a workflow, no two nodes can have the
same name. The engine will let you know if this is the case when you add
nodes to a workflow either directly using \emph{add\_nodes} or using the
\emph{connect} function.

Names have many internal uses. They determine the name of the directory
in which the workflow/node is run and the outputs are stored.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realigner} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{StructRealignSPM}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Now this output will be stored in a directory called
\emph{StructRealignSPM}. Proper naming of your nodes can be advantageous
from the perspective that it provides a semantic descriptor aligned with
your thought process.


\subparagraph{iterables}
\label{users/tutorial_102:iterables}
This can only be set for Node and MapNode. This is syntactic sugar for
running a subgraph with the Node/MapNode at its root in a \code{for}
loop. For example, consider an fMRI preprocessing pipeline that you
would like to run for all your subjects. You can define a workflow and
then execute it for every single subject inside a \code{for} loop. Consider
the simplistic example below, where startnode is a node belonging to
workflow `mywork.'

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{subjects}\PYG{p}{:}
    \PYG{n}{startnode}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{n}{s}
    \PYG{n}{mywork}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

The pipeline engine provides a convenience function that simplifies
this:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{startnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjects}\PYG{p}{)}
\PYG{n}{mywork}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This will achieve the same exact behavior as the for loop above. The
workflow graph is:

\includegraphics{proc2subj.png}

Now consider the situation in which you want the last node (typically
smoothing) of your preprocessing pipeline to smooth using two
different kernels (0 mm and 6 mm FWHM). Again the common approach
would be:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{subjects}\PYG{p}{:}
    \PYG{n}{startnode}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{n}{s}
    \PYG{n}{uptosmoothingworkflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{smoothnode}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile} \PYG{o}{=} \PYG{n}{lastnode}\PYG{o}{.}\PYG{n}{output}\PYG{o}{.}\PYG{n}{outfile}
    \PYG{k}{for} \PYG{n}{fwhm} \PYG{o+ow}{in} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{]}\PYG{p}{:}
        \PYG{n}{smoothnode}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{n}{fwhm}
        \PYG{n}{remainingworkflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Instead of having multiple \code{for} loops at various stages, you can set up
another set of iterables for the smoothnode.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{startnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjects}\PYG{p}{)}
\PYG{n}{smoothnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mywork}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This will run the preprocessing workflow for two different smoothing
kernels over all subjects.

\includegraphics{proc2subj2fwhm.png}

Thus setting iterables has a multiplicative effect. In the above
examples there is a separate, distinct specifymodel node that's
executed for each combination of subject and smoothing.


\subparagraph{iterfield}
\label{users/tutorial_102:iterfield}
This is a mandatory keyword arg for MapNode. This enables running the
underlying interface over a set of inputs and is particularly useful
when the interface can only operate on a single input. For example, the
\code{nipype.interfaces.fsl.BET} will operate on only one (3d or 4d)
NIfTI file. But wrapping BET in a MapNode can execute it over a list of files:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{better} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{stripper}\PYG{l+s}{'}\PYG{p}{,}
                    \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{better}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{file1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{file2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{better}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This will create a directory called \code{stripper} and inside it two
subdirectories called \code{in\_file\_0} and \code{in\_file\_1}. The output of running bet
separately on each of those files will be stored in those two
subdirectories.

This can be extended to run it on pairwise inputs. For example,

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{transform} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{ApplyVolTransform}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{warpvol}\PYG{l+s}{'}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{source\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{transform}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{file1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{file2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{transform}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{reg\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{file1.reg}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{file2.reg}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{transform}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

The above will be equivalent to running transform by taking corresponding items from
each of the two fields in iterfield. The subdirectories get always
named with respect to the first iterfield.


\subparagraph{overwrite}
\label{users/tutorial_102:overwrite}
The overwrite keyword arg forces a node to be rerun.


\subparagraph{The \emph{clone} function}
\label{users/tutorial_102:the-clone-function}
The \emph{clone} function can be used to create a copy of a workflow. No
references to the original workflow are retained. As such the clone
function requires a name keyword arg that specifies a new name for the
duplicate workflow.


\subsubsection{Pipeline 103}
\label{users/tutorial_103:pipeline-103}\label{users/tutorial_103:tutorial-103}\label{users/tutorial_103::doc}\label{users/tutorial_103:wikipedia-pca}

\paragraph{Modifying inputs to pipeline nodes}
\label{users/tutorial_103:modifying-inputs-to-pipeline-nodes}
Two nodes can be connected as shown below.

\begin{Verbatim}[commandchars=\\\{\}]
\end{Verbatim}


\paragraph{workflow.connect(realigner, `realigned\_files', smoother, `infile')}
\label{users/tutorial_103:workflow-connect-realigner-realigned-files-smoother-infile}
The connection mechanism allows for a function to be evaluated on the
output field (`realigned files') of the source node (realigner) and
have its result be sent to the input field (`infile') of the
destination node (smoother).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{reverse\PYGZus{}order}\PYG{p}{(}\PYG{n}{inlist}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{inlist}\PYG{o}{.}\PYG{n}{reverse}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{inlist}

\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{realigner}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{reverse\PYGZus{}order}\PYG{p}{)}\PYG{p}{,}
                 \PYG{n}{smoother}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{infile}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

This can be extended to provide additional arguments to the
function. For example:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{reorder}\PYG{p}{(}\PYG{n}{inlist}\PYG{p}{,} \PYG{n}{order}\PYG{p}{)}\PYG{p}{:}
   \PYG{k}{return} \PYG{p}{[}\PYG{n}{inlist}\PYG{p}{[}\PYG{n}{item}\PYG{p}{]} \PYG{k}{for} \PYG{n}{item} \PYG{o+ow}{in} \PYG{n}{order}\PYG{p}{]}

\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{realigner}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{reorder}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{n}{smoother}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{infile}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

In this example, we assume the realigned\_files produces a list of 4
files. We can reorder these files in a particular order using the
modifier. Since such modifications are not tracked, they should be
used with extreme care and only in cases where absolutely
necessary. Often, one may find that it is better to insert a node
rather than a function.


\paragraph{Distributed computation}
\label{users/tutorial_103:distributed-computation}
The pipeline engine has built-in support for distributed computation on
clusters. This can be achieved via plugin-modules for the \href{http://ipython.scipy.org}{IPython}
distributed computing interface or SGE, provided the user sets up a
workflow on a shared filesystem.

For \href{http://ipython.scipy.org}{IPython} the environment needs to be configured for distributed
operation. Details are available at {\hyperref[users/parallel_processing:parallel-processing]{\emph{Distributed processing with nipype}}}.

The default behavior is to run in series using the Linear plugin.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

In some cases it may be advantageous to run the workflow in series
locally (e.g., debugging, small-short pipelines, large memory only
interfaces, relocating working directory/updating hashes).


\paragraph{Debugging}
\label{users/tutorial_103:debugging}
When a crash happens while running a pipeline, a crashdump is stored in
the pipeline's working directory unless the config option `crashdumpdir'
has been set (see :ref:config\_options).

The crashdump is a compressed numpy file that stores a dictionary
containing three fields:
\begin{enumerate}
\item {} 
node - the node that failed

\item {} 
execgraph - the graph that the node came from

\item {} 
traceback - from local or remote session for the failure.

\end{enumerate}

We keep extending the information contained in the file and making
it easier to troubleshoot the failures. However, in the meantime the following
can help to recover information related to the failure.

in \href{http://ipython.scipy.org}{IPython} do (\code{\%pdb} in \href{http://ipython.scipy.org}{IPython} is similar to \code{dbstop} if error in Matlab):

\begin{Verbatim}[commandchars=@\[\]]
from nipype.utils.filemanip import loadflat
crashinfo = loadflat('crashdump....npz')
@%pdb
crashinfo@PYGZlb[]'node'@PYGZrb[].run()  @# re-creates the crash
pdb@textgreater[] up  @#typically, but not necessarily the crash is one stack frame up
pdb@textgreater[] inspect variables
pdb@textgreater[]quit
\end{Verbatim}


\paragraph{Relocation of workdir}
\label{users/tutorial_103:relocation-of-workdir}
In some circumstances, one might decide to move their entire working
directory to a new location. It would be convenient to rerun only
necessary components of the pipeline, instead of running all the nodes
all over again. It is possible to do that with the
\code{updatehash()} function.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{updatehash}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

This will execute the workflow and update all the hash values that
were stored without actually running any of the interfaces.


\subparagraph{Caveats}
\label{users/tutorial_103:caveats}
Any interface that stores a filename within a generated file will trip
(e.g., \code{spm/fsl.Level1Design}, \emph{SpecifyModel.modelgen}). This is because
the outputs are not regenerated in this hash update. If your workflow
contains such an interfaces and none of your parameters or underlying
packages have changed, then you can relocate and re-execute:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{updatehash}\PYG{p}{(}\PYG{n}{force\PYGZus{}execute}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{spm.level1design}\PYG{l+s}{'}\PYG{p}{,}
                                   \PYG{l+s}{'}\PYG{l+s}{specifymodel.modelgen}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The names for \code{force\_execute} has to correspond to the directories that
were created.


\subsubsection{MapNode, iterfield, and iterables explained}
\label{users/mapnode_and_iterables:mapnode-and-iterables}\label{users/mapnode_and_iterables:mapnode-iterfield-and-iterables-explained}\label{users/mapnode_and_iterables::doc}\label{users/mapnode_and_iterables:wikipedia-pca}
In this chapter we will try to explain the concepts behind MapNode, iterfield,
and iterables.


\paragraph{MapNode and iterfield}
\label{users/mapnode_and_iterables:mapnode-and-iterfield}
Imagine that you have a list of items (lets say files) and you want to execute
the same node on them (for example some smoothing or masking). Some nodes accept
multiple files and do exactly the same thing on them, but some don't (they expect
only one file). MapNode can solve this problem. Imagine you have the following
workflow:
\includegraphics{graphviz-5c392fbfe6945536aaf27147c442c2417c054fd6.pdf}
Node ``A'' outputs a list of files, but node ``B'' accepts only one file. Additionally
``C'' expects a list of files. What you would like is to run ``B'' for every file in
the output of ``A'' and collect the results as a list and feed it to ``C''. Something
like this:
\includegraphics{graphviz-e42edebeac5ad696b556be3cdfb89dfd6f5091f9.pdf}
The code to achieve this is quite simple

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}
\PYG{n}{a} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{A}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{a}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{c} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{C}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{c}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{my\PYGZus{}workflow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{my\PYGZus{}workflow}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                     \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

assuming that interfaces ``A'' and ``C'' have one input ``in\_files'' and one output
``out\_files'' (both lists of files). Interface ``B'' has single file input ``in\_file''
and single file output ``out\_file''.

You probably noticed that you connect nodes as if ``B'' could accept and output
list of files. This is because it is wrapped using MapNode instead of Node. This
special version of node will (under the bonnet) create an instance of ``B'' for
every item in the list from the input. The compulsory argument ``iterfield''
defines which input should it iterate over (for example in single file smooth
interface you would like to iterate over input files not the smoothing width). At
the end outputs are collected into a list again. In other words this is map and
reduce scenario.

You might have also noticed that the iterfield arguments expects a list of input
names instead of just one name. This suggests that there can be more than one!
Even thou a bit confusing this is true. You can specify more than one input to
iterate over but the lists that you provide (for all the inputs specified in
iterfield) have to have the same length. MapNode will then pair the parameters up
and run the first instance with first set of parameters and second with second set
of parameters. For example, this code:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{b} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{n}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{b}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{another\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{different\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{b}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{]}
\PYG{n}{b}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

is almost the same as running

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{b1} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b1}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}
\PYG{n}{b1}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n} \PYG{o}{=} \PYG{l+m+mi}{1}

\PYG{n}{b2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b2}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{another\PYGZus{}file}\PYG{l+s}{'}
\PYG{n}{b2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n} \PYG{o}{=} \PYG{l+m+mi}{2}

\PYG{n}{b3} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b3}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{different\PYGZus{}file}\PYG{l+s}{'}
\PYG{n}{b3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n} \PYG{o}{=} \PYG{l+m+mi}{3}
\end{Verbatim}

It is a rarely used feature, but you can sometimes find it useful.


\paragraph{Iterables}
\label{users/mapnode_and_iterables:iterables}
Now imagine a different scenario. You have your workflow as before
\includegraphics{graphviz-0ba86da8c92761a1ca59f55ee0fe0de1c9980ddf.pdf}
and there are three possible values of one of the inputs node ``B'' you would like
to investigate (for example width of 2,4, and 6 pixels of a smoothing node). You
would like to see how different parameters in node ``B'' would influence everything
that depends on its outputs (node ``C'' in our example). Therefore the new graph
should look like this:
\includegraphics{graphviz-42dc9d4bfbce5f7627baf955d6fd4ef8864b3686.pdf}
Of course you can do it manually by creating copies of all the nodes for
different parameter set, but this can be very time consuming, especially when is
are more than one node taking inputs from ``B''. Luckily nipype supports this
scenario! Its called iterables and and you use it this way:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}
\PYG{n}{a} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{A}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{a}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{B}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{b}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{b}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{n}\PYG{l+s}{"}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{c} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{C}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{c}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{my\PYGZus{}workflow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{my\PYGZus{}workflow}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                     \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Assuming that you want to try out values 1, 2, and 3 of input ``n'' of the node
``B''. This will also create three different versions of node ``C'' - each with
inputs from instances of node ``C'' with different values of ``n''.

Iterables are also commonly used to execute the same workflow for many subjects.
Usually one parametrises DataGrabber node with subject ID. This is achieved by
connecting an IdentityNode in front of DataGrabber. When you set iterables of the
IdentityNode to the list of subjects IDs, the same workflow will be executed
for every subject. See {\hyperref[users/examples/spm_tutorial::doc]{\emph{Using SPM for analysis}}} to see this pattern in action.


\subsubsection{Using Camino for pipelined diffusion analysis}
\label{users/examples/camino_dti_tutorial:using-camino-for-pipelined-diffusion-analysis}\label{users/examples/camino_dti_tutorial::doc}\label{users/examples/camino_dti_tutorial:example-camino-dti-tutorial}\label{users/examples/camino_dti_tutorial:wikipedia-pca}

\paragraph{Introduction}
\label{users/examples/camino_dti_tutorial:introduction}
This script, camino\_dti\_tutorial.py, demonstrates the ability to perform basic diffusion analysis
in a Nipype pipeline.
\begin{quote}

python camino\_dti\_tutorial.py
\end{quote}

We perform this analysis using the FSL course data, which can be acquired from here:
\href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{camino}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino2trackvis} \PYG{k+kn}{as} \PYG{n+nn}{cam2trk}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.misc} \PYG{k+kn}{as} \PYG{n+nn}{misc}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}

We use the following functions to scrape the voxel and data dimensions of the input images. This allows the
pipeline to be flexible enough to accept and process images of varying size. The SPM Face tutorial
(spm\_face\_tutorial.py) also implements this inferral of voxel size from the data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{voxdims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}zooms}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{datadims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}data\PYGZus{}shape}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}affine}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}affine}\PYG{p}{(}\PYG{p}{)}

\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subj1}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Map field names to individual subject runs

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvecs}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvals}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.engine.Node} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{n}{info}\PYG{o}{.}\PYG{n}{keys}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{"}

\PYG{c}{\# This needs to point to the fdt folder you can find after extracting}
\PYG{c}{\# http://www.fmrib.ox.ac.uk/fslcourse/fsl\PYGZus{}course\PYGZus{}data2.tar.gz}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}course\PYGZus{}data/fdt/}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

An inputnode is used to pass the data obtained by the data grabber to the actual processing functions

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvecs}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvals}\PYG{l+s}{"}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{inputnode}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setup for Diffusion Tensor Computation}
\label{users/examples/camino_dti_tutorial:setup-for-diffusion-tensor-computation}
In this section we create the nodes necessary for diffusion analysis.
First, the diffusion image is converted to voxel order.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{image2voxel} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{Image2Voxel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{image2voxel}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fsl2scheme} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{FSL2Scheme}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{fsl2scheme}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fsl2scheme}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{usegradmod} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Second, diffusion tensors are fit to the voxel-order data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtifit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTIFit}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dtifit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Next, a lookup table is generated from the schemefile and the
signal-to-noise ratio (SNR) of the unweighted (q=0) data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtlutgen} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTLUTGen}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dtlutgen}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dtlutgen}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{snr} \PYG{o}{=} \PYG{l+m+mf}{16.0}
\PYG{n}{dtlutgen}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inversion} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

In this tutorial we implement probabilistic tractography using the PICo algorithm.
PICo tractography requires an estimate of the fibre direction and a model of its
uncertainty in each voxel; this is produced using the following node.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{picopdfs} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{PicoPDFs}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{picopdfs}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{picopdfs}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputmodel} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dt}\PYG{l+s}{'}
\end{Verbatim}

An FSL BET node creates a brain mask is generated from the diffusion image for seeding the PICo tractography.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bet} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{bet}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Finally, tractography is performed.
First DT streamline tractography.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{trackdt} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TrackDT}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{trackdt}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Now camino's Probablistic Index of connectivity algorithm.
In this tutorial, we will use only 1 iteration for time-saving purposes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{trackpico} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TrackPICo}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{trackpico}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{trackpico}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{iterations} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

Currently, the best program for visualizing tracts is TrackVis. For this reason, a node is included to
convert the raw tract data to .trk format. Solely for testing purposes, another node is added to perform the reverse.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cam2trk\PYGZus{}dt} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Camino2Trackvis}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{cam2trk\PYGZus{}dt}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cam2trk\PYGZus{}dt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{min\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mi}{30}
\PYG{n}{cam2trk\PYGZus{}dt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}order} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{LAS}\PYG{l+s}{'}

\PYG{n}{cam2trk\PYGZus{}pico} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Camino2Trackvis}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{cam2trk\PYGZus{}pico}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cam2trk\PYGZus{}pico}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{min\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mi}{30}
\PYG{n}{cam2trk\PYGZus{}pico}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}order} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{LAS}\PYG{l+s}{'}

\PYG{n}{trk2camino} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Trackvis2Camino}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{trk2camino}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Tracts can also be converted to VTK and OOGL formats, for use in programs such as GeomView and Paraview,
using the following two nodes. For VTK use VtkStreamlines.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{procstreamlines} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{ProcStreamlines}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{procstreamlines}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{procstreamlines}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outputtracts} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{oogl}\PYG{l+s}{'}
\end{Verbatim}

We can also produce a variety of scalar values from our fitted tensors. The following nodes generate the
fractional anisotropy and diffusivity trace maps and their associated headers.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fa} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{FA}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fa}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{trace} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TrD}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{trace}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{dteig} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTEig}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dteig}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{analyzeheader\PYGZus{}fa} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=} \PYG{n}{camino}\PYG{o}{.}\PYG{n}{AnalyzeHeader}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{analyzeheader\PYGZus{}fa}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{analyzeheader\PYGZus{}fa}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{datatype} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{double}\PYG{l+s}{"}
\PYG{n}{analyzeheader\PYGZus{}trace} \PYG{o}{=} \PYG{n}{analyzeheader\PYGZus{}fa}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analyzeheader\PYGZus{}trace}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{fa2nii} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{misc}\PYG{o}{.}\PYG{n}{CreateNifti}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fa2nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{trace2nii} \PYG{o}{=} \PYG{n}{fa2nii}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trace2nii}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Since we have now created all our nodes, we can now define our workflow and start making connections.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tractography}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{bet}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

File format conversion

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{image2voxel}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{bvecs}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvec\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{bvals}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bval\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Tensor fitting

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{image2voxel}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}order}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{scheme}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{scheme\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}
                     \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Workflow for applying DT streamline tractogpahy

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{bet}\PYG{p}{,} \PYG{n}{trackdt}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{seed\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{trackdt}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Workflow for applying PICo

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{bet}\PYG{p}{,} \PYG{n}{trackpico}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{seed\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{n}{dtlutgen}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{scheme}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{scheme\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtlutgen}\PYG{p}{,} \PYG{n}{picopdfs}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dtLUT}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{luts}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{picopdfs}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{picopdfs}\PYG{p}{,} \PYG{n}{trackpico}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{pdfs}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{c}{\# ProcStreamlines might throw memory errors - comment this line out in such case}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trackdt}\PYG{p}{,} \PYG{n}{procstreamlines}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tracked}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Connecting the Fractional Anisotropy and Trace nodes is simple, as they obtain their input from the
tensor fitting.

This is also where our voxel- and data-grabbing functions come in. We pass these functions, along with
the original DWI image from the input node, to the header-generating nodes. This ensures that the files
will be correct and readable.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fa}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{fa}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fa}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fa}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}affine}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{affine}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{header}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{header\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}


\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trace}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trace}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trace}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{trace}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}affine}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{affine}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{header}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{header\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{dteig}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trackpico}\PYG{p}{,} \PYG{n}{cam2trk\PYGZus{}pico}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{tracked}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trackdt}\PYG{p}{,} \PYG{n}{cam2trk\PYGZus{}dt}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{tracked}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{cam2trk\PYGZus{}pico}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{cam2trk\PYGZus{}dt}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Finally, we create another higher-level workflow to connect our tractography workflow with the info and datagrabbing nodes
declared at the beginning. Our tutorial can is now extensible to any arbitrary number of subjects by simply adding
their names to the subject list and their data to the proper folders.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{workflow}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{camino\PYGZus{}dti\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{tractography}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.dwi}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.bvecs}\PYG{l+s}{'}\PYG{p}{)}
                                           \PYG{p}{]}\PYG{p}{)}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The following functions run the whole workflow and produce a .dot and .png graph of the processing pipeline.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

You can choose the format of the experted graph with the \code{format} option. For example \code{workflow.write\_graph(format='eps')}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/camino\_dti\_tutorial.py}).




\subsubsection{Using Camino and CMTK for structural connectivity analysis}
\label{users/examples/connectivity_tutorial:example-connectivity-tutorial}\label{users/examples/connectivity_tutorial:using-camino-and-cmtk-for-structural-connectivity-analysis}\label{users/examples/connectivity_tutorial::doc}

\paragraph{Introduction}
\label{users/examples/connectivity_tutorial:introduction}
This script, connectivity\_tutorial.py, demonstrates the ability to perform connectivity mapping
using Nipype for pipelining, Freesurfer for Reconstruction / Parcellation, Camino for tensor-fitting
and tractography, and the Connectome Mapping Toolkit (CMTK) for connectivity analysis.
\begin{quote}

python connectivity\_tutorial.py
\end{quote}

We perform this analysis using the FSL course data, which can be acquired from here:
\begin{quote}

\href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}
\end{quote}

This pipeline also requires the Freesurfer directory for `subj1' from the FSL course data.
To save time, this data can be downloaded from here:
\begin{quote}

\href{http://dl.dropbox.com/u/315714/subj1.zip?dl=1}{http://dl.dropbox.com/u/315714/subj1.zip?dl=1}
\end{quote}

Along with Camino (\href{http://web4.cs.ucl.ac.uk/research/medic/camino/pmwiki/pmwiki.php?n=Main.HomePage}{http://web4.cs.ucl.ac.uk/research/medic/camino/pmwiki/pmwiki.php?n=Main.HomePage}),
Camino-Trackvis (\href{http://www.nitrc.org/projects/camino-trackvis/}{http://www.nitrc.org/projects/camino-trackvis/}), FSL (\href{http://www.fmrib.ox.ac.uk/fsl/}{http://www.fmrib.ox.ac.uk/fsl/}),
and Freesurfer (\href{http://surfer.nmr.mgh.harvard.edu/}{http://surfer.nmr.mgh.harvard.edu/}), you must also have the Connectome File Format
library installed as well as the Connectome Mapper.

These are written by Stephan Gerhard and can be obtained from:
\begin{quote}

\href{http://www.cmtk.org/}{http://www.cmtk.org/}
\end{quote}

Or on github at:
\begin{quote}

CFFlib: \href{https://github.com/LTS5/cfflib}{https://github.com/LTS5/cfflib}
CMP: \href{https://github.com/LTS5/cmp}{https://github.com/LTS5/cmp}
\end{quote}

Output data can be visualized in the ConnectomeViewer
\begin{quote}

ConnectomeViewer: \href{https://github.com/LTS5/connectomeviewer}{https://github.com/LTS5/connectomeviewer}
\end{quote}

First, we import the necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{camino}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino2trackvis} \PYG{k+kn}{as} \PYG{n+nn}{cam2trk}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}    \PYG{c}{\# freesurfer}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.cmtk} \PYG{k+kn}{as} \PYG{n+nn}{cmtk}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.misc} \PYG{k+kn}{as} \PYG{n+nn}{misc}
\PYG{k+kn}{import} \PYG{n+nn}{inspect}

\PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\PYG{k+kn}{import} \PYG{n+nn}{cmp}                                    \PYG{c}{\# connectome mapper}
\end{Verbatim}

We define the following functions to scrape the voxel and data dimensions of the input images. This allows the
pipeline to be flexible enough to accept and process images of varying size. The SPM Face tutorial
(spm\_face\_tutorial.py) also implements this inferral of voxel size from the data. We also define functions to
select the proper parcellation/segregation file from Freesurfer's output for each subject. For the mapping in
this tutorial, we use the aparc+seg.mgz file. While it is possible to change this to use the regions defined in
aparc.a2009s+aseg.mgz, one would also have to write/obtain a network resolution map defining the nodes based on those
regions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{voxdims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}zooms}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{datadims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}data\PYGZus{}shape}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{datadims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}affine}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}affine}\PYG{p}{(}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{select\PYGZus{}aparc}\PYG{p}{(}\PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{for} \PYG{n}{in\PYGZus{}file} \PYG{o+ow}{in} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{:}
        \PYG{k}{if} \PYG{l+s}{'}\PYG{l+s}{aparc+aseg.mgz}\PYG{l+s}{'} \PYG{o+ow}{in} \PYG{n}{in\PYGZus{}file}\PYG{p}{:}
            \PYG{n}{idx} \PYG{o}{=} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{o}{.}\PYG{n}{index}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{[}\PYG{n}{idx}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{select\PYGZus{}aparc\PYGZus{}annot}\PYG{p}{(}\PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{for} \PYG{n}{in\PYGZus{}file} \PYG{o+ow}{in} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{:}
        \PYG{k}{if} \PYG{l+s}{'}\PYG{l+s}{.aparc.annot}\PYG{l+s}{'} \PYG{o+ow}{in} \PYG{n}{in\PYGZus{}file}\PYG{p}{:}
            \PYG{n}{idx} \PYG{o}{=} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{o}{.}\PYG{n}{index}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{list\PYGZus{}of\PYGZus{}files}\PYG{p}{[}\PYG{n}{idx}\PYG{p}{]}
\end{Verbatim}

These need to point to the main Freesurfer directory as well as the freesurfer subjects directory.
No assumptions are made about where the directory of subjects is placed.
Recon-all must have been run on subj1 from the FSL course data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fs\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/usr/local/freesurfer}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{freesurfer}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

This needs to point to the fdt folder you can find after extracting
\href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}course\PYGZus{}data/fdt/}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fs}\PYG{o}{.}\PYG{n}{FSCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}subjects\PYGZus{}dir}\PYG{p}{(}\PYG{n}{subjects\PYGZus{}dir}\PYG{p}{)}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subj1}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

An infosource node is used to loop through the subject list and define the input files.
For our purposes, these are the diffusion-weighted MR image, b vectors, and b values.
The info dictionary is used to provide a template of the naming of these files. For instance,
the 4D nifti diffusion image is stored in the FSL course data as data.nii.gz.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}

\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvecs}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvals}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

A datasource node is used to perform the actual data grabbing.
Templates for the associated images are used to obtain the correct images.
The data are assumed to lie in data\_dir/subject\_id/.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{n}{info}\PYG{o}{.}\PYG{n}{keys}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{"}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\end{Verbatim}

FreeSurferSource nodes are used to retrieve a number of image
files that were automatically generated by the recon-all process.
Here we use three of these nodes, two of which are defined to return files for solely the left and right hemispheres.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{FreeSurferSource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{FreeSurferSource}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fssource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{FreeSurferSource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{subjects\PYGZus{}dir}

\PYG{n}{FreeSurferSourceLH} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{FreeSurferSource}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fssourceLH}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{FreeSurferSourceLH}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{subjects\PYGZus{}dir}
\PYG{n}{FreeSurferSourceLH}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{lh}\PYG{l+s}{'}

\PYG{n}{FreeSurferSourceRH} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{FreeSurferSource}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fssourceRH}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{FreeSurferSourceRH}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{subjects\PYGZus{}dir}
\PYG{n}{FreeSurferSourceRH}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{rh}\PYG{l+s}{'}
\end{Verbatim}

Since the b values and b vectors come from the FSL course, we must convert it to a scheme file
for use in Camino.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fsl2scheme} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{FSL2Scheme}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{fsl2scheme}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fsl2scheme}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{usegradmod} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

FSL's Brain Extraction tool is used to create a mask from the b0 image

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{b0Strip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bet\PYGZus{}b0}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

FSL's FLIRT function is used to coregister the b0 mask and the structural image.
A convert\_xfm node is then used to obtain the inverse of the transformation matrix.
FLIRT is used once again to apply the inverse transformation to the parcellated brain image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{n}{dof}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{coregister}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{cost} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{corratio}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{convertxfm} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ConvertXFM}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{convertxfm}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{convertxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{invert\PYGZus{}xfm} \PYG{o}{=} \PYG{n+nb+bp}{True}

\PYG{n}{inverse} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{inverse}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{inverse}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interp} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{nearestneighbour}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{inverse\PYGZus{}AparcAseg} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{inverse\PYGZus{}AparcAseg}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{inverse\PYGZus{}AparcAseg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interp} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{nearestneighbour}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

A number of conversion operations are required to obtain NIFTI files from the FreesurferSource for each subject.
Nodes are used to convert the following:
\begin{itemize}
\item {} 
Original structural image to NIFTI

\item {} 
Parcellated white matter image to NIFTI

\item {} 
Parcellated whole-brain image to NIFTI

\item {} \begin{description}
\item[{Pial, white, inflated, and spherical surfaces for both the left and right hemispheres}] \leavevmode
are converted to GIFTI for visualization in ConnectomeViewer

\end{description}

\item {} 
Parcellated annotation files for the left and right hemispheres are also converted to GIFTI

\end{itemize}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{MRIConvert}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{nii}\PYG{l+s}{'}

\PYG{n}{mri\PYGZus{}convert\PYGZus{}WMParc} \PYG{o}{=} \PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mri\PYGZus{}convert\PYGZus{}WMParc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mri\PYGZus{}convert\PYGZus{}AparcAseg} \PYG{o}{=} \PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mri\PYGZus{}convert\PYGZus{}AparcAseg}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{mris\PYGZus{}convertLH} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{MRIsConvert}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertLH}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}datatype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{gii}\PYG{l+s}{'}
\PYG{n}{mris\PYGZus{}convertRH} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertRH}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertRHwhite} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertRHwhite}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertLHwhite} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertLHwhite}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertRHinflated} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertRHinflated}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertLHinflated} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertLHinflated}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertRHsphere} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertRHsphere}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertLHsphere} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertLHsphere}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertLHlabels} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertLHlabels}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{mris\PYGZus{}convertRHlabels} \PYG{o}{=} \PYG{n}{mris\PYGZus{}convertLH}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mris\PYGZus{}convertRHlabels}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

An inputnode is used to pass the data obtained by the data grabber to the actual processing functions

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvecs}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvals}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{inputnode}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

In this section we create the nodes necessary for diffusion analysis.
First, the diffusion image is converted to voxel order, since this is the format in which Camino does
its processing.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{image2voxel} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{Image2Voxel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{image2voxel}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Second, diffusion tensors are fit to the voxel-order data.
If desired, these tensors can be converted to a Nifti tensor image using the DT2NIfTI interface.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtifit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTIFit}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dtifit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Next, a lookup table is generated from the schemefile and the
signal-to-noise ratio (SNR) of the unweighted (q=0) data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtlutgen} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTLUTGen}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dtlutgen}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dtlutgen}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{snr} \PYG{o}{=} \PYG{l+m+mf}{16.0}
\PYG{n}{dtlutgen}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inversion} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

In this tutorial we implement probabilistic tractography using the PICo algorithm.
PICo tractography requires an estimate of the fibre direction and a model of its uncertainty in each voxel;
this probabilitiy distribution map is produced using the following node.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{picopdfs} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{PicoPDFs}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{picopdfs}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{picopdfs}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputmodel} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dt}\PYG{l+s}{'}
\end{Verbatim}

Finally, tractography is performed. In this tutorial, we will use only one iteration for time-saving purposes.
It is important to note that we use the TrackPICo interface here. This interface now expects the files required
for PICo tracking (i.e. the output from picopdfs). Similar interfaces exist for alternative types of tracking,
such as Bayesian tracking with Dirac priors (TrackBayesDirac).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{track} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TrackPICo}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{track}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{iterations} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

This tutorial demonstrates two methods of connectivity mapping. The first uses the conmap function of Camino.
The problem with this method is that it can be very memory intensive. To deal with this, we add a ``shredding'' node
which removes roughly half of the tracts in the file.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractshred} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TractShredder}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tractshred}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{tractshred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{offset} \PYG{o}{=} \PYG{l+m+mi}{0}
\PYG{n}{tractshred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bunchsize} \PYG{o}{=} \PYG{l+m+mi}{2}
\PYG{n}{tractshred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{space} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

Here we create the Camino-based connectivity mapping node. For visualization, it can be beneficial to set a
threshold for the minimum number of fiber connections that are required for an edge to be drawn on the graph.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{conmap} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{Conmap}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{conmap}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{conmap}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{threshold} \PYG{o}{=} \PYG{l+m+mi}{100}
\end{Verbatim}

Currently, the best program for visualizing tracts is TrackVis. For this reason, a node is included to
convert the raw tract data to .trk format. Solely for testing purposes, another node is added to perform the reverse.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{camino2trackvis} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Camino2Trackvis}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{camino2trk}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{camino2trackvis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{min\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mi}{30}
\PYG{n}{camino2trackvis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}order} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{LAS}\PYG{l+s}{'}
\PYG{n}{trk2camino} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Trackvis2Camino}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{trk2camino}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Tracts can also be converted to VTK and OOGL formats, for use in programs such as GeomView and Paraview,
using the following two nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{vtkstreamlines} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{VtkStreamlines}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{vtkstreamlines}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{procstreamlines} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{ProcStreamlines}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{procstreamlines}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{procstreamlines}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outputtracts} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{oogl}\PYG{l+s}{'}
\end{Verbatim}

We can easily produce a variety of scalar values from our fitted tensors. The following nodes generate the
fractional anisotropy and diffusivity trace maps and their associated headers, and then merge them back
into a single .nii file.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fa} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{FA}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fa}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{trace} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{TrD}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{trace}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{dteig} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{DTEig}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dteig}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{analyzeheader\PYGZus{}fa} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{AnalyzeHeader}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{analyzeheader\PYGZus{}fa}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{analyzeheader\PYGZus{}fa}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{datatype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{double}\PYG{l+s}{'}
\PYG{n}{analyzeheader\PYGZus{}trace} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{camino}\PYG{o}{.}\PYG{n}{AnalyzeHeader}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{analyzeheader\PYGZus{}trace}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{analyzeheader\PYGZus{}trace}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{datatype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{double}\PYG{l+s}{'}

\PYG{n}{fa2nii} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{misc}\PYG{o}{.}\PYG{n}{CreateNifti}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fa2nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{trace2nii} \PYG{o}{=} \PYG{n}{fa2nii}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trace2nii}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

This section adds the Connectome Mapping Toolkit (CMTK) nodes.
These interfaces are fairly experimental and may not function properly.
In order to perform connectivity mapping using CMTK, the parcellated structural data is rewritten
using the indices and parcellation scheme from the connectome mapper (CMP). This process has been
written into the ROIGen interface, which will output a remapped aparc+aseg image as well as a
dictionary of label information (i.e. name, display colours) pertaining to the original and remapped regions.
These label values are input from a user-input lookup table, if specified, and otherwise the default
Freesurfer LUT (/freesurfer/FreeSurferColorLUT.txt).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{roigen} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cmtk}\PYG{o}{.}\PYG{n}{ROIGen}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{ROIGen}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cmp\PYGZus{}config} \PYG{o}{=} \PYG{n+nb}{cmp}\PYG{o}{.}\PYG{n}{configuration}\PYG{o}{.}\PYG{n}{PipelineConfiguration}\PYG{p}{(}\PYG{n}{parcellation\PYGZus{}scheme} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{NativeFreesurfer}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cmp\PYGZus{}config}\PYG{o}{.}\PYG{n}{parcellation\PYGZus{}scheme} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{NativeFreesurfer}\PYG{l+s}{"}
\PYG{n}{roigen}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{LUT\PYGZus{}file} \PYG{o}{=} \PYG{n}{cmp\PYGZus{}config}\PYG{o}{.}\PYG{n}{get\PYGZus{}freeview\PYGZus{}lut}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{NativeFreesurfer}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{freesurferaparc}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

The CreateMatrix interface takes in the remapped aparc+aseg image as well as the label dictionary and fiber tracts
and outputs a number of different files. The most important of which is the connectivity network itself, which is stored
as a `gpickle' and can be loaded using Python's NetworkX package (see CreateMatrix docstring). Also outputted are various
NumPy arrays containing detailed tract information, such as the start and endpoint regions, and statistics on the mean and
standard deviation for the fiber length of each connection. These matrices can be used in the ConnectomeViewer to plot the
specific tracts that connect between user-selected regions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{creatematrix} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cmtk}\PYG{o}{.}\PYG{n}{CreateMatrix}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{CreateMatrix}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{creatematrix}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{resolution\PYGZus{}network\PYGZus{}file} \PYG{o}{=} \PYG{n}{cmp\PYGZus{}config}\PYG{o}{.}\PYG{n}{parcellation}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{freesurferaparc}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{node\PYGZus{}information\PYGZus{}graphml}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

Here we define the endpoint of this tutorial, which is the CFFConverter node, as well as a few nodes which use
the Nipype Merge utility. These are useful for passing lists of the files we want packaged in our CFF file.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{CFFConverter} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{cmtk}\PYG{o}{.}\PYG{n}{CFFConverter}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{CFFConverter}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{giftiSurfaces} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{8}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{GiftiSurfaces}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{giftiLabels} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{GiftiLabels}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{niftiVolumes} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{NiftiVolumes}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fiberDataArrays} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{FiberDataArrays}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{gpickledNetworks} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{NetworkFiles}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Since we have now created all our nodes, we can define our workflow and start making connections.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mapping}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

First, we connect the input node to the early conversion functions.
FreeSurfer input nodes:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{FreeSurferSource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{FreeSurferSourceLH}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{FreeSurferSourceRH}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Required conversions for processing in Camino:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{image2voxel}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                       \PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{bvecs}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bvec\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{bvals}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{bval\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                       \PYG{p}{(}\PYG{n}{image2voxel}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}order}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                       \PYG{p}{(}\PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{scheme}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{scheme\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Nifti conversions for the parcellated white matter image (used in Camino's conmap),
and the subject's stripped brain image from Freesurfer:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSource}\PYG{p}{,} \PYG{n}{mri\PYGZus{}convert\PYGZus{}WMParc}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{wmparc}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSource}\PYG{p}{,} \PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{brain}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Surface conversions to GIFTI (pial, white, inflated, and sphere for both hemispheres)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLH}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{pial}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRH}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{pial}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLHwhite}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{white}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRHwhite}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{white}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLHinflated}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{inflated}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRHinflated}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{inflated}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLHsphere}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{sphere}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRHsphere}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{sphere}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The annotation files are converted using the pial surface as a map via the MRIsConvert interface.
One of the functions defined earlier is used to select the lh.aparc.annot and rh.aparc.annot files
specifically (rather than i.e. rh.aparc.a2009s.annot) from the output list given by the FreeSurferSource.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLHlabels}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{pial}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRHlabels}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{pial}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceLH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertLHlabels}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{annot}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{select\PYGZus{}aparc\PYGZus{}annot}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{annot\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSourceRH}\PYG{p}{,} \PYG{n}{mris\PYGZus{}convertRHlabels}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{annot}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{select\PYGZus{}aparc\PYGZus{}annot}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{annot\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

This section coregisters the diffusion-weighted and parcellated white-matter / whole brain images.
At present the conmap node connection is left commented, as there have been recent changes in Camino
code that have presented some users with errors.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{b0Strip}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{b0Strip}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{convertxfm}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}matrix\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{b0Strip}\PYG{p}{,} \PYG{n}{inverse}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{convertxfm}\PYG{p}{,} \PYG{n}{inverse}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}matrix\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mri\PYGZus{}convert\PYGZus{}WMParc}\PYG{p}{,} \PYG{n}{inverse}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{c}{\#mapping.connect([(inverse, conmap,[('out\PYGZus{}file','roi\PYGZus{}file')])])}
\end{Verbatim}

The tractography pipeline consists of the following nodes. Further information about the tractography
can be found in nipype/examples/camino\_dti\_tutorial.py.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{b0Strip}\PYG{p}{,} \PYG{n}{track}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{seed\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fsl2scheme}\PYG{p}{,} \PYG{n}{dtlutgen}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{scheme}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{scheme\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtlutgen}\PYG{p}{,} \PYG{n}{picopdfs}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dtLUT}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{luts}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{picopdfs}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{picopdfs}\PYG{p}{,} \PYG{n}{track}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{pdfs}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The tractography is passed to the shredder in preparation for connectivity mapping.
Again, the required conmap connection is left commented out.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{track}\PYG{p}{,} \PYG{n}{tractshred}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tracked}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{c}{\#mapping.connect([(tractshred, conmap,[("shredded","in\PYGZus{}file")])])}
\end{Verbatim}

Connecting the Fractional Anisotropy and Trace nodes is simple, as they obtain their input from the
tensor fitting. This is also where our voxel- and data-grabbing functions come in. We pass these functions,
along with the original DWI image from the input node, to the header-generating nodes. This ensures that the
files will be correct and readable.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fa}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{fa}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
    \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fa}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fa}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}affine}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{affine}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{analyzeheader\PYGZus{}fa}\PYG{p}{,} \PYG{n}{fa2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{header}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{header\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}


\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trace}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trace}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
    \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{trace}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{trace}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}affine}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{affine}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{analyzeheader\PYGZus{}trace}\PYG{p}{,} \PYG{n}{trace2nii}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{header}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{header\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{dtifit}\PYG{p}{,} \PYG{n}{dteig}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{tensor\PYGZus{}fitted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The output tracts are converted to Trackvis format (and back). Here we also use the voxel- and data-grabbing
functions defined at the beginning of the pipeline.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{track}\PYG{p}{,} \PYG{n}{camino2trackvis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{tracked}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                       \PYG{p}{(}\PYG{n}{track}\PYG{p}{,} \PYG{n}{vtkstreamlines}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{tracked}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                       \PYG{p}{(}\PYG{n}{camino2trackvis}\PYG{p}{,} \PYG{n}{trk2camino}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{trackvis}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{camino2trackvis}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{voxel\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
    \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}data\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data\PYGZus{}dims}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Here the CMTK connectivity mapping nodes are connected.
The original aparc+aseg image is converted to NIFTI, then registered to
the diffusion image and delivered to the ROIGen node. The remapped parcellation,
original tracts, and label file are then given to CreateMatrix.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{FreeSurferSource}\PYG{p}{,} \PYG{n}{mri\PYGZus{}convert\PYGZus{}AparcAseg}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{aparc\PYGZus{}aseg}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{select\PYGZus{}aparc}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{b0Strip}\PYG{p}{,} \PYG{n}{inverse\PYGZus{}AparcAseg}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{convertxfm}\PYG{p}{,} \PYG{n}{inverse\PYGZus{}AparcAseg}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}matrix\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mri\PYGZus{}convert\PYGZus{}AparcAseg}\PYG{p}{,} \PYG{n}{inverse\PYGZus{}AparcAseg}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inverse\PYGZus{}AparcAseg}\PYG{p}{,} \PYG{n}{roigen}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{aparc\PYGZus{}aseg\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{roigen}\PYG{p}{,} \PYG{n}{creatematrix}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{roigen}\PYG{p}{,} \PYG{n}{creatematrix}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dict\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{dict\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{camino2trackvis}\PYG{p}{,} \PYG{n}{creatematrix}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trackvis}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{tract\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{creatematrix}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{out\PYGZus{}matrix\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The merge nodes defined earlier are used here to create lists of the files which are
destined for the CFFConverter.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{creatematrix}\PYG{p}{,} \PYG{n}{gpickledNetworks}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matrix\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in1}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertLH}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in1}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertRH}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in2}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertLHwhite}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in3}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertRHwhite}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in4}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertLHinflated}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in5}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertRHinflated}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in6}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertLHsphere}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in7}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertRHsphere}\PYG{p}{,} \PYG{n}{giftiSurfaces}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in8}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertLHlabels}\PYG{p}{,} \PYG{n}{giftiLabels}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in1}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mris\PYGZus{}convertRHlabels}\PYG{p}{,} \PYG{n}{giftiLabels}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{converted}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in2}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{roigen}\PYG{p}{,} \PYG{n}{niftiVolumes}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in1}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{niftiVolumes}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dwi}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in2}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{mri\PYGZus{}convert\PYGZus{}Brain}\PYG{p}{,} \PYG{n}{niftiVolumes}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in3}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{creatematrix}\PYG{p}{,} \PYG{n}{fiberDataArrays}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{endpoint\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in1}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{creatematrix}\PYG{p}{,} \PYG{n}{fiberDataArrays}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{endpoint\PYGZus{}file\PYGZus{}mm}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in2}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{creatematrix}\PYG{p}{,} \PYG{n}{fiberDataArrays}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{fiber\PYGZus{}length\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in3}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{creatematrix}\PYG{p}{,} \PYG{n}{fiberDataArrays}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{fiber\PYGZus{}label\PYGZus{}file}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{in4}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

This block actually connects the merged lists to the CFF converter. We pass the surfaces
and volumes that are to be included, as well as the tracts and the network itself. The currently
running pipeline (connectivity\_tutorial.py) is also scraped and included in the CFF file. This
makes it easy for the user to examine the entire processing pathway used to generate the end
product.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{CFFConverter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{script\PYGZus{}files} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{n}{inspect}\PYG{o}{.}\PYG{n}{getfile}\PYG{p}{(}\PYG{n}{inspect}\PYG{o}{.}\PYG{n}{currentframe}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{giftiSurfaces}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{gifti\PYGZus{}surfaces}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{giftiLabels}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{gifti\PYGZus{}labels}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{gpickledNetworks}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{gpickled\PYGZus{}networks}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{niftiVolumes}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{nifti\PYGZus{}volumes}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{fiberDataArrays}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{out}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{data\PYGZus{}files}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{camino2trackvis}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{trackvis}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{tract\PYGZus{}files}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{mapping}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{CFFConverter}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{title}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Finally, we create another higher-level workflow to connect our mapping workflow with the info and datagrabbing nodes
declared at the beginning. Our tutorial can is now extensible to any arbitrary number of subjects by simply adding
their names to the subject list and their data to the proper folders.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{connectivity} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{connectivity}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{connectivity}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{connectivity\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{connectivity}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{mapping}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.dwi}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.bvecs}\PYG{l+s}{'}\PYG{p}{)}
                                               \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
        \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{mapping}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

The following functions run the whole workflow and produce graphs describing the processing pipeline.
By default, write\_graph outputs a .dot file and a .png image, but here we set it to output the image
as a vector graphic, by passing the format='eps' argument.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{connectivity}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{connectivity}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{n}{format}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{eps}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

The output CFF file of this pipeline can be loaded in the Connectome Viewer (\href{http://www.cmtk.org}{http://www.cmtk.org})
After loading the network into memory it can be examined in 3D or as a connectivity matrix
using the default scripts produced by the Code Oracle.
To compare networks, one must use the MergeCNetworks interface to merge two networks into
a single CFF file. Statistics can then be run using the Network Brain Statistics (NBS) plugin
Surfaces can also be loaded along with their labels from the aparc+aseg file. The tractography
is included in the file so that region-to-region fibers can be individually plotted using the
Code Oracle.


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/connectivity\_tutorial.py}).




\subsubsection{Dartmouth College Workshop 2010}
\label{users/examples/dartmouth_workshop_2010:example-dartmouth-workshop-2010}\label{users/examples/dartmouth_workshop_2010::doc}\label{users/examples/dartmouth_workshop_2010:dartmouth-college-workshop-2010}
First lets go to the directory with the data we'll be working on and start the interactive python interpreter
(with some nipype specific configuration). Note that nipype does not need to be run through ipython - it is
just much nicer to do interactive work in it.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nb}{cd} \PYG{n+nv}{\$TDPATH}
ipython -p nipype
\end{Verbatim}

For every neuroimaging procedure supported by nipype there exists a wrapper - a small piece of code managing
the underlying software (FSL, SPM, AFNI etc.). We call those interfaces. They are standarised so we can hook them up
together. Lets have a look at some of them.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [1]: }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}

\PYG{g+gp}{In [2]: }\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{o}{.}\PYG{n}{help}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{Inputs}
\PYG{g+go}{------}

\PYG{g+go}{Mandatory:}
\PYG{g+go}{ in\PYGZus{}file: input file to skull strip}

\PYG{g+go}{Optional:}
\PYG{g+go}{ args: Additional parameters to the command}
\PYG{g+go}{ center: center of gravity in voxels}
\PYG{g+go}{ environ: Environment variables (default=\PYGZob{}\PYGZcb{})}
\PYG{g+go}{ frac: fractional intensity threshold}
\PYG{g+go}{ functional: apply to 4D fMRI data}
\PYG{g+go}{  mutually exclusive: functional, reduce\PYGZus{}bias}
\PYG{g+go}{ mask: create binary mask image}
\PYG{g+go}{ mesh: generate a vtk mesh brain surface}
\PYG{g+go}{ no\PYGZus{}output: Don't generate segmented output}
\PYG{g+go}{ out\PYGZus{}file: name of output skull stripped image}
\PYG{g+go}{ outline: create surface outline image}
\PYG{g+go}{ output\PYGZus{}type: FSL output type}
\PYG{g+go}{ radius: head radius}
\PYG{g+go}{ reduce\PYGZus{}bias: bias field and neck cleanup}
\PYG{g+go}{  mutually exclusive: functional, reduce\PYGZus{}bias}
\PYG{g+go}{ skull: create skull image}
\PYG{g+go}{ threshold: apply thresholding to segmented brain image and mask}
\PYG{g+go}{ vertical\PYGZus{}gradient: vertical gradient in fractional intensity threshold (-1, 1)}

\PYG{g+go}{Outputs}
\PYG{g+go}{-------}
\PYG{g+go}{mask\PYGZus{}file: path/name of binary brain mask (if generated)}
\PYG{g+go}{meshfile: path/name of vtk mesh file (if generated)}
\PYG{g+go}{out\PYGZus{}file: path/name of skullstripped file}
\PYG{g+go}{outline\PYGZus{}file: path/name of outline file (if generated)}

\PYG{g+gp}{In [3]: }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}

\PYG{g+gp}{In [4]: }\PYG{n}{fs}\PYG{o}{.}\PYG{n}{Smooth}\PYG{o}{.}\PYG{n}{help}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{Inputs}
\PYG{g+go}{------}

\PYG{g+go}{Mandatory:}
\PYG{g+go}{ in\PYGZus{}file: source volume}
\PYG{g+go}{ num\PYGZus{}iters: number of iterations instead of fwhm}
\PYG{g+go}{  mutually exclusive: surface\PYGZus{}fwhm}
\PYG{g+go}{ reg\PYGZus{}file: registers volume to surface anatomical}
\PYG{g+go}{ surface\PYGZus{}fwhm: surface FWHM in mm}
\PYG{g+go}{  mutually exclusive: num\PYGZus{}iters}
\PYG{g+go}{  requires: reg\PYGZus{}file}

\PYG{g+go}{Optional:}
\PYG{g+go}{ args: Additional parameters to the command}
\PYG{g+go}{ environ: Environment variables (default=\PYGZob{}\PYGZcb{})}
\PYG{g+go}{ proj\PYGZus{}frac: project frac of thickness a long surface normal}
\PYG{g+go}{  mutually exclusive: proj\PYGZus{}frac\PYGZus{}avg}
\PYG{g+go}{ proj\PYGZus{}frac\PYGZus{}avg: average a long normal min max delta}
\PYG{g+go}{  mutually exclusive: proj\PYGZus{}frac}
\PYG{g+go}{ smoothed\PYGZus{}file: output volume}
\PYG{g+go}{ subjects\PYGZus{}dir: subjects directory}
\PYG{g+go}{ vol\PYGZus{}fwhm: volumesmoothing outside of surface}

\PYG{g+go}{Outputs}
\PYG{g+go}{-------}
\PYG{g+go}{args: Additional parameters to the command}
\PYG{g+go}{environ: Environment variables}
\PYG{g+go}{smoothed\PYGZus{}file: smoothed input volume}
\PYG{g+go}{subjects\PYGZus{}dir: subjects directory}
\end{Verbatim}

You can read about all of the interfaces implemented in nipype at our online documentation at \href{http://nipy.sourceforge.net/nipype/documentation.html\#documentation}{http://nipy.sourceforge.net/nipype/documentation.html\#documentation} .
Check it out now.


\paragraph{Using interfaces}
\label{users/examples/dartmouth_workshop_2010:using-interfaces}
Having interfaces allows us to use third party software (like FSL BET) as function. Look how simple it is.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{data/s1/struct.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{print} \PYG{n}{result}
\end{Verbatim}

Running a single program is not much of a breakthrough. Lets run motion correction followed by smoothing
(isotropic - in other words not using SUSAN). Notice that in the first line we are setting the output data type
for all FSL interfaces.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI\PYGZus{}GZ}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{result1} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{MCFLIRT}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{result2} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{f3\PYGZus{}mcf.nii.gz}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Simple workflow}
\label{users/examples/dartmouth_workshop_2010:simple-workflow}
In the previous example we knew that fsl.MCFLIRT will produce a file called f3\_mcf.nii.gz and we have hard coded
this as an input to fsl.Smooth. This is quite limited, but luckily nipype supports joining interfaces in pipelines.
This way output of one interface will be used as an input of another without having to hard code anything. Before
connecting Interfaces we need to put them into (separate) Nodes and give them unique names. This way every interface will
process data in a separate folder.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}
\PYG{k+kn}{import} \PYG{n+nn}{os}

\PYG{n}{motion\PYGZus{}correct} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{MCFLIRT}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                         \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{motion\PYGZus{}correct}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{motion\PYGZus{}correct\PYGZus{}and\PYGZus{}smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{motion\PYGZus{}correct\PYGZus{}and\PYGZus{}smooth}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{motion\PYGZus{}correct\PYGZus{}and\PYGZus{}smooth}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)} \PYG{c}{\# define where will be the root folder for the workflow}
\PYG{n}{motion\PYGZus{}correct\PYGZus{}and\PYGZus{}smooth}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                                   \PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                                   \PYG{p}{]}\PYG{p}{)}
\PYG{c}{\# we are connecting 'out\PYGZus{}file' output of motion\PYGZus{}correct to 'in\PYGZus{}file' input of smooth}
\PYG{n}{motion\PYGZus{}correct\PYGZus{}and\PYGZus{}smooth}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Another workflow}
\label{users/examples/dartmouth_workshop_2010:another-workflow}
Another example of a simple workflow (calculate the mean of fMRI signal and subtract it).
This time we'll be assigning inputs after defining the workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{calc\PYGZus{}mean} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{calc\PYGZus{}mean}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{calc\PYGZus{}mean}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{-Tmean}\PYG{l+s}{"}
\PYG{n}{subtract} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{subtract}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{subtract}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{-sub}\PYG{l+s}{"}

\PYG{n}{demean} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{demean}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{demean}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{demean}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                \PYG{p}{(}\PYG{n}{calc\PYGZus{}mean}\PYG{p}{,} \PYG{n}{subtract}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}

\PYG{n}{demean}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{calc\PYGZus{}mean}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{demean}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subtract}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{demean}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Reusing workflows}
\label{users/examples/dartmouth_workshop_2010:reusing-workflows}
The beauty of the workflows is that they are reusable. We can just import a workflow made by someone
else and feed it with our data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{fsl\PYGZus{}tutorial2} \PYG{k+kn}{import} \PYG{n}{preproc}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{func} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{struct} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/struct.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

... and we can run it again and it won't actually rerun anything because none of
the parameters have changed.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

... and we can change a parameter and run it again. Only the dependent nodes
are rerun and that too only if the input state has changed.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{meanfuncmask}\PYG{o}{.}\PYG{n}{frac} \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Visualizing workflows 1}
\label{users/examples/dartmouth_workshop_2010:visualizing-workflows-1}
So what did we run in this precanned workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Datasink}
\label{users/examples/dartmouth_workshop_2010:datasink}
Datasink is a special interface for copying and arranging results.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{func} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{struct} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/s1/struct.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{sinker}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preprocess} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preprocout}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preprocess}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preprocess}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                    \PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{meanfunc2.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{meanfunc}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{maskfunc3.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{funcruns}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                    \PYG{p}{]}\PYG{p}{)}
\PYG{n}{preprocess}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Datagrabber}
\label{users/examples/dartmouth_workshop_2010:datagrabber}
Datagrabber is (surprise, surprise) an interface for collecting files from hard drive. It is very flexible and
supports almost any file organisation of your data you can imagine.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource1} \PYG{o}{=} \PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{datasource1}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data/s1/f3.nii}\PYG{l+s}{'}
\PYG{n}{results} \PYG{o}{=} \PYG{n}{datasource1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{print} \PYG{n}{results}\PYG{o}{.}\PYG{n}{outputs}

\PYG{n}{datasource2} \PYG{o}{=} \PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{datasource2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data/s*/f*.nii}\PYG{l+s}{'}
\PYG{n}{results} \PYG{o}{=} \PYG{n}{datasource2}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{print} \PYG{n}{results}\PYG{o}{.}\PYG{n}{outputs}

\PYG{n}{datasource3} \PYG{o}{=} \PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{run}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{datasource3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data/s1/f}\PYG{l+s+si}{\%d}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{run} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{7}\PYG{p}{]}
\PYG{n}{results} \PYG{o}{=} \PYG{n}{datasource3}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{print} \PYG{n}{results}\PYG{o}{.}\PYG{n}{outputs}

\PYG{n}{datasource4} \PYG{o}{=} \PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{run}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{datasource4}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data/}\PYG{l+s+si}{\%s}\PYG{l+s}{/f}\PYG{l+s+si}{\%d}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource4}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{run} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{7}\PYG{p}{]}
\PYG{n}{datasource4}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s3}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{results} \PYG{o}{=} \PYG{n}{datasource4}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{print} \PYG{n}{results}\PYG{o}{.}\PYG{n}{outputs}
\end{Verbatim}


\paragraph{Iterables}
\label{users/examples/dartmouth_workshop_2010:iterables}
Iterables is a special field of the Node class that enables to iterate all workfloes/nodes connected to it over
some parameters. Here we'll use it to iterate over two subjects.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}
\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s3}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasource}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{my\PYGZus{}workflow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{my\PYGZus{}workflow}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,} \PYG{n}{preproc}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{inputspec.func}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                          \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{inputspec.struct}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

and we can change a node attribute and run it again

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smoothnode} \PYG{o}{=} \PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{get\PYGZus{}node}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{preproc.smooth}\PYG{l+s}{'}\PYG{p}{)}
\PYG{k}{assert}\PYG{p}{(}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{smoothnode}\PYG{p}{)}\PYG{o}{==}\PYG{l+s}{'}\PYG{l+s}{preproc.smooth}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{smoothnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mf}{5.}\PYG{p}{,}\PYG{l+m+mf}{10.}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{my\PYGZus{}workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Visualizing workflows 2}
\label{users/examples/dartmouth_workshop_2010:visualizing-workflows-2}
In the case of nested workflows, we might want to look at expanded forms of the workflow.
.. include:: ../../links\_names.txt


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/dartmouth\_workshop\_2010.py}).




\subsubsection{Using Diffusion Toolkit for DTI analysis}
\label{users/examples/dtk_dti_tutorial:using-diffusion-toolkit-for-dti-analysis}\label{users/examples/dtk_dti_tutorial:example-dtk-dti-tutorial}\label{users/examples/dtk_dti_tutorial::doc}
A pipeline example that uses several interfaces to perform analysis on
diffusion weighted images using Diffusion Toolkit tools.

This tutorial is based on the 2010 FSL course and uses data freely available at
the FSL website at: \href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}

More details can be found at
\href{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}

In order to run this tutorial you need to have Diffusion Toolkit and FSL tools installed and
accessible from matlab/command line. Check by calling fslinfo and dtk from the command
line.

Tell python where to find the appropriate functions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.workflows.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl\PYGZus{}wf}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.diffusion\PYGZus{}toolkit} \PYG{k+kn}{as} \PYG{n+nn}{dtk}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}

Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/dtk_dti_tutorial:setting-up-workflows}
This is a generic workflow for DTI data analysis using the FSL


\paragraph{Data specific components}
\label{users/examples/dtk_dti_tutorial:data-specific-components}
The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{dwis1} and \code{dwis2}.  Each subject directory
contains each of the following files: bvec, bval, diffusion weighted data, a set of target masks,
a seed file, and a transformation matrix.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{dwi} or \code{bvals}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

Specify the subject directories

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subj1}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

Map field names to individual subject runs

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvecs}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvals}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.engine.Node} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{n}{info}\PYG{o}{.}\PYG{n}{keys}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{"}

\PYG{c}{\# This needs to point to the fdt folder you can find after extracting}
\PYG{c}{\# http://www.fmrib.ox.ac.uk/fslcourse/fsl\PYGZus{}course\PYGZus{}data2.tar.gz}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}course\PYGZus{}data/fdt/}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\paragraph{Setup for Diffusion Tensor Computation}
\label{users/examples/dtk_dti_tutorial:setup-for-diffusion-tensor-computation}
Here we will create a generic workflow for DTI computation

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{computeTensor} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{computeTensor}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

extract the volume with b=0 (nodif\_brain)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fslroi} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ExtractROI}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fslroi}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}min}\PYG{o}{=}\PYG{l+m+mi}{0}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}
\end{Verbatim}

create a brain mask from the nodif\_brain

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bet} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bet}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.34}
\end{Verbatim}

correct the diffusion weighted images for eddy\_currents

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{eddycorrect} \PYG{o}{=} \PYG{n}{fsl\PYGZus{}wf}\PYG{o}{.}\PYG{n}{create\PYGZus{}eddy\PYGZus{}correct\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{eddycorrect}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{eddycorrect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{ref\PYGZus{}num}\PYG{o}{=}\PYG{l+m+mi}{0}
\end{Verbatim}

compute the diffusion tensor in each voxel

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtifit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{DTIRecon}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dtifit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{computeTensor}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                        \PYG{p}{(}\PYG{n}{fslroi}\PYG{p}{,}\PYG{n}{bet}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{eddycorrect}\PYG{p}{,}\PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.eddy\PYGZus{}corrected}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{DWI}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup for Tracktography}
\label{users/examples/dtk_dti_tutorial:setup-for-tracktography}
Here we will create a workflow to enable deterministic tracktography

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tractography}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{dtk\PYGZus{}tracker} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{DTITracker}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dtk\PYGZus{}tracker}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dtk\PYGZus{}tracker}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{invert\PYGZus{}x} \PYG{o}{=} \PYG{n+nb+bp}{True}

\PYG{n}{smooth\PYGZus{}trk} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{SplineFilter}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{smooth\PYGZus{}trk}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{smooth\PYGZus{}trk}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{step\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mf}{0.5}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                      \PYG{p}{(}\PYG{n}{dtk\PYGZus{}tracker}\PYG{p}{,} \PYG{n}{smooth\PYGZus{}trk}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{track\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{track\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Setup data storage area

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{datasink}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtiresults}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/workingdir/dwiproc}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup the pipeline that combines the two workflows: tractography and computeTensor}
\label{users/examples/dtk_dti_tutorial:setup-the-pipeline-that-combines-the-two-workflows-tractography-and-computetensor}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dwiproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dwiproc}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtk\PYGZus{}dti\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{computeTensor}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fslroi.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtifit.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtifit.bvecs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{eddycorrect.inputnode.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{computeTensor}\PYG{p}{,}\PYG{n}{tractography}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bet.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtk\PYGZus{}tracker.mask1\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtifit.tensor}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtk\PYGZus{}tracker.tensor\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
                                                 \PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}

\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/dtk\_dti\_tutorial.py}).




\subsubsection{Using Diffusion Toolkit for ODF analysis}
\label{users/examples/dtk_odf_tutorial::doc}\label{users/examples/dtk_odf_tutorial:using-diffusion-toolkit-for-odf-analysis}\label{users/examples/dtk_odf_tutorial:example-dtk-odf-tutorial}
A pipeline example that uses several interfaces to perform analysis on
diffusion weighted images using Diffusion Toolkit tools.

This tutorial is based on the 2010 FSL course and uses data freely available at
the FSL website at: \href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}

More details can be found at
\href{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}

In order to run this tutorial you need to have Diffusion Toolkit and FSL tools installed and
accessible from matlab/command line. Check by calling fslinfo and dtk from the command
line.

Tell python where to find the appropriate functions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.workflows.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl\PYGZus{}wf}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.diffusion\PYGZus{}toolkit} \PYG{k+kn}{as} \PYG{n+nn}{dtk}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}

Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/dtk_odf_tutorial:setting-up-workflows}
This is a generic workflow for DTI data analysis using the FSL


\paragraph{Data specific components}
\label{users/examples/dtk_odf_tutorial:data-specific-components}
The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{dwis1} and \code{dwis2}.  Each subject directory
contains each of the following files: bvec, bval, diffusion weighted data, a set of target masks,
a seed file, and a transformation matrix.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{dwi} or \code{bvals}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

Specify the subject directories

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{siemens\PYGZus{}hardi\PYGZus{}test}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

Map field names to individual subject runs

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{siemens\PYGZus{}hardi\PYGZus{}test\PYGZus{}data}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvecs}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{siemens\PYGZus{}hardi\PYGZus{}test\PYGZus{}data.bvec}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvals}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{siemens\PYGZus{}hardi\PYGZus{}test\PYGZus{}data.bval}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.engine.Node} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{n}{info}\PYG{o}{.}\PYG{n}{keys}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{"}

\PYG{c}{\# This needs to point to the fdt folder you can find after extracting}
\PYG{c}{\# http://www.fmrib.ox.ac.uk/fslcourse/fsl\PYGZus{}course\PYGZus{}data2.tar.gz}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\paragraph{Setup for ODF Computation}
\label{users/examples/dtk_odf_tutorial:setup-for-odf-computation}
Here we will create a generic workflow for ODF computation

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{compute\PYGZus{}ODF} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{compute\PYGZus{}ODF}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

extract the volume with b=0 (nodif\_brain)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fslroi} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ExtractROI}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fslroi}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}min}\PYG{o}{=}\PYG{l+m+mi}{0}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}
\end{Verbatim}

create a brain mask from the nodif\_brain

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bet} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bet}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.34}
\end{Verbatim}

correct the diffusion weighted images for eddy\_currents

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{eddycorrect} \PYG{o}{=} \PYG{n}{fsl\PYGZus{}wf}\PYG{o}{.}\PYG{n}{create\PYGZus{}eddy\PYGZus{}correct\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{eddycorrect}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{eddycorrect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{ref\PYGZus{}num}\PYG{o}{=}\PYG{l+m+mi}{0}


\PYG{n}{hardi\PYGZus{}mat} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{HARDIMat}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{hardi\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{odf\PYGZus{}recon} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{ODFRecon}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}recon}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{compute\PYGZus{}ODF}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                        \PYG{p}{(}\PYG{n}{fslroi}\PYG{p}{,}\PYG{n}{bet}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{eddycorrect}\PYG{p}{,} \PYG{n}{odf\PYGZus{}recon}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.eddy\PYGZus{}corrected}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{DWI}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{eddycorrect}\PYG{p}{,} \PYG{n}{hardi\PYGZus{}mat}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.eddy\PYGZus{}corrected}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{hardi\PYGZus{}mat}\PYG{p}{,} \PYG{n}{odf\PYGZus{}recon}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{matrix}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup for Tracktography}
\label{users/examples/dtk_odf_tutorial:setup-for-tracktography}
Here we will create a workflow to enable deterministic tracktography

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tractography}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{odf\PYGZus{}tracker} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{ODFTracker}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{odf\PYGZus{}tracker}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{smooth\PYGZus{}trk} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{dtk}\PYG{o}{.}\PYG{n}{SplineFilter}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{smooth\PYGZus{}trk}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{smooth\PYGZus{}trk}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{step\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                      \PYG{p}{(}\PYG{n}{odf\PYGZus{}tracker}\PYG{p}{,} \PYG{n}{smooth\PYGZus{}trk}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{track\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{track\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup the pipeline that combines the two workflows: tractography and compute\_ODF}
\label{users/examples/dtk_odf_tutorial:setup-the-pipeline-that-combines-the-two-workflows-tractography-and-compute-odf}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dwiproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dwiproc}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtk\PYGZus{}odf\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{compute\PYGZus{}ODF}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fslroi.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{hardi\PYGZus{}mat.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{hardi\PYGZus{}mat.bvecs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{eddycorrect.inputnode.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{compute\PYGZus{}ODF}\PYG{p}{,}\PYG{n}{tractography}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bet.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}tracker.mask1\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}recon.ODF}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}tracker.ODF}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}recon.max}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{odf\PYGZus{}tracker.max}\PYG{l+s}{'}\PYG{p}{)}
                                                 \PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}

\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{compute\PYGZus{}ODF}\PYG{o}{.}\PYG{n}{hardi\PYGZus{}mat}\PYG{o}{.}\PYG{n}{oblique\PYGZus{}correction} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{compute\PYGZus{}ODF}\PYG{o}{.}\PYG{n}{odf\PYGZus{}recon}\PYG{o}{.}\PYG{n}{n\PYGZus{}directions} \PYG{o}{=} \PYG{l+m+mi}{31}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{compute\PYGZus{}ODF}\PYG{o}{.}\PYG{n}{odf\PYGZus{}recon}\PYG{o}{.}\PYG{n}{n\PYGZus{}b0} \PYG{o}{=} \PYG{l+m+mi}{5}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{compute\PYGZus{}ODF}\PYG{o}{.}\PYG{n}{odf\PYGZus{}recon}\PYG{o}{.}\PYG{n}{n\PYGZus{}output\PYGZus{}directions} \PYG{o}{=} \PYG{l+m+mi}{181}

\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/dtk\_odf\_tutorial.py}).




\subsubsection{Using FreeSurfer for smoothing}
\label{users/examples/freesurfer_tutorial:example-freesurfer-tutorial}\label{users/examples/freesurfer_tutorial:using-freesurfer-for-smoothing}\label{users/examples/freesurfer_tutorial::doc}
This tutorial illustrates how to perform surface-based smoothing of
cortical data using \href{http://surfer.nmr.mgh.harvard.edu}{FreeSurfer} and then perform firstlevel model and
contrast estimation using \href{http://www.fil.ion.ucl.ac.uk/spm}{SPM}. A surface-based second level glm
illustrates the use of spherical registration and freesurfer's glm
functions.


\paragraph{Preparing environment}
\label{users/examples/freesurfer_tutorial:preparing-environment}

\subparagraph{Step 0}
\label{users/examples/freesurfer_tutorial:step-0}
In order to run this tutorial you need to have \href{http://www.fil.ion.ucl.ac.uk/spm}{SPM} and \href{http://surfer.nmr.mgh.harvard.edu}{FreeSurfer}
tools installed and accessible from matlab/command line. Check by
calling mri\_info from the command line.


\subparagraph{Step 1}
\label{users/examples/freesurfer_tutorial:step-1}
Link the \emph{fsaverage} directory for your freesurfer distribution. To do
this type:

\begin{Verbatim}[commandchars=@\[\]]
cd nipype-tutorial/fsdata
ln -s @$FREESURFER@_HOME/subjects/fsaverage
cd ..
\end{Verbatim}


\paragraph{Defining the workflow}
\label{users/examples/freesurfer_tutorial:defining-the-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}

\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model generation}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}      \PYG{c}{\# artifact detection}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}    \PYG{c}{\# freesurfer}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# i/o routines}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\end{Verbatim}


\subparagraph{Preliminaries}
\label{users/examples/freesurfer_tutorial:preliminaries}
Confirm package dependencies are installed.  (This is only for the tutorial,
rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set any package specific configuration.

Setting the subjects directory and the appropriate matlab command to use. if
you want to use a different spm version/path, it should also be entered here.

These are currently being set at the class level, so every node will inherit
these settings. However, these can also be changed or set for an individual
node.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Tell freesurfer what subjects directory to use}
\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsdata}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fs}\PYG{o}{.}\PYG{n}{FSCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}subjects\PYGZus{}dir}\PYG{p}{(}\PYG{n}{subjects\PYGZus{}dir}\PYG{p}{)}

\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\PYG{c}{\# If SPM is not in your MATLAB path you should add it here}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}paths}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/software/spm8}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setup preprocessing workflow}
\label{users/examples/freesurfer_tutorial:setup-preprocessing-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.algorithms.rapidart} to determine which of the
images in the functional series are outliers based on deviations in
intensity or movement.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{art} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{art}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences}      \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{False}\PYG{p}{,}\PYG{n+nb+bp}{True}\PYG{p}{]}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}norm}             \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold}       \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask\PYGZus{}type}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameter\PYGZus{}source}     \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM}\PYG{l+s}{'}
\end{Verbatim}

Use \code{nipype.interfaces.freesurfer.BBRegister} to coregister the mean
functional image generated by realign to the subjects' surfaces.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{surfregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{BBRegister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{surfregister}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{surfregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{init} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsl}\PYG{l+s}{'}
\PYG{n}{surfregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrast\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{t2}\PYG{l+s}{'}
\end{Verbatim}

Use \code{nipype.interfaces.io.FreeSurferSource} to retrieve various image
files that are automatically generated by the recon-all process.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{FreeSurferSource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{FreeSurferSource}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fssource}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.freesurfer.ApplyVolTransform} to convert the
brainmask generated by freesurfer into the realigned functional space.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{ApplyVolTransform} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{ApplyVolTransform}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{applyreg}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{ApplyVolTransform}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inverse} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.interfaces.freesurfer.Binarize} to extract a binary brain
mask.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Threshold} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{Binarize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{threshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{Threshold}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{min} \PYG{o}{=} \PYG{l+m+mi}{10}
\PYG{n}{Threshold}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{nii}\PYG{l+s}{'}
\end{Verbatim}

Two different types of functional data smoothing are performed in this
workflow. The volume smoothing option performs a standard SPM smoothin. using
\code{nipype.interfaces.spm.Smooth}. In addition, we use a smoothing routine
from freesurfer (\code{nipype.interfaces.freesurfer.Binarize}) to project the
functional data from the volume to the subjects' surface, smooth it on the
surface and fit it back into the volume forming the cortical ribbon. The
projection uses the average value along a ``cortical column''. In addition to the
surface smoothing, the rest of the volume is smoothed with a 3d gaussian kernel.

\begin{notice}{note}{Note:}
It is very important to note that the projection to the surface takes a 3d
manifold to a 2d manifold. Hence the reverse projection, simply fills the
thickness of cortex with the smoothed data. The smoothing is not performed
in a depth specific manner. The output of this branch should only be used
for surface-based analysis and visualization.
\end{notice}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{volsmooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{volsmooth}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{surfsmooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{n}{proj\PYGZus{}frac\PYGZus{}avg}\PYG{o}{=}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mf}{0.1}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{surfsmooth}\PYG{l+s}{"}\PYG{p}{,}
                        \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

We connect up the different nodes to implement the preprocessing workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{surfregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{FreeSurferSource}\PYG{p}{,} \PYG{n}{ApplyVolTransform}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{brainmask}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{target\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{surfregister}\PYG{p}{,} \PYG{n}{ApplyVolTransform}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{ApplyVolTransform}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{ApplyVolTransform}\PYG{p}{,} \PYG{n}{Threshold}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{Threshold}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{binary\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{volsmooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{surfsmooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{surfregister}\PYG{p}{,} \PYG{n}{surfsmooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Set up volume analysis workflow}
\label{users/examples/freesurfer_tutorial:set-up-volume-analysis-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{volanalysis} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{volanalysis}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate SPM-specific design information using
\code{nipype.interfaces.spm.SpecifyModel}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenate\PYGZus{}runs}        \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Generate a first level SPM.mat file for analysis
\code{nipype.interfaces.spm.Level1Design}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases}              \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateModel} to determine the
parameters of the model.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateContrast} to estimate the
first level contrasts specified in a few steps above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrastestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrastestimate}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{volanalysis}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Set up surface analysis workflow}
\label{users/examples/freesurfer_tutorial:set-up-surface-analysis-workflow}
We simply clone the volume analysis workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{surfanalysis} \PYG{o}{=} \PYG{n}{volanalysis}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{surfanalysis}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Set up volume normalization workflow}
\label{users/examples/freesurfer_tutorial:set-up-volume-normalization-workflow}
The volume analysis is performed in individual space. Therefore, post analysis
we normalize the contrast images to MNI space.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{volnorm} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{volnormconimages}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.freesurfer.MRIConvert} to convert the brainmask,
an mgz file and the contrast images (nifti-1 img/hdr pairs), to single volume
nifti images.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{convert} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{MRIConvert}\PYG{p}{(}\PYG{n}{out\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{convert2nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{convert2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{MRIConvert}\PYG{p}{(}\PYG{n}{out\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{convertimg2nii}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Segment} to segment the structural image and
generate the transformation file to MNI space.

\begin{notice}{note}{Note:}
Segment takes longer than usual because the nose is wrapped behind
the head in the structural image.
\end{notice}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{segment} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Segment}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{segment}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.freesurfer.ApplyVolTransform} to convert contrast
images into freesurfer space.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normwreg} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{ApplyVolTransform}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{source\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{applyreg2con}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Normalize} to normalize the contrast images
to MNI space

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normalize} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{n}{jobtype}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{write}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{norm2mni}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Connect up the volume normalization components

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{volnorm}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{convert}\PYG{p}{,} \PYG{n}{segment}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{convert2}\PYG{p}{,} \PYG{n}{normwreg}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{segment}\PYG{p}{,} \PYG{n}{normalize}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformation\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{parameter\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normwreg}\PYG{p}{,} \PYG{n}{normalize}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Preproc + Analysis + VolumeNormalization workflow}
\label{users/examples/freesurfer_tutorial:preproc-analysis-volumenormalization-workflow}
Connect up the lower level workflows into an integrated analysis. In addition,
we add an input node that specifies all the inputs needed for this
workflow. Thus, one can import this workflow and connect it to their own data
sources. An example with the nifti-tutorial data is provided below.

For this workflow the only necessary inputs are the functional images, a
freesurfer subject id corresponding to recon-all processed data, the session
information for the functional runs and the contrasts to be evaluated.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}
                                                             \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}
                                                             \PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}
                                                             \PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{inputnode}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Connect the components into an integrated workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,}\PYG{n}{preproc}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realign.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{surfregister.subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fssource.subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{volanalysis}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{modelspec.subject\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrastestimate.contrasts}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{surfanalysis}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{modelspec.subject\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrastestimate.contrasts}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{]}\PYG{p}{)}

\PYG{c}{\# attach volume and surface model specification and estimation components}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{volanalysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{volsmooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{art.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{threshold.binary\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{level1design.mask\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{surfanalysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{surfsmooth.smoothed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{art.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{l+s}{'}\PYG{l+s}{modelspec.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{threshold.binary\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{l+s}{'}\PYG{l+s}{level1design.mask\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                    \PYG{p}{]}\PYG{p}{)}

\PYG{c}{\# attach volume contrast normalization components}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{volnorm}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fssource.orig}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{convert2nii.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{surfregister.out\PYGZus{}reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{applyreg2con.reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fssource.orig}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{applyreg2con.target\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{volanalysis}\PYG{p}{,} \PYG{n}{volnorm}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{l+s}{'}\PYG{l+s}{convertimg2nii.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{]}\PYG{p}{)}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Data specific components}
\label{users/examples/freesurfer_tutorial:data-specific-components}
The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{s1} and \code{s2}.  Each subject directory
contains four functional volumes: f3.nii, f5.nii, f7.nii, f10.nii. And
one anatomical volume named struct.nii.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

In the example below, run `f3' is of type `func' and gets mapped to a
nifti filename through a template `\%s.nii'. So `f3' would become
`f3.nii'.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data.}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s3}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f7}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f10}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\subparagraph{Set preprocessing parameters}
\label{users/examples/freesurfer_tutorial:set-preprocessing-parameters}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{fssource}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{n}{subjects\PYGZus{}dir}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{volsmooth}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{4}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{surfsmooth}\PYG{o}{.}\PYG{n}{surface\PYGZus{}fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{surfsmooth}\PYG{o}{.}\PYG{n}{vol\PYGZus{}fwhm} \PYG{o}{=} \PYG{l+m+mi}{4}
\end{Verbatim}


\subparagraph{Experimental paradigm specific components}
\label{users/examples/freesurfer_tutorial:experimental-paradigm-specific-components}
Here we create a function that returns subject-specific information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix. In this tutorial, the same
paradigm was used for every participant.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{subjectinfo}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
    \PYG{k+kn}{from} \PYG{n+nn}{copy} \PYG{k+kn}{import} \PYG{n}{deepcopy}
    \PYG{k}{print} \PYG{l+s}{"}\PYG{l+s}{Subject ID: }\PYG{l+s+si}{\%s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
    \PYG{n}{output} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{n}{names} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{onsets} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{15}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{45}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{]}
        \PYG{n}{output}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{r}\PYG{p}{,}
                      \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{names}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{n}{deepcopy}\PYG{p}{(}\PYG{n}{onsets}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{]} \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{names}\PYG{p}{]}\PYG{p}{,}
                            \PYG{p}{)}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{output}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}
\end{Verbatim}


\subparagraph{Set up node specific inputs}
\label{users/examples/freesurfer_tutorial:set-up-node-specific-inputs}
We replicate the modelspec parameters separately for the surface- and
volume-based analysis.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspecref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{volanalysis}\PYG{o}{.}\PYG{n}{modelspec}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}

\PYG{n}{modelspecref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{surfanalysis}\PYG{o}{.}\PYG{n}{modelspec}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}

\PYG{n}{l1designref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{volanalysis}\PYG{o}{.}\PYG{n}{level1design}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}

\PYG{n}{l1designref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{surfanalysis}\PYG{o}{.}\PYG{n}{level1design}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\end{Verbatim}


\subparagraph{Setup the pipeline}
\label{users/examples/freesurfer_tutorial:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Workfow} to create a
graph-based execution pipeline for first level analysis.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{volsurf\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.func}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inputnode.subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjectinfo}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{l+s}{'}\PYG{l+s}{inputnode.session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Store the output}
\label{users/examples/freesurfer_tutorial:store-the-output}
Create a datasink node to store the contrast images and registration info

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{volsurf\PYGZus{}tutorial/l1out}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{substitutions} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{getsubs}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{subs} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{subject\PYGZus{}id}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}
    \PYG{k}{return} \PYG{n}{subs}

\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getsubs}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{substitutions}\PYG{l+s}{'}\PYG{p}{)}
                                       \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{l1pipeline}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{surfanalysis.contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{preproc.surfregister.out\PYGZus{}reg\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{registrations}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Run the analysis pipeline and also create a dot+png (if graphviz is available)
that visually represents the workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{n}{graph2use}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{flat}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Level2 surface-based pipeline}
\label{users/examples/freesurfer_tutorial:level2-surface-based-pipeline}
Create a level2 workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2flow} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{l2out}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{volsurf\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Setup a dummy node to iterate over contrasts and hemispheres

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{,}
                                                               \PYG{l+s}{'}\PYG{l+s}{hemi}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{inputnode}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2inputnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{,} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{contrasts}\PYG{p}{)}\PYG{o}{+}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                         \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{hemi}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{lh}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{rh}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Use a datagrabber node to collect contrast images and registration files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2source} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                             \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reg}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                   \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{l2source}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{volsurf\PYGZus{}tutorial/l1out}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{*}\PYG{l+s}{'}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{con}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{*/contrasts/con\PYGZus{}}\PYG{l+s+si}{\%04d}\PYG{l+s}{.img}\PYG{l+s}{'}\PYG{p}{,}
                                      \PYG{n}{reg}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{*/registrations/*.dat}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{con}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}\PYG{n}{reg}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{l2inputnode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{contrasts}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{l2source}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Merge contrast images and registration files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mergenode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{axis}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{hstack}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merge}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{ordersubjects}\PYG{p}{(}\PYG{n}{files}\PYG{p}{,} \PYG{n}{subj\PYGZus{}list}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{outlist} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{subj\PYGZus{}list}\PYG{p}{:}
        \PYG{k}{for} \PYG{n}{f} \PYG{o+ow}{in} \PYG{n}{files}\PYG{p}{:}
            \PYG{k}{if} \PYG{l+s}{'}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{f}\PYG{p}{:}
                \PYG{n}{outlist}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{f}\PYG{p}{)}
                \PYG{k}{continue}
    \PYG{k}{print} \PYG{n}{outlist}
    \PYG{k}{return} \PYG{n}{outlist}

\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{l2source}\PYG{p}{,}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{ordersubjects}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{l2source}\PYG{p}{,}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{reg}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{ordersubjects}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Concatenate contrast images projected to fsaverage

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2concat} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{MRISPreproc}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{concat}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2concat}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{target} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsaverage}\PYG{l+s}{'}
\PYG{n}{l2concat}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}

\PYG{k}{def} \PYG{n+nf}{list2tuple}\PYG{p}{(}\PYG{n}{listoflist}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{tuple}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)} \PYG{k}{for} \PYG{n}{x} \PYG{o+ow}{in} \PYG{n}{listoflist}\PYG{p}{]}
\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{l2inputnode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{hemi}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{l2concat}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{hemi}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{mergenode}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{list2tuple}\PYG{p}{)}\PYG{p}{,} \PYG{n}{l2concat}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{vol\PYGZus{}measure\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Perform a one sample t-test

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2ttest} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fs}\PYG{o}{.}\PYG{n}{OneSampleTTest}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{onesample}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{l2concat}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{l2ttest}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Run the analysis pipeline and also create a dot+png (if graphviz is available)
that visually represents the workflow.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{l2flow}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{n}{graph2use}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{flat}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/freesurfer\_tutorial.py}).




\subsubsection{Using FSL for DTI analysis}
\label{users/examples/fsl_dti_tutorial::doc}\label{users/examples/fsl_dti_tutorial:using-fsl-for-dti-analysis}\label{users/examples/fsl_dti_tutorial:example-fsl-dti-tutorial}
A pipeline example that uses several interfaces to perform analysis on
diffusion weighted images using FSL FDT tools.

This tutorial is based on the 2010 FSL course and uses data freely available at
the FSL website at: \href{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}{http://www.fmrib.ox.ac.uk/fslcourse/fsl\_course\_data2.tar.gz}

More details can be found at
\href{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt/index.htm}

In order to run this tutorial you need to have fsl tools installed and
accessible from matlab/command line. Check by calling fslinfo from the command
line.

Tell python where to find the appropriate functions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.workflows.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl\PYGZus{}wf}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}

Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/fsl_dti_tutorial:setting-up-workflows}
This is a generic workflow for DTI data analysis using the FSL


\paragraph{Data specific components}
\label{users/examples/fsl_dti_tutorial:data-specific-components}
The nipype tutorial contains data for two subjects.  Subject data is in two
subdirectories, \code{dwis1} and \code{dwis2}.  Each subject directory contains each
of the following files: bvec, bval, diffusion weighted data, a set of target
masks, a seed file, and a transformation matrix.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{dwi} or \code{bvals}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

Specify the subject directories

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subj1}\PYG{l+s}{'}\PYG{p}{]}
\end{Verbatim}

Map field names to individual subject runs

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvecs}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{bvals}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}thal\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{target\PYGZus{}masks} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}M1\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}S1\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}occipital\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}pfc\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}pmc\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}ppc\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{,}
                                           \PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}temporal\PYGZus{}right}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.engine.Node} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{n}{info}\PYG{o}{.}\PYG{n}{keys}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{"}

\PYG{c}{\# This needs to point to the fdt folder you can find after extracting}
\PYG{c}{\# http://www.fmrib.ox.ac.uk/fslcourse/fsl\PYGZus{}course\PYGZus{}data2.tar.gz}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}course\PYGZus{}data/fdt/}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{'}\PYG{p}{,}
                                        \PYG{n}{seed\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{.bedpostX/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{"}\PYG{p}{,}
                                        \PYG{n}{target\PYGZus{}masks}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{.bedpostX/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\paragraph{Setup for Diffusion Tensor Computation}
\label{users/examples/fsl_dti_tutorial:setup-for-diffusion-tensor-computation}
Here we will create a generic workflow for DTI computation

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{computeTensor} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{computeTensor}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

extract the volume with b=0 (nodif\_brain)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fslroi} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ExtractROI}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fslroi}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}min}\PYG{o}{=}\PYG{l+m+mi}{0}
\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}
\end{Verbatim}

create a brain mask from the nodif\_brain

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bet} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bet}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.34}
\end{Verbatim}

correct the diffusion weighted images for eddy\_currents

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{eddycorrect} \PYG{o}{=} \PYG{n}{fsl\PYGZus{}wf}\PYG{o}{.}\PYG{n}{create\PYGZus{}eddy\PYGZus{}correct\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{eddycorrect}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{eddycorrect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{ref\PYGZus{}num}\PYG{o}{=}\PYG{l+m+mi}{0}
\end{Verbatim}

compute the diffusion tensor in each voxel

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dtifit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{DTIFit}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dtifit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{computeTensor}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                        \PYG{p}{(}\PYG{n}{fslroi}\PYG{p}{,}\PYG{n}{bet}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{eddycorrect}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.eddy\PYGZus{}corrected}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{base\PYGZus{}name}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{bet}\PYG{p}{,}\PYG{n}{dtifit}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                      \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup for Tracktography}
\label{users/examples/fsl_dti_tutorial:setup-for-tracktography}
Here we will create a workflow to enable probabilistic tracktography
and hard segmentation of the seed region

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tractography}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}dti\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

estimate the diffusion parameters: phi, theta, and so on

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bedpostx} \PYG{o}{=} \PYG{n}{fsl\PYGZus{}wf}\PYG{o}{.}\PYG{n}{create\PYGZus{}bedpostx\PYGZus{}pipeline}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{bedpostx}\PYG{o}{.}\PYG{n}{get\PYGZus{}node}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{xfibres}\PYG{l+s}{"}\PYG{p}{)}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{n\PYGZus{}fibres}\PYG{l+s}{"}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}


\PYG{n}{flirt} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{flirt}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{flirt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Info}\PYG{o}{.}\PYG{n}{standard\PYGZus{}image}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{MNI152\PYGZus{}T1\PYGZus{}2mm\PYGZus{}brain.nii.gz}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{flirt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dof} \PYG{o}{=} \PYG{l+m+mi}{12}
\end{Verbatim}

perform probabilistic tracktography

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{probtrackx} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ProbTrackX}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{probtrackx}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mode}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{seedmask}\PYG{l+s}{'}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{c\PYGZus{}thresh} \PYG{o}{=} \PYG{l+m+mf}{0.2}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n\PYGZus{}steps}\PYG{o}{=}\PYG{l+m+mi}{2000}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{step\PYGZus{}length}\PYG{o}{=}\PYG{l+m+mf}{0.5}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{n\PYGZus{}samples}\PYG{o}{=}\PYG{l+m+mi}{5000}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{opd}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{os2t}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{probtrackx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{loop\PYGZus{}check}\PYG{o}{=}\PYG{n+nb+bp}{True}
\end{Verbatim}

perform hard segmentation on the output of probtrackx

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{findthebiggest} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FindTheBiggest}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{findthebiggest}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

connect all the nodes for this workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{add\PYGZus{}nodes}\PYG{p}{(}\PYG{p}{[}\PYG{n}{bedpostx}\PYG{p}{,} \PYG{n}{flirt}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{tractography}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{bedpostx}\PYG{p}{,}\PYG{n}{probtrackx}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.thsamples}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{thsamples}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.phsamples}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{phsamples}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outputnode.fsamples}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fsamples}\PYG{l+s}{'}\PYG{p}{)}
                                            \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{n}{probtrackx}\PYG{p}{,}\PYG{n}{findthebiggest}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{targets}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{n}{flirt}\PYG{p}{,} \PYG{n}{probtrackx}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}matrix\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{xfm}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                     \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Setup data storage area

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{datasink}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtiresults}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{os}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/workingdir/dwiproc}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup the pipeline that combines the two workflows: tractography and computeTensor}
\label{users/examples/fsl_dti_tutorial:setup-the-pipeline-that-combines-the-two-workflows-tractography-and-computetensor}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dwiproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{dwiproc}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsl\PYGZus{}dti\PYGZus{}tutorial}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasource}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{computeTensor}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fslroi.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtifit.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dtifit.bvecs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{eddycorrect.inputnode.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{tractography}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bedpostx.inputnode.bvals}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bedpostx.inputnode.bvecs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{probtrackx.seed}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{target\PYGZus{}masks}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{probtrackx.target\PYGZus{}masks}\PYG{l+s}{'}\PYG{p}{)}
                                              \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{computeTensor}\PYG{p}{,}\PYG{n}{tractography}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{eddycorrect.outputnode.eddy\PYGZus{}corrected}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bedpostx.inputnode.dwi}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bet.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{bedpostx.inputnode.mask}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bet.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{probtrackx.mask}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fslroi.roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{flirt.reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{tractography}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{findthebiggest.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fbiggest.@biggestsegmentation}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}

\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{dwiproc}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/fsl\_dti\_tutorial.py}).




\subsubsection{Using FSL for fMRI analysis with FEEDS data}
\label{users/examples/fsl_feeds_tutorial:using-fsl-for-fmri-analysis-with-feeds-data}\label{users/examples/fsl_feeds_tutorial::doc}\label{users/examples/fsl_feeds_tutorial:example-fsl-feeds-tutorial}
A pipeline example that data from the FSL FEEDS set. Single subject, two
stimuli.

You can find it at \href{http://www.fmrib.ox.ac.uk/fsl/feeds/doc/index.html}{http://www.fmrib.ox.ac.uk/fsl/feeds/doc/index.html}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}

\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model generation}
\end{Verbatim}


\paragraph{Preliminaries}
\label{users/examples/fsl_feeds_tutorial:preliminaries}
Setup any package specific configuration. The output file format for FSL
routines is being set to compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI\PYGZus{}GZ}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/fsl_feeds_tutorial:setting-up-workflows}
In this tutorial we will be setting up a hierarchical workflow for fsl
analysis. This will demonstrate how pre-defined workflows can be setup and
shared across users, projects and labs.


\paragraph{Setup preprocessing workflow}
\label{users/examples/fsl_feeds_tutorial:setup-preprocessing-workflow}
This is a generic fsl feat preprocessing workflow encompassing skull stripping,
motion correction and smoothing operations.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set up a node to define all inputs required for the preprocessing workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}
                                                             \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{inputspec}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Convert functional images to float representation. Since there can be more than
one functional run we use a MapNode to convert each run.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{img2float} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{out\PYGZus{}data\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{float}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}dtype}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{img2float}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{img2float}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Extract the middle volume of the first run as the reference

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{extract\PYGZus{}ref} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ExtractROI}\PYG{p}{(}\PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{extractref}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to pick the first file from a list of files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{pickfirst}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{files}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{k}{return} \PYG{n}{files}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{k}{else}\PYG{p}{:}
        \PYG{k}{return} \PYG{n}{files}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{img2float}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to return the 1 based index of the middle volume

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getmiddlevolume}\PYG{p}{(}\PYG{n}{func}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nibabel} \PYG{k+kn}{import} \PYG{n}{load}
    \PYG{n}{funcfile} \PYG{o}{=} \PYG{n}{func}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{func}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{funcfile} \PYG{o}{=} \PYG{n}{func}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{timepoints} \PYG{o}{=} \PYG{n}{load}\PYG{p}{(}\PYG{n}{funcfile}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get\PYGZus{}shape}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{(}\PYG{n}{timepoints}\PYG{o}{/}\PYG{l+m+mi}{2}\PYG{p}{)}\PYG{o}{-}\PYG{l+m+mi}{1}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getmiddlevolume}\PYG{p}{)}\PYG{p}{,} \PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{t\PYGZus{}min}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Realign the functional runs to the middle volume of the first run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{motion\PYGZus{}correct} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{MCFLIRT}\PYG{p}{(}\PYG{n}{save\PYGZus{}mats} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                                                  \PYG{n}{save\PYGZus{}plots} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{realign}\PYG{l+s}{'}\PYG{p}{,}
                            \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{img2float}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{ref\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Extract the mean volume of the first functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                   \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{meanfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Strip the skull from the mean functional to generate a mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfuncmask} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                                         \PYG{n}{no\PYGZus{}output}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}
                                         \PYG{n}{frac} \PYG{o}{=} \PYG{l+m+mf}{0.3}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{meanfuncmask}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{meanfuncmask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the functional runs with the extracted mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}bet}\PYG{l+s}{'}\PYG{p}{,}
                                               \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{maskfunc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfuncmask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the 2nd and 98th percentile intensities of each functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{getthresh} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageStats}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-p 2 -p 98}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{getthreshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getthresh}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Threshold the first run of the functional data at 10\% of the 98th percentile

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{threshold} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{out\PYGZus{}data\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{char}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}thresh}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{threshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get 10\% of the intensity

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getthreshop}\PYG{p}{(}\PYG{n}{thresh}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{l+s}{'}\PYG{l+s}{-thr }\PYG{l+s+si}{\%.10f}\PYG{l+s}{ -Tmin -bin}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{o}{*}\PYG{n}{thresh}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{getthresh}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getthreshop}\PYG{p}{)}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the median value of the functional runs using the mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{medianval} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageStats}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-k }\PYG{l+s+si}{\%s}\PYG{l+s}{ -p 50}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{medianval}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{medianval}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{medianval}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Dilate the mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dilatemask} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}dil}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-dilF}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dilatemask}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the motion corrected functional runs with the dilated mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{maskfunc2}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the mean image from each functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc2}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{meanfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Merge the median values with the mean functional images into a coupled list

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mergenode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{axis}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{hstack}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merge}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfunc2}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Smooth each run using SUSAN with the brightness threshold set to 75\% of the
median value for each run and a mask consituting the mean functional

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{SUSAN}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{brightness\PYGZus{}threshold}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{usans}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{smooth}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get the brightness threshold for SUSAN

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getbtthresh}\PYG{p}{(}\PYG{n}{medianvals}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{l+m+mf}{0.75}\PYG{o}{*}\PYG{n}{val} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{medianvals}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{convert\PYGZus{}th}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{p}{[}\PYG{n+nb}{tuple}\PYG{p}{(}\PYG{p}{[}\PYG{n}{val}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{l+m+mf}{0.75}\PYG{o}{*}\PYG{n}{val}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{x}\PYG{p}{]}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getbtthresh}\PYG{p}{)}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{brightness\PYGZus{}threshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{mergenode}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{convert\PYGZus{}th}\PYG{p}{)}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{usans}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the smoothed data with the dilated mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc3} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{maskfunc3}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{smoothed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Scale each volume of the run so that the median value of the run is set to 10000

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{intnorm} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}intnorm}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{intnorm}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get the scaling factor for intensity normalization

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getinormscale}\PYG{p}{(}\PYG{n}{medianvals}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{-mul }\PYG{l+s+si}{\%.10f}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{l+m+mf}{10000.}\PYG{o}{/}\PYG{n}{val}\PYG{p}{)} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{medianvals}\PYG{p}{]}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getinormscale}\PYG{p}{)}\PYG{p}{,} \PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Perform temporal highpass filtering on the data

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{highpass} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}tempfilt}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{highpass}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{highpass}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate a mean functional image from the first run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc3} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc3}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{highpass}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{meanfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Strip the structural image a coregister the mean functional image to the
structural image

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{nosestrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.3}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{nosestrip}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{skullstrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{stripstruct}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{n}{dof}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{coregister}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{nosestrip}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{nosestrip}\PYG{p}{,} \PYG{n}{skullstrip}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{skullstrip}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{meanfunc2}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up model fitting workflow}
\label{users/examples/fsl_feeds_tutorial:set-up-model-fitting-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelfit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelfit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.algorithms.modelgen.SpecifyModel} to generate design information.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifyModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}  \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Level1Design} to generate a run specific fsf
file for analysis

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FEATModel} to generate a run specific mat
file for use by FILMGLS

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelgen} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FEATModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelgen}\PYG{l+s}{'}\PYG{p}{,}
                      \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FILMGLS} to estimate a model specified by a
mat file and a functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FILMGLS}\PYG{p}{(}\PYG{n}{smooth\PYGZus{}autocorr}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}
                                                 \PYG{n}{mask\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,}
                                                 \PYG{n}{threshold}\PYG{o}{=}\PYG{l+m+mi}{1000}\PYG{p}{)}\PYG{p}{,}
                           \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelestimate}\PYG{l+s}{'}\PYG{p}{,}
                           \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.ContrastMgr} to generate contrast estimates

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{conestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ContrastMgr}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{conestimate}\PYG{l+s}{'}\PYG{p}{,}
                         \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{,}
                                      \PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{,}
                                      \PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
   \PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{modelgen}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{ev\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{ev\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelgen}\PYG{p}{,}\PYG{n}{modelestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelgen}\PYG{p}{,}\PYG{n}{conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{tcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelgen}\PYG{p}{,}\PYG{n}{conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{fcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelestimate}\PYG{p}{,}\PYG{n}{conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up fixed-effects workflow}
\label{users/examples/fsl_feeds_tutorial:set-up-fixed-effects-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fixed\PYGZus{}fx} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fixedfx}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Merge} to merge the copes and
varcopes for each condition

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{copemerge}    \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{n}{dimension}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{t}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{copemerge}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{varcopemerge} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{n}{dimension}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{t}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{varcopemerge}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.L2Model} to generate subject and condition
specific level 2 model design files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level2model} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{L2Model}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{l2model}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FLAMEO} to estimate a second level model

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{flameo} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLAMEO}\PYG{p}{(}\PYG{n}{run\PYGZus{}mode}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fe}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{flameo}\PYG{l+s}{"}\PYG{p}{,}
                    \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{var\PYGZus{}cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{fixed\PYGZus{}fx}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{copemerge}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{varcopemerge}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{var\PYGZus{}cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level2model}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}con}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{t\PYGZus{}con\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}grp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cov\PYGZus{}split\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up first-level workflow}
\label{users/examples/fsl_feeds_tutorial:set-up-first-level-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{sort\PYGZus{}copes}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{numelements} \PYG{o}{=} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{files}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
    \PYG{n}{outfiles} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{numelements}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outfiles}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{i}\PYG{p}{,}\PYG{p}{[}\PYG{p}{]}\PYG{p}{)}
        \PYG{k}{for} \PYG{n}{j}\PYG{p}{,} \PYG{n}{elements} \PYG{o+ow}{in} \PYG{n+nb}{enumerate}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
            \PYG{n}{outfiles}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{elements}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{outfiles}

\PYG{k}{def} \PYG{n+nf}{num\PYGZus{}copes}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}

\PYG{n}{firstlevel} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{modelfit}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{highpass.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{highpass.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{modelestimate.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{fixed\PYGZus{}fx}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregister.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{flameo.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{modelfit}\PYG{p}{,} \PYG{n}{fixed\PYGZus{}fx}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.copes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{sort\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{copemerge.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.varcopes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{sort\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{varcopemerge.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.copes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{num\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{l2model.num\PYGZus{}copes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{]}\PYG{p}{)}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Experiment specific components}
\label{users/examples/fsl_feeds_tutorial:experiment-specific-components}
This tutorial does a single subject analysis so we are not using infosource and
iterables

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the FEEDS data. You can find it at http://www.fmrib.ox.ac.uk/fsl/feeds/doc/index.html}
\PYG{n}{feeds\PYGZus{}data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{feeds\PYGZus{}data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fmri}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{structural}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataSource} object and fill in the
information from above about the layout of our data.  The
\code{nipype.pipeline.Node} module wraps the interface object and provides
additional housekeeping and pipeline specific functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{feeds\PYGZus{}data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii.gz}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}

\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}

\PYG{n}{hpcutoff} \PYG{o}{=} \PYG{l+m+mi}{100}
\PYG{n}{TR} \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{highpass}\PYG{o}{.}\PYG{n}{suffix} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}hpf}\PYG{l+s}{'}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{highpass}\PYG{o}{.}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-bptf }\PYG{l+s+si}{\%d}\PYG{l+s}{ -1}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{n}{hpcutoff}\PYG{o}{/}\PYG{n}{TR}\PYG{p}{)}
\end{Verbatim}

Setup a function that returns subject-specific information about the
experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information necessary
to generate an SPM design matrix. In this tutorial, the same paradigm was used
for every participant. Other examples of this function are available in the
\emph{doc/examples} folder. Note: Python knowledge required here.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}

\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Visual}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Auditory}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                        \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{(}\PYG{l+m+mi}{180}\PYG{o}{*}\PYG{n}{TR}\PYG{p}{)}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{(}\PYG{l+m+mi}{180}\PYG{o}{*}\PYG{n}{TR}\PYG{p}{)}\PYG{p}{,}\PYG{l+m+mi}{90}\PYG{p}{)}\PYG{p}{]}\PYG{p}{,}
                        \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{30}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{45}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                        \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                        \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                        \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                        \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                        \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a list of
lists. The inner list specifies the contrasts and has the following format -
{[}Name,Stat,{[}list of condition names{]},{[}weights on those conditions{]}. The
condition names must match the \emph{names} listed in the \emph{subjectinfo} function
described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Visual\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Visual}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Auditory}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Auditory\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Visual}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Auditory}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{cont3} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,} \PYG{n}{cont2}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{,}\PYG{n}{cont3}\PYG{p}{]}

\PYG{n}{model\PYGZus{}serial\PYGZus{}correlations} \PYG{o}{=} \PYG{n+nb+bp}{True}

\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{input\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{n}{hpcutoff}


\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{dgamma}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{n+nb+bp}{True}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{model\PYGZus{}serial\PYGZus{}correlations} \PYG{o}{=} \PYG{n}{model\PYGZus{}serial\PYGZus{}correlations}
\end{Verbatim}


\subparagraph{Set up complete workflow}
\label{users/examples/fsl_feeds_tutorial:set-up-complete-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{./fsl\PYGZus{}feeds/workingdir}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{config} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{crashdump\PYGZus{}dir}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{./fsl\PYGZus{}feeds/crashdumps}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,} \PYG{n}{firstlevel}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.inputspec.struct}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.inputspec.func}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Setup the datasink

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{n}{parameterization}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{./fsl\PYGZus{}feeds/l1out}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{substitutions} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dtype\PYGZus{}mcf\PYGZus{}mask\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{meanfunc}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                 \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{brain\PYGZus{}brain\PYGZus{}flirt}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{coregistered}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}
\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{firstlevel}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fixedfx.flameo.stats\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{fixedfx.@con}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{preproc.coregister.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{coregstruct}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{preproc.meanfunc2.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{meanfunc}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{modelfit.conestimate.zstats}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{level1.@Z}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{]}\PYG{p}{)}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Execute the pipeline}
\label{users/examples/fsl_feeds_tutorial:execute-the-pipeline}
The code discussed above sets up all the necessary data structures with
appropriate parameters and the connectivity between the processes, but does not
generate any output. To actually run the analysis on the data the
\code{nipype.pipeline.engine.Pipeline.Run} function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{c}{\#    l2pipeline.run()}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/fsl\_feeds\_tutorial.py}).




\subsubsection{Using FSL for fMRI analysis}
\label{users/examples/fsl_tutorial2:example-fsl-tutorial2}\label{users/examples/fsl_tutorial2:using-fsl-for-fmri-analysis}\label{users/examples/fsl_tutorial2::doc}
A workflow that uses fsl to perform a first level analysis on the nipype
tutorial data set:

\begin{Verbatim}[commandchars=@\[\]]
python fsl@_tutorial2.py
\end{Verbatim}

First tell python where to find the appropriate functions.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}

\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model generation}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}      \PYG{c}{\# artifact detection}
\end{Verbatim}


\paragraph{Preliminaries}
\label{users/examples/fsl_tutorial2:preliminaries}
Setup any package specific configuration. The output file format for FSL
routines is being set to compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI\PYGZus{}GZ}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/fsl_tutorial2:setting-up-workflows}
In this tutorial we will be setting up a hierarchical workflow for fsl
analysis. This will demonstrate how pre-defined workflows can be setup and
shared across users, projects and labs.


\paragraph{Setup preprocessing workflow}
\label{users/examples/fsl_tutorial2:setup-preprocessing-workflow}
This is a generic fsl feat preprocessing workflow encompassing skull stripping,
motion correction and smoothing operations.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set up a node to define all inputs required for the preprocessing workflow

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}
                                                             \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{inputspec}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Convert functional images to float representation. Since there can be more than
one functional run we use a MapNode to convert each run.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{img2float} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{out\PYGZus{}data\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{float}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}dtype}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{img2float}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{img2float}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Extract the middle volume of the first run as the reference

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{extract\PYGZus{}ref} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ExtractROI}\PYG{p}{(}\PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{extractref}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to pick the first file from a list of files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{pickfirst}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{files}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{k}{return} \PYG{n}{files}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{k}{else}\PYG{p}{:}
        \PYG{k}{return} \PYG{n}{files}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{img2float}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to return the 1 based index of the middle volume

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getmiddlevolume}\PYG{p}{(}\PYG{n}{func}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nibabel} \PYG{k+kn}{import} \PYG{n}{load}
    \PYG{n}{funcfile} \PYG{o}{=} \PYG{n}{func}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{func}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{funcfile} \PYG{o}{=} \PYG{n}{func}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{\PYGZus{}}\PYG{p}{,}\PYG{n}{timepoints} \PYG{o}{=} \PYG{n}{load}\PYG{p}{(}\PYG{n}{funcfile}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get\PYGZus{}shape}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{(}\PYG{n}{timepoints}\PYG{o}{/}\PYG{l+m+mi}{2}\PYG{p}{)}\PYG{o}{-}\PYG{l+m+mi}{1}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getmiddlevolume}\PYG{p}{)}\PYG{p}{,} \PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{t\PYGZus{}min}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Realign the functional runs to the middle volume of the first run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{motion\PYGZus{}correct} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{MCFLIRT}\PYG{p}{(}\PYG{n}{save\PYGZus{}mats} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                                                  \PYG{n}{save\PYGZus{}plots} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{realign}\PYG{l+s}{'}\PYG{p}{,}
                            \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{img2float}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{extract\PYGZus{}ref}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{roi\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{ref\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Plot the estimated motion parameters

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{plot\PYGZus{}motion} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{PlotMotionParams}\PYG{p}{(}\PYG{n}{in\PYGZus{}source}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fsl}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                        \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{plot\PYGZus{}motion}\PYG{l+s}{'}\PYG{p}{,}
                        \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{plot\PYGZus{}motion}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{plot\PYGZus{}type}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{rotations}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{translations}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{par\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{plot\PYGZus{}motion}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Extract the mean volume of the first functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                   \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{meanfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Strip the skull from the mean functional to generate a mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfuncmask} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                                         \PYG{n}{no\PYGZus{}output}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}
                                         \PYG{n}{frac} \PYG{o}{=} \PYG{l+m+mf}{0.3}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{meanfuncmask}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{meanfuncmask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the functional runs with the extracted mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}bet}\PYG{l+s}{'}\PYG{p}{,}
                                               \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{maskfunc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfuncmask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the 2nd and 98th percentile intensities of each functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{getthresh} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageStats}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-p 2 -p 98}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{getthreshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getthresh}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Threshold the first run of the functional data at 10\% of the 98th percentile

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{threshold} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{out\PYGZus{}data\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{char}\PYG{l+s}{'}\PYG{p}{,}
                                             \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}thresh}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{threshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get 10\% of the intensity

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getthreshop}\PYG{p}{(}\PYG{n}{thresh}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{l+s}{'}\PYG{l+s}{-thr }\PYG{l+s+si}{\%.10f}\PYG{l+s}{ -Tmin -bin}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{o}{*}\PYG{n}{thresh}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{getthresh}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getthreshop}\PYG{p}{)}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the median value of the functional runs using the mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{medianval} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageStats}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-k }\PYG{l+s+si}{\%s}\PYG{l+s}{ -p 50}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{medianval}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{medianval}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{medianval}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Dilate the mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{dilatemask} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}dil}\PYG{l+s}{'}\PYG{p}{,}
                                              \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-dilF}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{dilatemask}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{threshold}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the motion corrected functional runs with the dilated mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{maskfunc2}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Determine the mean image from each functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc2} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc2}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{meanfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Merge the median values with the mean functional images into a coupled list

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{mergenode} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{axis}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{hstack}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merge}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{meanfunc2}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mergenode}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Smooth each run using SUSAN with the brightness threshold set to 75\% of the
median value for each run and a mask constituting the mean functional

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{SUSAN}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{brightness\PYGZus{}threshold}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{usans}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                    \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{smooth}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get the brightness threshold for SUSAN

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getbtthresh}\PYG{p}{(}\PYG{n}{medianvals}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{l+m+mf}{0.75}\PYG{o}{*}\PYG{n}{val} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{medianvals}\PYG{p}{]}

\PYG{k}{def} \PYG{n+nf}{getusans}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{p}{[}\PYG{n+nb}{tuple}\PYG{p}{(}\PYG{p}{[}\PYG{n}{val}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{l+m+mf}{0.75}\PYG{o}{*}\PYG{n}{val}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{x}\PYG{p}{]}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc2}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getbtthresh}\PYG{p}{)}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{brightness\PYGZus{}threshold}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{mergenode}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getusans}\PYG{p}{)}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{usans}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Mask the smoothed data with the dilated mask

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{maskfunc3} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-mas}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{maskfunc3}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{smooth}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{smoothed\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{dilatemask}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file2}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Scale each volume of the run so that the median value of the run is set to 10000

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{intnorm} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}intnorm}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{intnorm}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{maskfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Define a function to get the scaling factor for intensity normalization

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{getinormscale}\PYG{p}{(}\PYG{n}{medianvals}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{-mul }\PYG{l+s+si}{\%.10f}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{l+m+mf}{10000.}\PYG{o}{/}\PYG{n}{val}\PYG{p}{)} \PYG{k}{for} \PYG{n}{val} \PYG{o+ow}{in} \PYG{n}{medianvals}\PYG{p}{]}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{medianval}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}stat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getinormscale}\PYG{p}{)}\PYG{p}{,} \PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{op\PYGZus{}string}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Perform temporal highpass filtering on the data

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{highpass} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}tempfilt}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{highpass}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{intnorm}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{highpass}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate a mean functional image from the first run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{meanfunc3} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{op\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{-Tmean}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{n}{suffix}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{meanfunc3}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{n}{highpass}\PYG{p}{,} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{n}{meanfunc3}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Strip the structural image and coregister the mean functional image to the
structural image

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{nosestrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{frac}\PYG{o}{=}\PYG{l+m+mf}{0.3}\PYG{p}{)}\PYG{p}{,}
                    \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{nosestrip}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{skullstrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{stripstruct}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{n}{dof}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{coregister}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.algorithms.rapidart} to determine which of the
images in the functional series are outliers based on deviations in
intensity and/or movement.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{art} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{n}{use\PYGZus{}differences} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{False}\PYG{p}{,}\PYG{n+nb+bp}{True}\PYG{p}{]}\PYG{p}{,}
                                          \PYG{n}{use\PYGZus{}norm} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                                          \PYG{n}{norm\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mf}{0.5}\PYG{p}{,}
                                          \PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}\PYG{p}{,}
                                          \PYG{n}{parameter\PYGZus{}source} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{FSL}\PYG{l+s}{'}\PYG{p}{,}
                                          \PYG{n}{mask\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
              \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{art}\PYG{l+s}{"}\PYG{p}{)}


\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{inputnode}\PYG{p}{,} \PYG{n}{nosestrip}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{nosestrip}\PYG{p}{,} \PYG{n}{skullstrip}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{skullstrip}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{meanfunc2}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reference}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{motion\PYGZus{}correct}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{par\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{maskfunc2}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{dilatemask}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up model fitting workflow}
\label{users/examples/fsl_tutorial2:set-up-model-fitting-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelfit} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelfit}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.algorithms.modelgen.SpecifyModel} to generate design information.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifyModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}  \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Level1Design} to generate a run specific fsf
file for analysis

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FEATModel} to generate a run specific mat
file for use by FILMGLS

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelgen} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FEATModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelgen}\PYG{l+s}{'}\PYG{p}{,}
                      \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{ev\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FILMGLS} to estimate a model specified by a
mat file and a functional run

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FILMGLS}\PYG{p}{(}\PYG{n}{smooth\PYGZus{}autocorr}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}
                                                 \PYG{n}{mask\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,}
                                                 \PYG{n}{threshold}\PYG{o}{=}\PYG{l+m+mi}{1000}\PYG{p}{)}\PYG{p}{,}
                           \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{modelestimate}\PYG{l+s}{'}\PYG{p}{,}
                           \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.ContrastMgr} to generate contrast estimates

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{conestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ContrastMgr}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{conestimate}\PYG{l+s}{'}\PYG{p}{,}
                         \PYG{n}{iterfield} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{tcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{,}
                                      \PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{,}
                                      \PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}
   \PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{modelgen}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{fsf\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{ev\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{ev\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelgen}\PYG{p}{,}\PYG{n}{modelestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelgen}\PYG{p}{,}\PYG{n}{conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{tcon\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{(}\PYG{n}{modelestimate}\PYG{p}{,}\PYG{n}{conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{param\PYGZus{}estimates}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{sigmasquareds}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{corrections}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                               \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dof\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
   \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up fixed-effects workflow}
\label{users/examples/fsl_tutorial2:set-up-fixed-effects-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{fixed\PYGZus{}fx} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fixedfx}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Merge} to merge the copes and
varcopes for each condition

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{copemerge}    \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{n}{dimension}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{t}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                          \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                          \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{copemerge}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{varcopemerge} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{n}{dimension}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{t}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                       \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                       \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{varcopemerge}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.L2Model} to generate subject and condition
specific level 2 model design files

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level2model} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{L2Model}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                      \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{l2model}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.FLAMEO} to estimate a second level model

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{flameo} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{MapNode}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLAMEO}\PYG{p}{(}\PYG{n}{run\PYGZus{}mode}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fe}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{flameo}\PYG{l+s}{"}\PYG{p}{,}
                    \PYG{n}{iterfield}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{var\PYGZus{}cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{fixed\PYGZus{}fx}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{copemerge}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{varcopemerge}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{var\PYGZus{}cope\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level2model}\PYG{p}{,}\PYG{n}{flameo}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}con}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{t\PYGZus{}con\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}grp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cov\PYGZus{}split\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up first-level workflow}
\label{users/examples/fsl_tutorial2:set-up-first-level-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{sort\PYGZus{}copes}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{numelements} \PYG{o}{=} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{files}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
    \PYG{n}{outfiles} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{numelements}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outfiles}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{i}\PYG{p}{,}\PYG{p}{[}\PYG{p}{]}\PYG{p}{)}
        \PYG{k}{for} \PYG{n}{j}\PYG{p}{,} \PYG{n}{elements} \PYG{o+ow}{in} \PYG{n+nb}{enumerate}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
            \PYG{n}{outfiles}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{elements}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{outfiles}

\PYG{k}{def} \PYG{n+nf}{num\PYGZus{}copes}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{files}\PYG{p}{)}

\PYG{n}{firstlevel} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{modelfit}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{highpass.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{art.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{modelspec.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{highpass.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{modelestimate.in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{fixed\PYGZus{}fx}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregister.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{flameo.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{modelfit}\PYG{p}{,} \PYG{n}{fixed\PYGZus{}fx}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.copes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{sort\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{copemerge.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.varcopes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{sort\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{varcopemerge.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{conestimate.copes}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{num\PYGZus{}copes}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{l2model.num\PYGZus{}copes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                         \PYG{p}{]}\PYG{p}{)}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Experiment specific components}
\label{users/examples/fsl_tutorial2:experiment-specific-components}
The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{s1} and \code{s2}.  Each subject directory
contains four functional volumes: f3.nii, f5.nii, f7.nii, f10.nii. And
one anatomical volume named struct.nii.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

In the example below, run `f3' is of type `func' and gets mapped to a
nifti filename through a template `\%s.nii'. So `f3' would become
`f3.nii'.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data.}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{]} \PYG{c}{\#, 's3']}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f7}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f10}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataSource} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Use the get\_node function to retrieve an internal node by name. Then set the
iterables on this node to perform two different extents of smoothing.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smoothnode} \PYG{o}{=} \PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{get\PYGZus{}node}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{preproc.smooth}\PYG{l+s}{'}\PYG{p}{)}
\PYG{k}{assert}\PYG{p}{(}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{smoothnode}\PYG{p}{)}\PYG{o}{==}\PYG{l+s}{'}\PYG{l+s}{preproc.smooth}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{smoothnode}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mf}{5.}\PYG{p}{,}\PYG{l+m+mf}{10.}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{hpcutoff} \PYG{o}{=} \PYG{l+m+mi}{120}
\PYG{n}{TR} \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{highpass}\PYG{o}{.}\PYG{n}{suffix} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}hpf}\PYG{l+s}{'}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{highpass}\PYG{o}{.}\PYG{n}{op\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-bptf }\PYG{l+s+si}{\%d}\PYG{l+s}{ -1}\PYG{l+s}{'}\PYG{o}{\%}\PYG{p}{(}\PYG{n}{hpcutoff}\PYG{o}{/}\PYG{n}{TR}\PYG{p}{)}
\end{Verbatim}

Setup a function that returns subject-specific information about the
experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information necessary
to generate an SPM design matrix. In this tutorial, the same paradigm was used
for every participant. Other examples of this function are available in the
\emph{doc/examples} folder. Note: Python knowledge required here.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{subjectinfo}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
    \PYG{k+kn}{from} \PYG{n+nn}{copy} \PYG{k+kn}{import} \PYG{n}{deepcopy}
    \PYG{k}{print} \PYG{l+s}{"}\PYG{l+s}{Subject ID: }\PYG{l+s+si}{\%s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
    \PYG{n}{output} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{n}{names} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{onsets} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{15}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{45}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{]}
        \PYG{n}{output}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{r}\PYG{p}{,}
                      \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{names}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{n}{deepcopy}\PYG{p}{(}\PYG{n}{onsets}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{]} \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{names}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{output}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a list of
lists. The inner list specifies the contrasts and has the following format -
{[}Name,Stat,{[}list of condition names{]},{[}weights on those conditions{]}. The
condition names must match the \emph{names} listed in the \emph{subjectinfo} function
described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{cont3} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,} \PYG{n}{cont2}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}

\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{input\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{n}{hpcutoff}

\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{dgamma}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{n+nb+bp}{False}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\PYG{n}{firstlevel}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelfit}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{model\PYGZus{}serial\PYGZus{}correlations} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}


\subparagraph{Set up complete workflow}
\label{users/examples/fsl_tutorial2:set-up-complete-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{./fsl/workingdir}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{config} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{crashdump\PYGZus{}dir}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{./fsl/crashdumps}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{firstlevel}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjectinfo}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{modelfit.modelspec.subject\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,} \PYG{n}{firstlevel}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.inputspec.struct}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.inputspec.func}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Execute the pipeline}
\label{users/examples/fsl_tutorial2:execute-the-pipeline}
The code discussed above sets up all the necessary data structures with
appropriate parameters and the connectivity between the processes, but does not
generate any output. To actually run the analysis on the data the
\code{nipype.pipeline.engine.Pipeline.Run} function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{n}{graph2use}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{flat}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/fsl\_tutorial2.py}).




\subsubsection{Using SPM and nipy for fMRI analysis}
\label{users/examples/nipy_tutorial::doc}\label{users/examples/nipy_tutorial:example-nipy-tutorial}\label{users/examples/nipy_tutorial:using-spm-and-nipy-for-fmri-analysis}
The nipy\_tutorial.py integrates several interfaces to perform a first level
analysis on a two-subject data set. It is very similar to the spm\_tutorial with
the difference of using nipy for fitting GLM model and estimating contrasts.
The tutorial can
be found in the examples folder. Run the tutorial from inside the
nipype tutorial directory:
\begin{quote}

python nipy\_tutorial.py
\end{quote}
\begin{description}
\item[{::}] \leavevmode
from nipype.interfaces.nipy.model import FitGLM, EstimateContrast
from nipype.interfaces.nipy.preprocess import ComputeMask

\end{description}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}      \PYG{c}{\# artifact detection}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model specification}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}


\paragraph{Preliminaries}
\label{users/examples/nipy_tutorial:preliminaries}
Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set any package specific configuration. The output file format
for FSL routines is being set to uncompressed NIFTI and a specific
version of matlab is being used. The uncompressed format is required
because SPM does not handle compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Tell fsl to generate all output in uncompressed nifti format}
\PYG{c}{\#print fsl.Info.version()}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}

\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{s1} and \code{s2}.  Each subject directory
contains four functional volumes: f3.nii, f5.nii, f7.nii, f10.nii. And
one anatomical volume named struct.nii.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

In the example below, run `f3' is of type `func' and gets mapped to a
nifti filename through a template `\%s.nii'. So `f3' would become
`f3.nii'.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data.}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f7}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f10}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}


\paragraph{Preprocessing pipeline nodes}
\label{users/examples/nipy_tutorial:preprocessing-pipeline-nodes}
Now we create a \code{nipype.interfaces.io.DataSource} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}

\PYG{n}{compute\PYGZus{}mask} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ComputeMask}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{compute\PYGZus{}mask}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.algorithms.rapidart} to determine which of the
images in the functional series are outliers based on deviations in
intensity or movement.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{art} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{art}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences}      \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{True}\PYG{p}{,}\PYG{n+nb+bp}{True}\PYG{p}{]}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}norm}             \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold}       \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask\PYGZus{}type}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameter\PYGZus{}source}     \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM}\PYG{l+s}{'}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Coregister} to perform a rigid
body registration of the functional data to the structural data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{coregister}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}
\end{Verbatim}

Smooth the functional data using
\code{nipype.interfaces.spm.Smooth}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{4}
\end{Verbatim}


\paragraph{Set up analysis components}
\label{users/examples/nipy_tutorial:set-up-analysis-components}
Here we create a function that returns subject-specific information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix. In this tutorial, the same
paradigm was used for every participant.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{subjectinfo}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
    \PYG{k+kn}{from} \PYG{n+nn}{copy} \PYG{k+kn}{import} \PYG{n}{deepcopy}
    \PYG{k}{print} \PYG{l+s}{"}\PYG{l+s}{Subject ID: }\PYG{l+s+si}{\%s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
    \PYG{n}{output} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{n}{names} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{onsets} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{15}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{45}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{]}
        \PYG{n}{output}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{r}\PYG{p}{,}
                      \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{names}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{n}{deepcopy}\PYG{p}{(}\PYG{n}{onsets}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{]} \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{names}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{output}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}
\end{Verbatim}

Generate design information using
\code{nipype.interfaces.spm.SpecifyModel}. nipy accepts only design specified
in seconds so ``output\_units'' has always have to be set to ``secs''.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenate\PYGZus{}runs}        \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}
\end{Verbatim}

Fit the GLM model using nipy and ordinary least square method

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{model\PYGZus{}estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{FitGLM}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{model\PYGZus{}estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{model\PYGZus{}estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{TR} \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{model\PYGZus{}estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{model} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{spherical}\PYG{l+s}{"}
\PYG{n}{model\PYGZus{}estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{method} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{ols}\PYG{l+s}{"}
\end{Verbatim}

Estimate the contrasts. The format of the contrasts definition is the same as
for FSL and SPM

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrast\PYGZus{}estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrast\PYGZus{}estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrast\PYGZus{}estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}
\end{Verbatim}


\paragraph{Setup the pipeline}
\label{users/examples/nipy_tutorial:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Pipeline} to create a
graph-based execution pipeline for first level analysis. The config
options tells the pipeline engine to use \emph{workdir} as the disk
location to use when running the processes and keeping their
outputs. The \emph{use\_parameterized\_dirs} tells the engine to create
sub-directories under \emph{workdir} corresponding to the iterables in the
pipeline. Thus for this pipeline there will be subject specific
sub-directories.

The \code{nipype.pipeline.engine.Pipeline.connect} function creates the
links between the processes, i.e., how data should flow in and out of
the processing nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{nipy\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{realign}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{compute\PYGZus{}mask}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}volume}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,} \PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{target}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                        \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{smooth}\PYG{p}{,} \PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{compute\PYGZus{}mask}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{brain\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{art}\PYG{p}{,} \PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{modelspec}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{subjectinfo}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{subject\PYGZus{}info}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,} \PYG{n}{model\PYGZus{}estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{compute\PYGZus{}mask}\PYG{p}{,} \PYG{n}{model\PYGZus{}estimate}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{brain\PYGZus{}mask}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{model\PYGZus{}estimate}\PYG{p}{,} \PYG{n}{contrast\PYGZus{}estimate}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{beta}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{beta}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{nvbeta}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{nvbeta}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{s2}\PYG{l+s}{"}\PYG{p}{,}\PYG{l+s}{"}\PYG{l+s}{s2}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{dof}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{dof}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{axis}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{axis}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{constants}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{constants}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,}
                                                        \PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{reg\PYGZus{}names}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{reg\PYGZus{}names}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                  \PYG{p}{]}\PYG{p}{)}

\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/nipy\_tutorial.py}).




\subsubsection{Using SPM for analysis: Auditory dataset}
\label{users/examples/spm_auditory_tutorial:using-spm-for-analysis-auditory-dataset}\label{users/examples/spm_auditory_tutorial:example-spm-auditory-tutorial}\label{users/examples/spm_auditory_tutorial::doc}

\paragraph{Introduction}
\label{users/examples/spm_auditory_tutorial:introduction}
The spm\_auditory\_tutorial.py recreates the classical workflow described in the SPM8 manual (\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf})
using auditory dataset that can be downloaded from \href{http://www.fil.ion.ucl.ac.uk/spm/data/auditory/}{http://www.fil.ion.ucl.ac.uk/spm/data/auditory/}:
\begin{quote}

python spm\_auditory\_tutorial.py
\end{quote}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlabimport nipype.interfaces.fsl as fsl          \# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model specification}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}


\subparagraph{Preliminaries}
\label{users/examples/spm_auditory_tutorial:preliminaries}
Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}


\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setting up workflows}
\label{users/examples/spm_auditory_tutorial:setting-up-workflows}
In this tutorial we will be setting up a hierarchical workflow for spm
analysis. This will demonstrate how pre-defined workflows can be setup
and shared across users, projects and labs.


\subparagraph{Setup preprocessing workflow}
\label{users/examples/spm_auditory_tutorial:setup-preprocessing-workflow}
This is a generic preprocessing workflow that can be used by different analyses

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

We strongly encourage to use 4D files insteead of series of 3D for fMRI analyses
for many reasons (cleanness and saving and filesystem inodes are among them). However,
the the workflow presented in the SPM8 manual which this tutorial is based on
uses 3D files. Therefore we leave converting to 4D as an option. We are using \emph{merge\_to\_4d}
variable, because switching between 3d and 4d requires some additional steps (explauned later on).
Use \code{nipype.interfaces.fsl.Merge} to merge a series of 3D files along the time
dimension creating a 4d file.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{merge\PYGZus{}to\PYGZus{}4d} \PYG{o}{=} \PYG{n+nb+bp}{True}

\PYG{k}{if} \PYG{n}{merge\PYGZus{}to\PYGZus{}4d}\PYG{p}{:}
    \PYG{n}{merge} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Merge}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{merge}\PYG{l+s}{"}\PYG{p}{)}
    \PYG{n}{merge}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dimension}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{t}\PYG{l+s}{"}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Coregister} to perform a rigid
body registration of the functional data to the structural data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{coregister}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}



\PYG{n}{segment} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Segment}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{segment}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Uncomment the following line for faster execution

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\#segment.inputs.gaussians\PYGZus{}per\PYGZus{}class = [1, 1, 1, 4]}
\end{Verbatim}

Warp functional and structural data to SPM's T1 template using
\code{nipype.interfaces.spm.Normalize}.  The tutorial data set
includes the template image, T1.nii.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normalize\PYGZus{}func} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize\PYGZus{}func}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize\PYGZus{}func}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{write}\PYG{l+s}{"}

\PYG{n}{normalize\PYGZus{}struc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize\PYGZus{}struc}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize\PYGZus{}struc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{write}\PYG{l+s}{"}
\end{Verbatim}

Smooth the functional data using
\code{nipype.interfaces.spm.Smooth}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

\emph{write\_voxel\_sizes} is the input of the normalize interface that is recommended to be set to
the voxel sizes of the target volume. There is no need to set it manually since we van infer it from data
using the following function:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{voxdims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}zooms}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Here we are connecting all the nodes together. Notice that we add the merge node only if you choose
to use 4D. Also \emph{get\_vox\_dims} function is passed along the input volume of normalise to set the optimal
voxel sizes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{merge\PYGZus{}to\PYGZus{}4d}\PYG{p}{:}
    \PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{merge}\PYG{p}{,} \PYG{n}{realign}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{target}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{segment}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}source}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{segment}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformation\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{parameter\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{segment}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}struc}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformation\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{parameter\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{modulated\PYGZus{}input\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{modulated\PYGZus{}input\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{write\PYGZus{}voxel\PYGZus{}sizes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{write\PYGZus{}voxel\PYGZus{}sizes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Set up analysis workflow}
\label{users/examples/spm_auditory_tutorial:set-up-analysis-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1analysis} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{analysis}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate SPM-specific design information using
\code{nipype.interfaces.spm.SpecifyModel}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Generate a first level SPM.mat file for analysis
\code{nipype.interfaces.spm.Level1Design}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases}              \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateModel} to determine the
parameters of the model.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}

\PYG{n}{threshold} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Threshold}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{threshold}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateContrast} to estimate the
first level contrasts specified in a few steps above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrastestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrastestimate}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{l1analysis}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{contrastestimate}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                    \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{stat\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Preproc + Analysis pipeline}
\label{users/examples/spm_auditory_tutorial:preproc-analysis-pipeline}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Pluging in \emph{functional\_runs} is a bit more complicated, because model spec expects a list of \emph{runs}.
Every run can be a 4D file or a list of 3D files. Therefore for 3D analysis we need a list of lists and
to make one we need a helper function.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{merge\PYGZus{}to\PYGZus{}4d}\PYG{p}{:}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                                \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{k}{else}\PYG{p}{:}
    \PYG{k}{def} \PYG{n+nf}{makelist}\PYG{p}{(}\PYG{n}{item}\PYG{p}{)}\PYG{p}{:}
        \PYG{k}{return} \PYG{p}{[}\PYG{n}{item}\PYG{p}{]}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{makelist}\PYG{p}{)}\PYG{p}{,}
                                                \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Data specific components}
\label{users/examples/spm_auditory_tutorial:data-specific-components}
In this tutorial there is only one subject \emph{M00223}.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data downloaded from http://www.fil.ion.ucl.ac.uk/spm/data/auditory/}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{M00223}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{f}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{16}\PYG{p}{,}\PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s+si}{\%s}\PYG{l+s}{\PYGZus{}}\PYG{l+s+si}{\%03d}\PYG{l+s}{.img}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\subparagraph{Experimental paradigm specific components}
\label{users/examples/spm_auditory_tutorial:experimental-paradigm-specific-components}
Here we create a structure that provides information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\PYG{n}{subjectinfo} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{6}\PYG{p}{,}\PYG{l+m+mi}{84}\PYG{p}{,}\PYG{l+m+mi}{12}\PYG{p}{)}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{6}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{active \textgreater{} rest}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{]}

\PYG{c}{\# set up node specific inputs}
\PYG{n}{modelspecref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{modelspec}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{scans}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{scans}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mi}{7}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}

\PYG{n}{l1designref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{level1design}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{]}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{subjectinfo}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{threshold}\PYG{o}{.}\PYG{n}{contrast\PYGZus{}index} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}


\subparagraph{Setup the pipeline}
\label{users/examples/spm_auditory_tutorial:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Pipeline} to create a
graph-based execution pipeline for first level analysis. The config
options tells the pipeline engine to use \emph{workdir} as the disk
location to use when running the processes and keeping their
outputs. The \emph{use\_parameterized\_dirs} tells the engine to create
sub-directories under \emph{workdir} corresponding to the iterables in the
pipeline. Thus for this pipeline there will be subject specific
sub-directories.

The \code{nipype.pipeline.engine.Pipeline.connect} function creates the
links between the processes, i.e., how data should flow in and out of
the processing nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.coregister.source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}
\PYG{k}{if} \PYG{n}{merge\PYGZus{}to\PYGZus{}4d}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.merge.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{k}{else}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.realign.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setup storage results}
\label{users/examples/spm_auditory_tutorial:setup-storage-results}
Use \code{nipype.interfaces.io.DataSink} to store selected outputs
from the pipeline in a specific location. This allows the user to
selectively choose important output bits from the analysis and keep
them.

The first step is to create a datasink node and then to connect
outputs from the modules above to storage locations. These take the
following form directory\_name{[}.{[}@{]}subdir{]} where parts between {[}{]} are
optional. For example `realign.@mean' below creates a directory called
realign in `l1output/subject\_id/' and stores the mean image output
from the Realign process in the realign directory. If the @ is left
out, then a sub-directory with the name `mean' would be created and
the mean image would be copied to that directory.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}tutorial/l1output}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{os}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}

\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{l1pipeline}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@con}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@T}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Execute the pipeline}
\label{users/examples/spm_auditory_tutorial:execute-the-pipeline}
The code discussed above sets up all the necessary data structures
with appropriate parameters and the connectivity between the
processes, but does not generate any output. To actually run the
analysis on the data the \code{nipype.pipeline.engine.Pipeline.Run}
function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/spm\_auditory\_tutorial.py}).




\subsubsection{Using SPM for analysis: Famous vs non-famous faces}
\label{users/examples/spm_face_tutorial:using-spm-for-analysis-famous-vs-non-famous-faces}\label{users/examples/spm_face_tutorial:example-spm-face-tutorial}\label{users/examples/spm_face_tutorial::doc}

\paragraph{Introduction}
\label{users/examples/spm_face_tutorial:introduction}
The spm\_face\_tutorial.py recreates the classical workflow described in the SPM8 manual (\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf})
using auditory dataset that can be downloaded from \href{http://www.fil.ion.ucl.ac.uk/spm/data/face\_rep/face\_rep\_SPM5.html}{http://www.fil.ion.ucl.ac.uk/spm/data/face\_rep/face\_rep\_SPM5.html}:
\begin{quote}

python spm\_tutorial.py
\end{quote}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model specification}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}


\subparagraph{Preliminaries}
\label{users/examples/spm_face_tutorial:preliminaries}
Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set any package specific configuration. The output file format
for FSL routines is being set to uncompressed NIFTI and a specific
version of matlab is being used. The uncompressed format is required
because SPM does not handle compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Tell fsl to generate all output in uncompressed nifti format}
\PYG{k}{print} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Info}\PYG{o}{.}\PYG{n}{version}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}

\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\PYG{c}{\# If SPM is not in your MATLAB path you should add it here}
\PYG{c}{\# mlab.MatlabCommand.set\PYGZus{}default\PYGZus{}paths('/path/to/your/spm8')}
\end{Verbatim}


\subparagraph{Setting up workflows}
\label{users/examples/spm_face_tutorial:setting-up-workflows}
In this tutorial we will be setting up a hierarchical workflow for spm
analysis. It one is slightly different then the one used in spm\_tutorial2.


\subparagraph{Setup preprocessing workflow}
\label{users/examples/spm_face_tutorial:setup-preprocessing-workflow}
This is a generic preprocessing workflow that can be used by different analyses

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}

\PYG{n}{slice\PYGZus{}timing} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{SliceTiming}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{slice\PYGZus{}timing}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Coregister} to perform a rigid
body registration of the functional data to the structural data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{coregister}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}



\PYG{n}{segment} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Segment}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{segment}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Uncomment the following line for faster execution

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\#segment.inputs.gaussians\PYGZus{}per\PYGZus{}class = [1, 1, 1, 4]}
\end{Verbatim}

Warp functional and structural data to SPM's T1 template using
\code{nipype.interfaces.spm.Normalize}.  The tutorial data set
includes the template image, T1.nii.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normalize\PYGZus{}func} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize\PYGZus{}func}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize\PYGZus{}func}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{write}\PYG{l+s}{"}

\PYG{n}{normalize\PYGZus{}struc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize\PYGZus{}struc}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize\PYGZus{}struc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{write}\PYG{l+s}{"}
\end{Verbatim}

Smooth the functional data using
\code{nipype.interfaces.spm.Smooth}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

\emph{write\_voxel\_sizes} is the input of the normalize interface that is recommended to be set to
the voxel sizes of the target volume. There is no need to set it manually since we van infer it from data
using the following function:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
    \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{,} \PYG{n+nb}{list}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{volume} \PYG{o}{=} \PYG{n}{volume}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
    \PYG{n}{nii} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{volume}\PYG{p}{)}
    \PYG{n}{hdr} \PYG{o}{=} \PYG{n}{nii}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{voxdims} \PYG{o}{=} \PYG{n}{hdr}\PYG{o}{.}\PYG{n}{get\PYGZus{}zooms}\PYG{p}{(}\PYG{p}{)}
    \PYG{k}{return} \PYG{p}{[}\PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{voxdims}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Here we are connecting all the nodes together. Notice that we add the merge node only if you choose
to use 4D. Also \emph{get\_vox\_dims} function is passed along the input volume of normalise to set the optimal
voxel sizes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{target}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{segment}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}source}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{segment}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformation\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{parameter\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{segment}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}struc}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{transformation\PYGZus{}mat}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{parameter\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{modulated\PYGZus{}input\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{modulated\PYGZus{}input\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{write\PYGZus{}voxel\PYGZus{}sizes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,} \PYG{n}{slice\PYGZus{}timing}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{slice\PYGZus{}timing}\PYG{p}{,} \PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{timecorrected\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{timecorrected\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{get\PYGZus{}vox\PYGZus{}dims}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{write\PYGZus{}voxel\PYGZus{}sizes}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normalize\PYGZus{}func}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Set up analysis workflow}
\label{users/examples/spm_face_tutorial:set-up-analysis-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1analysis} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{analysis}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate SPM-specific design information using
\code{nipype.interfaces.spm.SpecifyModel}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Generate a first level SPM.mat file for analysis
\code{nipype.interfaces.spm.Level1Design}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateModel} to determine the
parameters of the model.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}

\PYG{n}{threshold} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Threshold}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{threshold}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateContrast} to estimate the
first level contrasts specified in a few steps above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrastestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrastestimate}\PYG{l+s}{"}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{pickfirst}\PYG{p}{(}\PYG{n}{l}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{n}{l}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}

\PYG{n}{l1analysis}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{contrastestimate}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                    \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{pickfirst}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{stat\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Preproc + Analysis pipeline}
\label{users/examples/spm_face_tutorial:preproc-analysis-pipeline}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}

Pluging in \emph{functional\_runs} is a bit more complicated, because model spec expects a list of \emph{runs}.
Every run can be a 4D file or a list of 3D files. Therefore for 3D analysis we need a list of lists and
to make one we need a helper function.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{makelist}\PYG{p}{(}\PYG{n}{item}\PYG{p}{)}\PYG{p}{:}
    \PYG{k}{return} \PYG{p}{[}\PYG{n}{item}\PYG{p}{]}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{makelist}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Data specific components}
\label{users/examples/spm_face_tutorial:data-specific-components}
In this tutorial there is only one subject \emph{M03953}.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data downloaded from http://www.fil.ion.ucl.ac.uk/spm/data/face\PYGZus{}rep/face\PYGZus{}rep\PYGZus{}SPM5.html}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}face\PYGZus{}data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{M03953}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{RawEPI}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{"}\PYG{l+s}{\PYGZus{}}\PYG{l+s+si}{\%04d}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n}{i} \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{6}\PYG{p}{,}\PYG{l+m+mi}{357}\PYG{p}{)}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Structural}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+m+mi}{7}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/s}\PYG{l+s+si}{\%s}\PYG{l+s}{\PYGZus{}}\PYG{l+s+si}{\%04d}\PYG{l+s+si}{\%s}\PYG{l+s}{.img}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\subparagraph{Experimental paradigm specific components}
\label{users/examples/spm_face_tutorial:experimental-paradigm-specific-components}
Here we create a structure that provides information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\end{Verbatim}

We're importing the onset times from a mat file (found on
\href{http://www.fil.ion.ucl.ac.uk/spm/data/face\_rep/face\_rep\_SPM5.html}{http://www.fil.ion.ucl.ac.uk/spm/data/face\_rep/face\_rep\_SPM5.html}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{scipy.io.matlab} \PYG{k+kn}{import} \PYG{n}{loadmat}
\PYG{n}{mat} \PYG{o}{=} \PYG{n}{loadmat}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{data\PYGZus{}dir}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{sots.mat}\PYG{l+s}{"}\PYG{p}{)}\PYG{p}{,} \PYG{n}{struct\PYGZus{}as\PYGZus{}record}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}
\PYG{n}{sot} \PYG{o}{=} \PYG{n}{mat}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sot}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
\PYG{n}{itemlag} \PYG{o}{=} \PYG{n}{mat}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{itemlag}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}

\PYG{n}{subjectinfo} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{N2}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cond1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of condition}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(1)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cond2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of condition\PYGZus{}dtemo}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(2)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cond3} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of condition\PYGZus{}ddisp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(3)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{c}{\# non-famous \textgreater{} famous}
\PYG{n}{fam1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Fame}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(1)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fam2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Fame\PYGZus{}dtemp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(2)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fam3} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Fame\PYGZus{}ddisp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(3)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{c}{\# rep1 \textgreater{} rep2}
\PYG{n}{rep1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Rep}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(1)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{rep2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Rep\PYGZus{}dtemp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(2)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{rep3} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive effect of Rep\PYGZus{}ddisp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(3)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{int1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive interaction of Fame x Rep}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(1)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(1)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{int2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive interaction of Fame x Rep\PYGZus{}dtemp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(2)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(2)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{int3} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{positive interaction of Fame x Rep\PYGZus{}ddisp}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{N2*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F1*bf(3)}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F2*bf(3)}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{contf1} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{average effect condition}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{cond1}\PYG{p}{,} \PYG{n}{cond2}\PYG{p}{,} \PYG{n}{cond3}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contf2} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{main effect Fam}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{fam1}\PYG{p}{,} \PYG{n}{fam2}\PYG{p}{,} \PYG{n}{fam3}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contf3} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{main effect Rep}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{rep1}\PYG{p}{,} \PYG{n}{rep2}\PYG{p}{,} \PYG{n}{rep3}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contf4} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{interaction: Fam x Rep}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{int1}\PYG{p}{,} \PYG{n}{int2}\PYG{p}{,} \PYG{n}{int3}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cond1}\PYG{p}{,} \PYG{n}{cond2}\PYG{p}{,} \PYG{n}{cond3}\PYG{p}{,} \PYG{n}{fam1}\PYG{p}{,} \PYG{n}{fam2}\PYG{p}{,} \PYG{n}{fam3}\PYG{p}{,} \PYG{n}{rep1}\PYG{p}{,} \PYG{n}{rep2}\PYG{p}{,} \PYG{n}{rep3}\PYG{p}{,} \PYG{n}{int1}\PYG{p}{,} \PYG{n}{int2}\PYG{p}{,} \PYG{n}{int3}\PYG{p}{,} \PYG{n}{contf1}\PYG{p}{,} \PYG{n}{contf2}\PYG{p}{,}\PYG{n}{contf3}\PYG{p}{,}\PYG{n}{contf4}\PYG{p}{]}
\end{Verbatim}

Setting up nodes inputs

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{num\PYGZus{}slices} \PYG{o}{=} \PYG{l+m+mi}{24}
\PYG{n}{TR} \PYG{o}{=} \PYG{l+m+mf}{2.}

\PYG{n}{slice\PYGZus{}timingref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{slice\PYGZus{}timing}
\PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{num\PYGZus{}slices} \PYG{o}{=} \PYG{n}{num\PYGZus{}slices}
\PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{time\PYGZus{}acquisition} \PYG{o}{=} \PYG{n}{TR} \PYG{o}{-} \PYG{n}{TR}\PYG{o}{/}\PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{num\PYGZus{}slices}\PYG{p}{)}
\PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{slice\PYGZus{}order} \PYG{o}{=} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{num\PYGZus{}slices}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{ref\PYGZus{}slice} \PYG{o}{=} \PYG{n}{num\PYGZus{}slices}\PYG{o}{/}\PYG{l+m+mi}{2}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{8}\PYG{p}{,} \PYG{l+m+mi}{8}\PYG{p}{,} \PYG{l+m+mi}{8}\PYG{p}{]}

\PYG{c}{\# set up node specific inputs}
\PYG{n}{modelspecref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{modelspec}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{scans}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{scans}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{n}{TR}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}

\PYG{n}{l1designref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{level1design}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{microtime\PYGZus{}resolution} \PYG{o}{=} \PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{num\PYGZus{}slices}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{microtime\PYGZus{}onset} \PYG{o}{=} \PYG{n}{slice\PYGZus{}timingref}\PYG{o}{.}\PYG{n}{ref\PYGZus{}slice}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

The following lines automatically inform SPM to create a default set of
contrats for a factorial design.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\#l1designref.factor\PYGZus{}info = [dict(name = 'Fame', levels = 2),}
\PYG{c}{\#                           dict(name = 'Rep', levels = 2)]}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{subjectinfo}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{threshold}\PYG{o}{.}\PYG{n}{contrast\PYGZus{}index} \PYG{o}{=} \PYG{l+m+mi}{1}
\end{Verbatim}

Use derivative estimates in the non-parametric model

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{use\PYGZus{}derivs} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Setting up parametricvariation of the model

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{subjectinfo\PYGZus{}param} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{N1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{N2}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,} \PYG{n}{sot}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{p}{[}\PYG{n+nb+bp}{None}\PYG{p}{,}
                                  \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Lag}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                        \PYG{n}{param}\PYG{o}{=}\PYG{n}{itemlag}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{tolist}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{n}{poly}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                                  \PYG{n+nb+bp}{None}\PYG{p}{,}
                                  \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Lag}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                        \PYG{n}{param}\PYG{o}{=}\PYG{n}{itemlag}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{o}{.}\PYG{n}{tolist}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{n}{poly}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{]}

\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Famous\PYGZus{}lag1}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{F2xLag\PYGZca{}1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Famous\PYGZus{}lag2}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{F2xLag\PYGZca{}2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fcont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Famous Lag}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{F}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,} \PYG{n}{cont2}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{paramcontrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,} \PYG{n}{cont2}\PYG{p}{,} \PYG{n}{fcont1}\PYG{p}{]}

\PYG{n}{paramanalysis} \PYG{o}{=} \PYG{n}{l1analysis}\PYG{o}{.}\PYG{n}{clone}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{paramanalysis}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{paramanalysis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{n}{paramanalysis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{subjectinfo\PYGZus{}param}
\PYG{n}{paramanalysis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{paramcontrasts}
\PYG{n}{paramanalysis}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{use\PYGZus{}derivs} \PYG{o}{=} \PYG{n+nb+bp}{False}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{paramanalysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                            \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{makelist}\PYG{p}{)}\PYG{p}{,}
                                                \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setup the pipeline}
\label{users/examples/spm_face_tutorial:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Pipeline} to create a
graph-based execution pipeline for first level analysis. The config
options tells the pipeline engine to use \emph{workdir} as the disk
location to use when running the processes and keeping their
outputs. The \emph{use\_parameterized\_dirs} tells the engine to create
sub-directories under \emph{workdir} corresponding to the iterables in the
pipeline. Thus for this pipeline there will be subject specific
sub-directories.

The \code{nipype.pipeline.engine.Pipeline.connect} function creates the
links between the processes, i.e., how data should flow in and out of
the processing nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}face\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.coregister.source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.realign.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Setup storage results}
\label{users/examples/spm_face_tutorial:setup-storage-results}
Use \code{nipype.interfaces.io.DataSink} to store selected outputs
from the pipeline in a specific location. This allows the user to
selectively choose important output bits from the analysis and keep
them.

The first step is to create a datasink node and then to connect
outputs from the modules above to storage locations. These take the
following form directory\_name{[}.{[}@{]}subdir{]} where parts between {[}{]} are
optional. For example `realign.@mean' below creates a directory called
realign in `l1output/subject\_id/' and stores the mean image output
from the Realign process in the realign directory. If the @ is left
out, then a sub-directory with the name `mean' would be created and
the mean image would be copied to that directory.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}tutorial/l1output}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{os}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}auditory\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}

\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{l1pipeline}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@con}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@T}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{paramanalysis.contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{paramcontrasts.@con}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{paramanalysis.contrastestimate.spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{paramcontrasts.@T}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\subparagraph{Execute the pipeline}
\label{users/examples/spm_face_tutorial:execute-the-pipeline}
The code discussed above sets up all the necessary data structures
with appropriate parameters and the connectivity between the
processes, but does not generate any output. To actually run the
analysis on the data the \code{nipype.pipeline.engine.Pipeline.Run}
function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/spm\_face\_tutorial.py}).




\subsubsection{Using SPM for analysis}
\label{users/examples/spm_tutorial:using-spm-for-analysis}\label{users/examples/spm_tutorial:example-spm-tutorial}\label{users/examples/spm_tutorial::doc}
The spm\_tutorial.py integrates several interfaces to perform a first
and second level analysis on a two-subject data set.  The tutorial can
be found in the examples folder.  Run the tutorial from inside the
nipype tutorial directory:
\begin{quote}

python spm\_tutorial.py
\end{quote}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}      \PYG{c}{\# artifact detection}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model specification}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}


\paragraph{Preliminaries}
\label{users/examples/spm_tutorial:preliminaries}
Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set any package specific configuration. The output file format
for FSL routines is being set to uncompressed NIFTI and a specific
version of matlab is being used. The uncompressed format is required
because SPM does not handle compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Tell fsl to generate all output in uncompressed nifti format}
\PYG{c}{\#print fsl.Info.version()}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}

\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{s1} and \code{s2}.  Each subject directory
contains four functional volumes: f3.nii, f5.nii, f7.nii, f10.nii. And
one anatomical volume named struct.nii.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

In the example below, run `f3' is of type `func' and gets mapped to a
nifti filename through a template `\%s.nii'. So `f3' would become
`f3.nii'.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data.}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s3}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f7}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f10}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}


\paragraph{Preprocessing pipeline nodes}
\label{users/examples/spm_tutorial:preprocessing-pipeline-nodes}
Now we create a \code{nipype.interfaces.io.DataSource} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.algorithms.rapidart} to determine which of the
images in the functional series are outliers based on deviations in
intensity or movement.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{art} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{art}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences}      \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{True}\PYG{p}{,}\PYG{n+nb+bp}{True}\PYG{p}{]}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}norm}             \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold}       \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask\PYGZus{}type}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameter\PYGZus{}source}     \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM}\PYG{l+s}{'}
\end{Verbatim}

Skull strip structural images using
\code{nipype.interfaces.fsl.BET}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{skullstrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{skullstrip}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{skullstrip}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Coregister} to perform a rigid
body registration of the functional data to the structural data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{coregister}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}
\end{Verbatim}

Warp functional and structural data to SPM's T1 template using
\code{nipype.interfaces.spm.Normalize}.  The tutorial data set
includes the template image, T1.nii.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normalize} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/T1.nii}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Smooth the functional data using
\code{nipype.interfaces.spm.Smooth}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fwhmlist} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{4}\PYG{p}{]}
\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{fwhmlist}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up analysis components}
\label{users/examples/spm_tutorial:set-up-analysis-components}
Here we create a function that returns subject-specific information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix. In this tutorial, the same
paradigm was used for every participant.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{subjectinfo}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
    \PYG{k+kn}{from} \PYG{n+nn}{copy} \PYG{k+kn}{import} \PYG{n}{deepcopy}
    \PYG{k}{print} \PYG{l+s}{"}\PYG{l+s}{Subject ID: }\PYG{l+s+si}{\%s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
    \PYG{n}{output} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{n}{names} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{onsets} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{15}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{45}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{]}
        \PYG{n}{output}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{r}\PYG{p}{,}
                      \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{names}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{n}{deepcopy}\PYG{p}{(}\PYG{n}{onsets}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{]} \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{names}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{output}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}
\end{Verbatim}

Generate SPM-specific design information using
\code{nipype.interfaces.spm.SpecifyModel}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenate\PYGZus{}runs}        \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}
\end{Verbatim}

Generate a first level SPM.mat file for analysis
\code{nipype.interfaces.spm.Level1Design}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases}              \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateModel} to determine the
parameters of the model.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateContrast} to estimate the
first level contrasts specified in a few steps above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrastestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrastestimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\end{Verbatim}


\paragraph{Setup the pipeline}
\label{users/examples/spm_tutorial:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Pipeline} to create a
graph-based execution pipeline for first level analysis. The config
options tells the pipeline engine to use \emph{workdir} as the disk
location to use when running the processes and keeping their
outputs. The \emph{use\_parameterized\_dirs} tells the engine to create
sub-directories under \emph{workdir} corresponding to the iterables in the
pipeline. Thus for this pipeline there will be subject specific
sub-directories.

The \code{nipype.pipeline.engine.Pipeline.connect} function creates the
links between the processes, i.e., how data should flow in and out of
the processing nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{realign}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{target}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{normalize}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{normalize}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjectinfo}\PYG{p}{)}\PYG{p}{,}
                                          \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{smooth}\PYG{p}{,}\PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,}\PYG{n}{skullstrip}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}source}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{skullstrip}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{art}\PYG{p}{,}\PYG{n}{modelspec}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{skullstrip}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup storage results}
\label{users/examples/spm_tutorial:setup-storage-results}
Use \code{nipype.interfaces.io.DataSink} to store selected outputs
from the pipeline in a specific location. This allows the user to
selectively choose important output bits from the analysis and keep
them.

The first step is to create a datasink node and then to connect
outputs from the modules above to storage locations. These take the
following form directory\_name{[}.{[}@{]}subdir{]} where parts between {[}{]} are
optional. For example `realign.@mean' below creates a directory called
realign in `l1output/subject\_id/' and stores the mean image output
from the Realign process in the realign directory. If the @ is left
out, then a sub-directory with the name `mean' would be created and
the mean image would be copied to that directory.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial/l1output}\PYG{l+s}{'}\PYG{p}{)}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{os}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial/workingdir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}

\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                          \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realign.@mean}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realign.@param}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{art}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{art.@outliers}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                   \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{statistic\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{art.@stats}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.pre-estimate}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.@spm}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.@beta}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.@mask}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.@res}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                              \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{RPVimage}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{model.@rpv}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{(}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@con}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@T}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup level 2 pipeline}
\label{users/examples/spm_tutorial:setup-level-2-pipeline}
Use \code{nipype.interfaces.io.DataGrabber} to extract the contrast
images across a group of first level subjects. Unlike the previous
pipeline that iterated over subjects, this pipeline will iterate over
contrasts.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# collect all the con images for each contrast.}
\PYG{n}{contrast\PYGZus{}ids} \PYG{o}{=} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{contrasts}\PYG{p}{)}\PYG{o}{+}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{l2source} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{l2source}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial/l1output/*/con*/*/\PYGZus{}fwhm\PYGZus{}}\PYG{l+s+si}{\%d}\PYG{l+s}{/con\PYGZus{}}\PYG{l+s+si}{\%04d}\PYG{l+s}{.img}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# iterate over all contrast images}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{fwhmlist}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{contrast\PYGZus{}ids}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Use \code{nipype.interfaces.spm.OneSampleTTest} to perform a
simple statistical analysis of the contrasts from the group of
subjects (n=2 in this example).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# setup a 1-sample t-test node}
\PYG{n}{onesamplettest} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{OneSampleTTest}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{onesamplettest}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

As before, we setup a pipeline to connect these two nodes (l2source
-\textgreater{} onesamplettest).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level2}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial/l2output}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{l2source}\PYG{p}{,}\PYG{n}{onesamplettest}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outfiles}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Execute the pipeline}
\label{users/examples/spm_tutorial:execute-the-pipeline}
The code discussed above sets up all the necessary data structures
with appropriate parameters and the connectivity between the
processes, but does not generate any output. To actually run the
analysis on the data the \code{nipype.pipeline.engine.Pipeline.Run}
function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{c}{\#    l2pipeline.run()}
\PYG{c}{\#    l1pipeline.write\PYGZus{}graph()}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/spm\_tutorial.py}).




\subsubsection{Using SPM for analysis: Hierarchical}
\label{users/examples/spm_tutorial2::doc}\label{users/examples/spm_tutorial2:example-spm-tutorial2}\label{users/examples/spm_tutorial2:using-spm-for-analysis-hierarchical}
The spm\_tutorial.py integrates several interfaces to perform a first
and second level analysis on a two-subject data set.  The tutorial can
be found in the examples folder.  Run the tutorial from inside the
nipype tutorial directory:
\begin{quote}

python spm\_tutorial.py
\end{quote}

Import necessary modules from nipype.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{as} \PYG{n+nn}{nio}           \PYG{c}{\# Data i/o}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}          \PYG{c}{\# spm}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{as} \PYG{n+nn}{mlab}      \PYG{c}{\# how to run matlab}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}          \PYG{c}{\# fsl}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{as} \PYG{n+nn}{util}     \PYG{c}{\# utility}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.pipeline.engine} \PYG{k+kn}{as} \PYG{n+nn}{pe}          \PYG{c}{\# pypeline engine}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.rapidart} \PYG{k+kn}{as} \PYG{n+nn}{ra}      \PYG{c}{\# artifact detection}
\PYG{k+kn}{import} \PYG{n+nn}{nipype.algorithms.modelgen} \PYG{k+kn}{as} \PYG{n+nn}{model}   \PYG{c}{\# model specification}
\PYG{k+kn}{import} \PYG{n+nn}{os}                                    \PYG{c}{\# system functions}
\end{Verbatim}


\paragraph{Preliminaries}
\label{users/examples/spm_tutorial2:preliminaries}
Confirm package dependencies are installed.  (This is only for the
tutorial, rarely would you put this in your own code.)

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.misc} \PYG{k+kn}{import} \PYG{n}{package\PYGZus{}check}

\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{numpy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.3}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{scipy}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.7}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{networkx}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{1.0}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{package\PYGZus{}check}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{0.10}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{tutorial1}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Set any package specific configuration. The output file format
for FSL routines is being set to uncompressed NIFTI and a specific
version of matlab is being used. The uncompressed format is required
because SPM does not handle compressed NIFTI.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Tell fsl to generate all output in uncompressed nifti format}
\PYG{k}{print} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Info}\PYG{o}{.}\PYG{n}{version}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FSLCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}output\PYGZus{}type}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{NIFTI}\PYG{l+s}{'}\PYG{p}{)}

\PYG{c}{\# Set the way matlab should be called}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}matlab\PYGZus{}cmd}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{matlab -nodesktop -nosplash}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{mlab}\PYG{o}{.}\PYG{n}{MatlabCommand}\PYG{o}{.}\PYG{n}{set\PYGZus{}default\PYGZus{}paths}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/software/spm8}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setting up workflows}
\label{users/examples/spm_tutorial2:setting-up-workflows}
In this tutorial we will be setting up a hierarchical workflow for spm
analysis. This will demonstrate how pre-defined workflows can be setup
and shared across users, projects and labs.


\paragraph{Setup preprocessing workflow}
\label{users/examples/spm_tutorial2:setup-preprocessing-workflow}
This is a generic preprocessing workflow that can be used by different analyses

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{preproc}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Realign} for motion correction
and register all images to the mean image.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{realign} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{realign}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.algorithms.rapidart} to determine which of the
images in the functional series are outliers based on deviations in
intensity or movement.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{art} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{ra}\PYG{o}{.}\PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{art}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences}      \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{True}\PYG{p}{,}\PYG{n+nb+bp}{True}\PYG{p}{]}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}norm}             \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold}       \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask\PYGZus{}type}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{file}\PYG{l+s}{'}
\PYG{n}{art}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameter\PYGZus{}source}     \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM}\PYG{l+s}{'}
\end{Verbatim}

Skull strip structural images using
\code{nipype.interfaces.fsl.BET}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{skullstrip} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{skullstrip}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{skullstrip}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.interfaces.spm.Coregister} to perform a rigid
body registration of the functional data to the structural data.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{coregister} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{coregister}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{coregister}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}
\end{Verbatim}

Warp functional and structural data to SPM's T1 template using
\code{nipype.interfaces.spm.Normalize}.  The tutorial data set
includes the template image, T1.nii.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{normalize} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{normalize}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{normalize}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data/T1.nii}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Smooth the functional data using
\code{nipype.interfaces.spm.Smooth}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{smooth}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{fwhmlist} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{4}\PYG{p}{]}
\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{fwhmlist}\PYG{p}{)}

\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{coregister}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                      \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{coregister}\PYG{p}{,} \PYG{n}{normalize}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{coregistered\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{apply\PYGZus{}to\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,} \PYG{n}{smooth}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,}\PYG{n}{skullstrip}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}source}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{realign}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{normalize}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalized\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{realigned\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{(}\PYG{n}{skullstrip}\PYG{p}{,}\PYG{n}{art}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                 \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Set up analysis workflow}
\label{users/examples/spm_tutorial2:set-up-analysis-workflow}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1analysis} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{analysis}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Generate SPM-specific design information using
\code{nipype.interfaces.spm.SpecifyModel}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{modelspec} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{model}\PYG{o}{.}\PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{modelspec}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{modelspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenate\PYGZus{}runs}        \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

Generate a first level SPM.mat file for analysis
\code{nipype.interfaces.spm.Level1Design}.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{level1design}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases}              \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateModel} to determine the
parameters of the model.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}
\end{Verbatim}

Use \code{nipype.interfaces.spm.EstimateContrast} to estimate the
first level contrasts specified in a few steps above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{contrastestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{contrastestimate}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use :class: \emph{nipype.interfaces.utility.Select} to select each contrast for
reporting.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{selectcontrast} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{Select}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{selectcontrast}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Overlay} to combine the statistical output of
the contrast estimate and a background image into one volume.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{overlaystats} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Overlay}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{overlaystats}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{overlaystats}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{stat\PYGZus{}thresh} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{n}{overlaystats}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{show\PYGZus{}negative\PYGZus{}stats}\PYG{o}{=}\PYG{n+nb+bp}{True}
\PYG{n}{overlaystats}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{auto\PYGZus{}thresh\PYGZus{}bg}\PYG{o}{=}\PYG{n+nb+bp}{True}
\end{Verbatim}

Use \code{nipype.interfaces.fsl.Slicer} to create images of the overlaid
statistical volumes for a report of the first-level results.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{slicestats} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Slicer}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{slicestats}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{slicestats}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{all\PYGZus{}axial} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{slicestats}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{image\PYGZus{}width} \PYG{o}{=} \PYG{l+m+mi}{750}

\PYG{n}{l1analysis}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{modelspec}\PYG{p}{,}\PYG{n}{level1design}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1design}\PYG{p}{,}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{level1estimate}\PYG{p}{,}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                                  \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{contrastestimate}\PYG{p}{,}\PYG{n}{selectcontrast}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inlist}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{selectcontrast}\PYG{p}{,}\PYG{n}{overlaystats}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{stat\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{overlaystats}\PYG{p}{,}\PYG{n}{slicestats}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Preproc + Analysis pipeline}
\label{users/examples/spm_tutorial2:preproc-analysis-pipeline}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l1pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{firstlevel}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{preproc}\PYG{p}{,} \PYG{n}{l1analysis}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{realign.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.realignment\PYGZus{}parameters}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{smooth.smoothed\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.functional\PYGZus{}runs}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{art.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{modelspec.outlier\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{skullstrip.mask\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{level1design.mask\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                           \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{normalize.normalized\PYGZus{}source}\PYG{l+s}{'}\PYG{p}{,}
                                            \PYG{l+s}{'}\PYG{l+s}{overlaystats.background\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Data specific components}
\label{users/examples/spm_tutorial2:data-specific-components}
The nipype tutorial contains data for two subjects.  Subject data
is in two subdirectories, \code{s1} and \code{s2}.  Each subject directory
contains four functional volumes: f3.nii, f5.nii, f7.nii, f10.nii. And
one anatomical volume named struct.nii.

Below we set some variables to inform the \code{datasource} about the
layout of our data.  We specify the location of the data, the subject
sub-directories and a dictionary that maps each run to a mnemonic (or
field) for the run type (\code{struct} or \code{func}).  These fields become
the output fields of the \code{datasource} node in the pipeline.

In the example below, run `f3' is of type `func' and gets mapped to a
nifti filename through a template `\%s.nii'. So `f3' would become
`f3.nii'.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# Specify the location of the data.}
\PYG{n}{data\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{data}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# Specify the subject directories}
\PYG{n}{subject\PYGZus{}list} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{s3}\PYG{l+s}{'}\PYG{p}{]}
\PYG{c}{\# Map field names to individual subject runs.}
\PYG{n}{info} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{func}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f7}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f10}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
            \PYG{n}{struct}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{infosource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{util}\PYG{o}{.}\PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{infosource}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we set up iteration over all the subjects. The following line
is a particular example of the flexibility of the system.  The
\code{datasource} attribute \code{iterables} tells the pipeline engine that
it should repeat the analysis on each of the items in the
\code{subject\_list}. In the current example, the entire first level
preprocessing and estimation will be repeated for each subject
contained in subject\_list.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{infosource}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subject\PYGZus{}list}\PYG{p}{)}
\end{Verbatim}

Now we create a \code{nipype.interfaces.io.DataGrabber} object and
fill in the information from above about the layout of our data.  The
\code{nipype.pipeline.NodeWrapper} module wraps the interface object
and provides additional housekeeping and pipeline specific
functionality.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasource} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}
                                               \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                     \PYG{n}{name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{datasource}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{data\PYGZus{}dir}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{n}{datasource}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}


\paragraph{Experimental paradigm specific components}
\label{users/examples/spm_tutorial2:experimental-paradigm-specific-components}
Here we create a function that returns subject-specific information
about the experimental paradigm. This is used by the
\code{nipype.interfaces.spm.SpecifyModel} to create the information
necessary to generate an SPM design matrix. In this tutorial, the same
paradigm was used for every participant.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{subjectinfo}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
    \PYG{k+kn}{from} \PYG{n+nn}{copy} \PYG{k+kn}{import} \PYG{n}{deepcopy}
    \PYG{k}{print} \PYG{l+s}{"}\PYG{l+s}{Subject ID: }\PYG{l+s+si}{\%s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{"}\PYG{o}{\%}\PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}
    \PYG{n}{output} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
    \PYG{n}{names} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}
    \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{onsets} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{15}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,}\PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{45}\PYG{p}{,}\PYG{l+m+mi}{240}\PYG{p}{,}\PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{]}
        \PYG{n}{output}\PYG{o}{.}\PYG{n}{insert}\PYG{p}{(}\PYG{n}{r}\PYG{p}{,}
                      \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{names}\PYG{p}{,}
                            \PYG{n}{onsets}\PYG{o}{=}\PYG{n}{deepcopy}\PYG{p}{(}\PYG{n}{onsets}\PYG{p}{)}\PYG{p}{,}
                            \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{]} \PYG{k}{for} \PYG{n}{s} \PYG{o+ow}{in} \PYG{n}{names}\PYG{p}{]}\PYG{p}{,}
                            \PYG{n}{amplitudes}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{tmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{pmod}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressor\PYGZus{}names}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
                            \PYG{n}{regressors}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{)}
    \PYG{k}{return} \PYG{n}{output}
\end{Verbatim}

Setup the contrast structure that needs to be evaluated. This is a
list of lists. The inner list specifies the contrasts and has the
following format - {[}Name,Stat,{[}list of condition names{]},{[}weights on
those conditions{]}. The condition names must match the \emph{names} listed
in the \emph{subjectinfo} function described above.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}

\PYG{c}{\# set up node specific inputs}
\PYG{n}{modelspecref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{modelspec}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{input\PYGZus{}units}             \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}            \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}         \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mi}{120}

\PYG{n}{l1designref} \PYG{o}{=} \PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{level1design}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units}       \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{output\PYGZus{}units}
\PYG{n}{l1designref}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{n}{modelspecref}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition}


\PYG{n}{l1pipeline}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{analysis}\PYG{o}{.}\PYG{n}{contrastestimate}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}


\PYG{c}{\# Iterate over each contrast and create report images.}
\PYG{n}{selectcontrast}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{index}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{[}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]} \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{contrasts}\PYG{p}{)}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup the pipeline}
\label{users/examples/spm_tutorial2:setup-the-pipeline}
The nodes created above do not describe the flow of data. They merely
describe the parameters used for each function. In this section we
setup the connections between the nodes such that appropriate outputs
from nodes are piped into appropriate inputs of other nodes.

Use the \code{nipype.pipeline.engine.Pipeline} to create a
graph-based execution pipeline for first level analysis. The config
options tells the pipeline engine to use \emph{workdir} as the disk
location to use when running the processes and keeping their
outputs. The \emph{use\_parameterized\_dirs} tells the engine to create
sub-directories under \emph{workdir} corresponding to the iterables in the
pipeline. Thus for this pipeline there will be subject specific
sub-directories.

The \code{nipype.pipeline.engine.Pipeline.connect} function creates the
links between the processes, i.e., how data should flow in and out of
the processing nodes.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{level1} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level1}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/workingdir}\PYG{l+s}{'}\PYG{p}{)}

\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasource}\PYG{p}{,} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{datasource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{preproc.realign.in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.coregister.target}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                        \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{preproc.normalize.source}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,}\PYG{n}{l1pipeline}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{subjectinfo}\PYG{p}{)}\PYG{p}{,}
                                          \PYG{l+s}{'}\PYG{l+s}{analysis.modelspec.subject\PYGZus{}info}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup storage results}
\label{users/examples/spm_tutorial2:setup-storage-results}
Use \code{nipype.interfaces.io.DataSink} to store selected outputs
from the pipeline in a specific location. This allows the user to
selectively choose important output bits from the analysis and keep
them.

The first step is to create a datasink node and then to connect
outputs from the modules above to storage locations. These take the
following form directory\_name{[}.{[}@{]}subdir{]} where parts between {[}{]} are
optional. For example `realign.@mean' below creates a directory called
realign in `l1output/subject\_id/' and stores the mean image output
from the Realign process in the realign directory. If the @ is left
out, then a sub-directory with the name `mean' would be created and
the mean image would be copied to that directory.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{datasink} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{datasink}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{datasink}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/l1output}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{report} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{report}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{report}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/report}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{report}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameterization} \PYG{o}{=} \PYG{n+nb+bp}{False}

\PYG{k}{def} \PYG{n+nf}{getstripdir}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{p}{)}\PYG{p}{:}
    \PYG{k+kn}{import} \PYG{n+nn}{os}
    \PYG{k}{return} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/workingdir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{\PYGZus{}subject\PYGZus{}id\PYGZus{}}\PYG{l+s+si}{\%s}\PYG{l+s}{'} \PYG{o}{\%} \PYG{n}{subject\PYGZus{}id}\PYG{p}{)}

\PYG{c}{\# store relevant outputs from various stages of the 1st level analysis}
\PYG{n}{level1}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{l1pipeline}\PYG{p}{,} \PYG{n}{datasink}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.con\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@con}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                       \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.contrastestimate.spmT\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{contrasts.@T}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{infosource}\PYG{p}{,} \PYG{n}{report}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{container}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                     \PYG{p}{(}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}id}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{getstripdir}\PYG{p}{)}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{strip\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{(}\PYG{n}{l1pipeline}\PYG{p}{,} \PYG{n}{report}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{analysis.slicestats.out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{@report}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Execute the pipeline}
\label{users/examples/spm_tutorial2:execute-the-pipeline}
The code discussed above sets up all the necessary data structures
with appropriate parameters and the connectivity between the
processes, but does not generate any output. To actually run the
analysis on the data the \code{nipype.pipeline.engine.Pipeline.Run}
function needs to be called.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
    \PYG{n}{level1}\PYG{o}{.}\PYG{n}{write\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\paragraph{Setup level 2 pipeline}
\label{users/examples/spm_tutorial2:setup-level-2-pipeline}
Use \code{nipype.interfaces.io.DataGrabber} to extract the contrast
images across a group of first level subjects. Unlike the previous
pipeline that iterated over subjects, this pipeline will iterate over
contrasts.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# collect all the con images for each contrast.}
\PYG{n}{contrast\PYGZus{}ids} \PYG{o}{=} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{contrasts}\PYG{p}{)}\PYG{o}{+}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{l2source} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{nio}\PYG{o}{.}\PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{l2source}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/l1output/*/con*/*/\PYGZus{}fwhm\PYGZus{}}\PYG{l+s+si}{\%d}\PYG{l+s}{/con\PYGZus{}}\PYG{l+s+si}{\%04d}\PYG{l+s}{.img}\PYG{l+s}{'}\PYG{p}{)}
\PYG{c}{\# iterate over all contrast images}
\PYG{n}{l2source}\PYG{o}{.}\PYG{n}{iterables} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{fwhm}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{fwhmlist}\PYG{p}{)}\PYG{p}{,}
                      \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{con}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{contrast\PYGZus{}ids}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Use \code{nipype.interfaces.spm.OneSampleTTest} to perform a
simple statistical analysis of the contrasts from the group of
subjects (n=2 in this example).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c}{\# setup a 1-sample t-test node}
\PYG{n}{onesamplettestdes} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{OneSampleTTestDesign}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{onesampttestdes}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2estimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface}\PYG{o}{=}\PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level2estimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2estimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{estimation\PYGZus{}method} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{Classical}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{\PYGZcb{}}
\PYG{n}{l2conestimate} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Node}\PYG{p}{(}\PYG{n}{interface} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level2conestimate}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Group}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{mean}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{l2conestimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{]}
\PYG{n}{l2conestimate}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{group\PYGZus{}contrast} \PYG{o}{=} \PYG{n+nb+bp}{True}
\end{Verbatim}

As before, we setup a pipeline to connect these two nodes (l2source
-\textgreater{} onesamplettest).

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{l2pipeline} \PYG{o}{=} \PYG{n}{pe}\PYG{o}{.}\PYG{n}{Workflow}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{level2}\PYG{l+s}{"}\PYG{p}{)}
\PYG{n}{l2pipeline}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}tutorial2/l2output}\PYG{l+s}{'}\PYG{p}{)}
\PYG{n}{l2pipeline}\PYG{o}{.}\PYG{n}{connect}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{l2source}\PYG{p}{,}\PYG{n}{onesamplettestdes}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outfiles}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}files}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{onesamplettestdes}\PYG{p}{,}\PYG{n}{l2estimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                  \PYG{p}{(}\PYG{n}{l2estimate}\PYG{p}{,}\PYG{n}{l2conestimate}\PYG{p}{,}\PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{spm\PYGZus{}mat\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{beta\PYGZus{}images}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}
                                             \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{residual\PYGZus{}image}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
                    \PYG{p}{]}\PYG{p}{)}
\end{Verbatim}


\paragraph{Execute the second level pipeline}
\label{users/examples/spm_tutorial2:execute-the-second-level-pipeline}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}
    \PYG{n}{l2pipeline}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\strong{See Also:}


The full source code of this example is included in the Nipype source distribution (\emph{../examples/spm\_tutorial2.py}).




\subsection{Requirements}
\label{users/pipeline_tutorial:requirements}\begin{quote}

All tutorials
\begin{itemize}
\item {} 
Release 0.3 of nipype and it's dependencies have been installed

\end{itemize}

Analysis tutorials
\begin{itemize}
\item {} 
\href{http://www.fmrib.ox.ac.uk/fsl}{FSL}, \href{http://surfer.nmr.mgh.harvard.edu}{FreeSurfer} and \href{http://www.mathworks.com}{MATLAB} are available and callable from the command line

\item {} 
\href{http://www.fil.ion.ucl.ac.uk/spm}{SPM} 5/8 is installed and callable in matlab

\item {} 
4(? XX) GB of space

\end{itemize}
\end{quote}


\subsection{Checklist for analysis tutorials}
\label{users/pipeline_tutorial:checklist-for-analysis-tutorials}
For the analysis tutorials, we will be using a slightly modified version of the
FBIRN Phase I travelling data set.


\subsubsection{Step 0}
\label{users/pipeline_tutorial:step-0}
Download and extract the \href{http://cirl.berkeley.edu/nipy/nipype-tutorial-0.2.tar.gz}{Pipeline tutorial data (429MB).}

(checksum: f91b81050e1262f0508d35135c2369f5)


\subsubsection{Step 1.}
\label{users/pipeline_tutorial:step-1}
Ensure that all programs are available by calling \code{bet}, \code{matlab}
and then \code{which spm} within matlab to ensure you have spm5/8 in your
matlab path.


\subsubsection{Step 2.}
\label{users/pipeline_tutorial:step-2}
You can now run the tutorial by typing \code{python tutorial\_script.py}
within the nipype-tutorial directory. This will run a full first level
analysis on two subjects following by a 1-sample t-test on their first
level results. The next section goes through each section of the
tutorial script and describes what it is doing.


\section{Model Specification for First Level fMRI Analysis}
\label{users/model_specification:model-specification-for-first-level-fmri-analysis}\label{users/model_specification:model-spec}\label{users/model_specification::doc}\label{users/model_specification:wikipedia-pca}
NiPyPE provides a general purpose model specification mechanism with
specialized subclasses for package specific extensions.


\subsection{General purpose model specification}
\label{users/model_specification:general-purpose-model-specification}
The \code{SpecifyModel} provides a generic mechanism for model
specification. A mandatory input called subject\_info provides paradigm
specification for each run corresponding to a subject. This has to be in
the form of a \code{Bunch} or a list of Bunch objects (one for each
run). Each Bunch object contains the following attribules.


\subsubsection{Required for most designs}
\label{users/model_specification:required-for-most-designs}\begin{itemize}
\item {} 
conditions : list of names

\item {} 
onsets : lists of onsets corresponding to each condition

\item {} \begin{description}
\item[{durations}] \leavevmode{[}lists of durations corresponding to each condition. Should be{]}
left to a single 0 if all events are being modelled as impulses.

\end{description}

\end{itemize}


\subsubsection{Optional}
\label{users/model_specification:optional}\begin{itemize}
\item {} \begin{description}
\item[{regressors}] \leavevmode{[}list of dicts specifying additional regressors for each run{]}\begin{itemize}
\item {} \begin{description}
\item[{names}] \leavevmode{[}list of names corresponding to each column. Should be None if{]}
automatically assigned.

\end{description}

\item {} 
values : lists of values for each regressors

\end{itemize}

\end{description}

\item {} \begin{description}
\item[{amplitudes}] \leavevmode{[}lists of amplitudes for each event. This will be ignored by{]}
SPM's Level1Design.

\end{description}

\end{itemize}

The following two (tmod, pmod) will be ignored by any
Level1Design class other than SPM:
\begin{itemize}
\item {} \begin{description}
\item[{tmod}] \leavevmode{[}lists of conditions that should be temporally modulated. Should{]}
default to None if not being used.

\end{description}

\item {} \begin{description}
\item[{pmod}] \leavevmode{[}list of Bunch corresponding to conditions{]}\begin{itemize}
\item {} 
name : name of parametric modulator

\item {} 
param : values of the modulator

\item {} 
poly : degree of modulation

\end{itemize}

\end{description}

\end{itemize}

An example Bunch definition:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\PYG{n}{condnames} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Tapping}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{Speaking}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{Yawning}\PYG{l+s}{'}\PYG{p}{]}
\PYG{n}{event\PYGZus{}onsets} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{,} \PYG{l+m+mi}{60}\PYG{p}{,} \PYG{l+m+mi}{80}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{30}\PYG{p}{,} \PYG{l+m+mi}{40}\PYG{p}{,} \PYG{l+m+mi}{70}\PYG{p}{]}\PYG{p}{]}
\PYG{n}{durations} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}

\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{condnames}\PYG{p}{,}
                                   \PYG{n}{onsets} \PYG{o}{=} \PYG{n}{event\PYGZus{}onsets}\PYG{p}{,}
                                   \PYG{n}{durations} \PYG{o}{=} \PYG{n}{durations}\PYG{p}{)}
\end{Verbatim}

Alternatively, you can provide condition, onset, duration and amplitude
information through event files. The event files have to be in 1,2 or 3
column format with the columns corresponding to Onsets, Durations and
Amplitudes and they have to have the name event\_name.run\textless{}anything else\textgreater{}
e.g.: Words.run001.txt. The event\_name part will be used to create the
condition names. Words.run001.txt may look like:

\begin{Verbatim}[commandchars=@\[\]]
@# Word Onsets Durations
 0   10
 20   10
 ...
\end{Verbatim}

or with amplitudes:

\begin{Verbatim}[commandchars=@\[\]]
@# Word Onsets Durations Amplitudes
0    10     1
20   10    1
...
\end{Verbatim}

Together with this information, one needs to specify:
\begin{itemize}
\item {} 
whether the durations and event onsets are specified in terms of scan volumes or

\end{itemize}

secs.
\begin{itemize}
\item {} 
the high-pass filter cutoff,

\item {} 
the repetition time per scan

\item {} 
functional data files corresponding to each run.

\end{itemize}

Optionally you can specify realignment parameters, outlier indices.
Outlier files should contain a list of numbers, one per row indicating
which scans should not be included in the analysis. The numbers are
0-based.


\subsection{SPM specific attributes}
\label{users/model_specification:spm-specific-attributes}
in addition to the generic specification options, several SPM specific
options can be provided. In particular, the subject\_info function can
provide temporal and parametric modulators in the Bunch attributes tmod
and pmod. The following example adds a linear parametric modulator for
speaking rate for the events specified earlier:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{pmod} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Rate}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{param}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{o}{.}\PYG{l+m+mi}{300}\PYG{p}{,} \PYG{o}{.}\PYG{l+m+mi}{500}\PYG{p}{,} \PYG{o}{.}\PYG{l+m+mi}{600}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
                                     \PYG{n}{poly}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{]}
\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{n}{condnames}\PYG{p}{,}
                                    \PYG{n}{onsets} \PYG{o}{=} \PYG{n}{event\PYGZus{}onsets}\PYG{p}{,}
                                    \PYG{n}{durations} \PYG{o}{=} \PYG{n}{durations}\PYG{p}{,}
                                    \PYG{n}{pmod} \PYG{o}{=} \PYG{n}{pmod}\PYG{p}{)}
\end{Verbatim}

\code{SpecifySPMModel} also allows specifying additional components.
If you have a study with multiple runs, you can choose to concatenate
conditions from different runs. by setting the input
option \textbf{concatenate\_runs} to True. You can also choose to set the
output options for this class to be in terms of `scans'.


\subsection{Sparse model specification}
\label{users/model_specification:sparse-model-specification}
In addition to standard models, \code{SpecifySparseModel} allows model
generation for sparse and sparse-clustered acquisition experiments.
Details of the model generation and utility are provided in \href{http://dl.dropbox.com/u/363467/OHBM2009\_HRF.pdf}{Ghosh et
al. (2009) OHBM 2009.}


\section{Distributed processing with nipype}
\label{users/parallel_processing:parallel-processing}\label{users/parallel_processing:distributed-processing-with-nipype}\label{users/parallel_processing::doc}\label{users/parallel_processing:wikipedia-pca}
The workflow engine is designed to support plugin interfaces for
distributed processing. Current plugins are available for multiprocessing,
\href{http://ipython.scipy.org}{IPython} (0.10.1/2) distributed processing platforms and for direct
processing on SGE/OGE. We anticipate future plugins for the \href{http://brainvisa.info/soma/soma-workflow/}{Soma} workflow,
\href{http://www.clusterresources.com/products/torque-resource-manager.php}{PBS}, \href{http://www.platform.com/Products/platform-lsf}{LSF} and \href{http://www.cs.wisc.edu/condor/}{Condor}.

Parallel distributed processing relies on the availability of a shared
filesystem across computational nodes.


\subsection{Using the pipeline engine with multiprocessing}
\label{users/parallel_processing:using-the-pipeline-engine-with-multiprocessing}
To use local distributed processing on a multicore machine, simply call:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{plugin}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{MultiProc}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{plugin\PYGZus{}args}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{n\PYGZus{}procs}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{2}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\end{Verbatim}

where n\_procs defines how many processes to use in parallel. Currently, the
multiprocessing plugin dumps outputs on the command window in an interleaved
manner.


\subsection{Using the pipeline engine with IPython}
\label{users/parallel_processing:using-the-pipeline-engine-with-ipython}
The pipeline engine provides a mechanism to distribute processes across
multiple cores and machines in a cluster employing a consistent login
system and a shared file system. Currently, the login process needs to
be ssh-able via public key authentication. This document now reflects use
with \href{http://ipython.scipy.org}{IPython} 0.10.1 or higher.

Please read the \href{http://ipython.scipy.org}{IPython} documentation to determine how to setup your
cluster for distributed processing. This typically involves calling
ipcluster. For example the following command will start an eight client
cluster locally and log all client messages to the file in
/tmp/pipeline:

\begin{Verbatim}[commandchars=@\[\]]
ipcluster local -n 8 --logdir /tmp/pipeline
\end{Verbatim}

If you use a more complicated environment distributed over ssh try using the
following configuration:

\begin{Verbatim}[commandchars=@\[\]]
ipcluster ssh -e --clusterfile=clusterfile.py
\end{Verbatim}

clusterfile.py example:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{send\PYGZus{}furl} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{c}{\# define cluster configurations}
\PYG{n}{half\PYGZus{}cores} \PYG{o}{=} \PYG{p}{\PYGZob{}} \PYG{l+s}{'}\PYG{l+s}{xxx.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{4}\PYG{p}{,}
                      \PYG{l+s}{'}\PYG{l+s}{yyy.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{4}\PYG{p}{,}
                      \PYG{l+s}{'}\PYG{l+s}{zzz.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{4}\PYG{p}{\PYGZcb{}}
\PYG{n}{all\PYGZus{}cores} \PYG{o}{=} \PYG{p}{\PYGZob{}} \PYG{l+s}{'}\PYG{l+s}{xxx.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{4}\PYG{p}{,}
                   \PYG{l+s}{'}\PYG{l+s}{yyy.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{8}\PYG{p}{,}
                   \PYG{l+s}{'}\PYG{l+s}{zzz.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{8}\PYG{p}{\PYGZcb{}}
\PYG{n}{xxx\PYGZus{}only} \PYG{o}{=} \PYG{p}{\PYGZob{}} \PYG{l+s}{'}\PYG{l+s}{xxx.mit.edu}\PYG{l+s}{'} \PYG{p}{:} \PYG{l+m+mi}{4}\PYG{p}{\PYGZcb{}}
\PYG{c}{\# choose cluster configurations}
\PYG{n}{engines} \PYG{o}{=} \PYG{n}{all\PYGZus{}cores} \PYG{c}{\# this is the primary information that ipcluster needs}
\end{Verbatim}

Once the clients have been started, any pipeline executed with:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{plugin}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{IPython}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

will automatically start getting distributed to the
clients. Alternatively, a config file may be used to define the
plugin. See \emph{config\_file\_} for details.

To prevent prevent parallel execution type:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{plugin}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{Linear}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}


\subsection{Using the pipeline engine with SGE/OGE}
\label{users/parallel_processing:using-the-pipeline-engine-with-sge-oge}
In order to use nipype with SGE/OGE (not tested), you simply need to
call:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{workflow}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{plugin}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{SGE}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

you can also pass additional arguments to the SGE plugin through the
keyword argument (plugin\_args). Currentyl the SGE engine, supports
sending a dictionary containing any of the following keys:

\begin{Verbatim}[commandchars=@\[\]]
template - custom template file. by
qsub@_args - any other command line args to be passed to qsub.
\end{Verbatim}

For example, the following snippet executes the workflow on myqueue with
a custom template:
\begin{quote}
\begin{description}
\item[{workflow.run(plugin='SGE',}] \leavevmode
plugin\_args=dict(template='mytemplate.sh', qsub\_args='-q myqueue')

\end{description}
\end{quote}


\chapter{Interfaces and Algorithms}
\label{interfaces/index:condor}\label{interfaces/index::doc}\label{interfaces/index:interface-index}\label{interfaces/index:interfaces-and-algorithms}\begin{quote}\begin{description}
\item[{Release}] \leavevmode
0.4.dev

\item[{Date}] \leavevmode
April 15, 2011, 14:40 PDT

\end{description}\end{quote}


\section{nipype.algorithms.misc}
\label{interfaces/generated/nipype.algorithms.misc::doc}\label{interfaces/generated/nipype.algorithms.misc:nipype-algorithms-misc}

\subsection{\texttt{CreateNifti}}
\label{interfaces/generated/nipype.algorithms.misc:createnifti}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
data@_file : (an existing file name)
        ANALYZE img file
header@_file : (an existing file name)
        corresponding ANALYZE hdr file

@PYGZlb[]Optional@PYGZrb[]
affine : (an array)
        affine transformation array
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
nifti@_file : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{Dissimilarity}}
\label{interfaces/generated/nipype.algorithms.misc:dissimilarity}
Calculates dissimilarity between two maps.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
volume1 : (an existing file name)
        Has to have the same dimensions as volume2.
volume2 : (an existing file name)
        Has to have the same dimensions as volume1.

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
method : ('dice' or 'jaccard')
        "dice": Dice's dissimilarity,    "jaccard": Jaccards's dissimilarity
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dissimilarity : (a float)
        Unknown
\end{Verbatim}


\subsection{\texttt{Distance}}
\label{interfaces/generated/nipype.algorithms.misc:distance}
Calculates distance between two volumes.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
volume1 : (an existing file name)
        Has to have the same dimensions as volume2.
volume2 : (an existing file name)
        Has to have the same dimensions as volume1.

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
method : ('eucl@_min' or 'eucl@_cog' or 'eucl@_mean' or 'eucl@_wmean')
        ""eucl@_min": Euclidean distance between two closest points    "eucl@_cog": mean Euclidian distance between the Center of Gravity of volume1 and CoGs of volume2    "eucl@_mean": mean Euclidian minimum distance of all volume2 voxels to volume1    "eucl@_wmean": mean Euclidian minimum distance of all volume2 voxels to volume1 weighted by their values
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
distance : (a float)
        Unknown
histogram : (a file name)
        Unknown
point1 : (an array with shape (3,))
        Unknown
point2 : (an array with shape (3,))
        Unknown
\end{Verbatim}


\subsection{\texttt{ModifyAffine}}
\label{interfaces/generated/nipype.algorithms.misc:modifyaffine}
Left multiplies the affine matrix with a specified values. Saves the volume as a nifti file.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
volumes : (an existing file name)
        volumes which affine matrices will be modified

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
transformation@_matrix : (an array with shape (4, 4))
        transformation matrix that will be left multiplied by the affine matrix
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
transformed@_volumes : (a file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{PickAtlas}}
\label{interfaces/generated/nipype.algorithms.misc:pickatlas}
Returns ROI masks given an atlas and a list of labels. Supports dilation
and left right masking (assuming the atlas is properly aligned).

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
atlas : (an existing file name)
        Location of the atlas that will be used.
dilation@_size : (an integer)
        Defines how much the mask will be dilated (expanded in 3D).
hemi : ('both' or 'left' or 'right')
        Restrict the mask to only one hemisphere: left or right
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
labels : (an integer or a list of items which are an integer)
        Labels of regions that will be included in the mask. Must be compatible with the atlas used.
output@_file : (a file name)
        Where to store the output mask.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
mask@_file : (an existing file name)
        output mask file
\end{Verbatim}


\subsection{\texttt{SimpleThreshold}}
\label{interfaces/generated/nipype.algorithms.misc:simplethreshold}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
threshold : (a float)
        volumes to be thresholdedeverything below this value will be set to zero
volumes : (an existing file name)
        volumes to be thresholded

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
thresholded@_volumes : (an existing file name)
        thresholded volumes
\end{Verbatim}


\section{nipype.algorithms.modelgen}
\label{interfaces/generated/nipype.algorithms.modelgen:nipype-algorithms-modelgen}\label{interfaces/generated/nipype.algorithms.modelgen::doc}

\subsection{\texttt{SpecifyModel}}
\label{interfaces/generated/nipype.algorithms.modelgen:specifymodel}
Makes a model specification compatible with spm/fsl designers.

The subject\_info field should contain paradigm information in the form of
a Bunch of a list of Bunch. The Bunch should contain the following
information.


\subsubsection{Required for most designs}
\label{interfaces/generated/nipype.algorithms.modelgen:required-for-most-designs}\begin{itemize}
\item {} 
conditions : list of names

\item {} 
onsets : lists of onsets corresponding to each condition

\item {} 
durations : lists of durations corresponding to each condition. Should be left to a single 0 if all events are being modelled as impulses.

\end{itemize}


\subsubsection{Optional}
\label{interfaces/generated/nipype.algorithms.modelgen:optional}\begin{quote}
\begin{itemize}
\item {} 
regressors : list of dicts
\begin{itemize}
\item {} 
names : list of names corresponding to each column. Should be None if
automatically assigned.

\item {} 
values : lists of values for each regressors

\end{itemize}

\item {} 
amplitudes : lists of amplitudes for each event. This will be ignored by
SPM's Level1Design.

\end{itemize}

The following two (tmod, pmod) will be ignored by any Level1Design class
other than SPM:
\begin{itemize}
\item {} 
tmod : lists of conditions that should be temporally modulated. Should
default to None if not being used.

\item {} 
pmod : list of Bunch corresponding to conditions
\begin{itemize}
\item {} 
name : name of parametric modulator

\item {} 
param : values of the modulator

\item {} 
poly : degree of modulation

\end{itemize}

\end{itemize}
\end{quote}

Alternatively, you can provide information through event files.

The event files have to be in 1,2 or 3 column format with the columns
corresponding to Onsets, Durations and Amplitudes and they have to have the
name event\_name.runXXX... e.g.: Words.run001.txt. The event\_name part will
be used to create the condition names.


\subsubsection{Examples}
\label{interfaces/generated/nipype.algorithms.modelgen:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s} \PYG{o}{=} \PYG{n}{SpecifyModel}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{functional\PYGZus{}runs} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{functional2.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{functional3.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{l+m+mi}{6}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mf}{128.}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{info} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{180}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}             \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{30}\PYG{p}{,} \PYG{l+m+mi}{40}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{150}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Using pmod:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{info} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cond2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{180}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{pmod}\PYG{o}{=}\PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{amp}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{n}{poly}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,}\PYG{n}{param}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}         \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cond2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{,} \PYG{l+m+mi}{120}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{80}\PYG{p}{,} \PYG{l+m+mi}{160}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{pmod}\PYG{o}{=}\PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{name}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{amp}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{n}{poly}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,}\PYG{n}{param}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
event@_info : (a list of items which are an existing file name)
        list of event description files 1,2 or 3 column format corresponding to onsets, durations and amplitudes
        exclusive: subject@_info
functional@_runs : (a list of items which are an existing file name or an existing file name)
        Data files for model. List of 4D files or list oflist of 3D files per session
high@_pass@_filter@_cutoff : (a float)
        High-pass filter cutoff in secs
input@_units : ('secs' or 'scans')
        Units of event onsets and durations (secs or scans)Output units are always in secs
subject@_info    Bunch of List(Bunch) subject specific condition information. see :class:[]`SpecifyModel[]` or SpecifyModel.@_@_doc@_@_ for details
        exclusive: event@_info
time@_repetition : (a float)
        Time between the start of one volume to the start of the next image volume.

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
outlier@_files : (an existing file name)
        Files containing scan outlier indices that should be tossed
realignment@_parameters : (an existing file name)
        Realignment parameters returned by motion correction algorithm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
session@_info    session info for level1designs
\end{Verbatim}


\subsection{\texttt{SpecifySPMModel}}
\label{interfaces/generated/nipype.algorithms.modelgen:specifyspmmodel}
Adds SPM specific options to SpecifyModel
\begin{quote}
\begin{description}
\item[{adds:}] \leavevmode\begin{itemize}
\item {} 
concatenate\_runs

\item {} 
output\_units

\end{itemize}

\end{description}
\end{quote}


\subsubsection{Examples}
\label{interfaces/generated/nipype.algorithms.modelgen:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s} \PYG{o}{=} \PYG{n}{SpecifySPMModel}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{output\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{scans}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mf}{128.}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{functional\PYGZus{}runs} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{functional2.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{functional3.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{l+m+mi}{6}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenate\PYGZus{}runs} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{info} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{180}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}             \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{30}\PYG{p}{,} \PYG{l+m+mi}{40}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{150}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
event@_info : (a list of items which are an existing file name)
        list of event description files 1,2 or 3 column format corresponding to onsets, durations and amplitudes
        exclusive: subject@_info
functional@_runs : (a list of items which are an existing file name or an existing file name)
        Data files for model. List of 4D files or list oflist of 3D files per session
high@_pass@_filter@_cutoff : (a float)
        High-pass filter cutoff in secs
input@_units : ('secs' or 'scans')
        Units of event onsets and durations (secs or scans)Output units are always in secs
subject@_info    Bunch of List(Bunch) subject specific condition information. see :class:[]`SpecifyModel[]` or SpecifyModel.@_@_doc@_@_ for details
        exclusive: event@_info
time@_repetition : (a float)
        Time between the start of one volume to the start of the next image volume.

@PYGZlb[]Optional@PYGZrb[]
concatenate@_runs : (a boolean)
        Concatenate all runs to look like a single session.
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
outlier@_files : (an existing file name)
        Files containing scan outlier indices that should be tossed
output@_units : ('secs' or 'scans')
        Units of design event onsets and durations (secs or scans)
realignment@_parameters : (an existing file name)
        Realignment parameters returned by motion correction algorithm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
session@_info    session info for level1designs
\end{Verbatim}


\subsection{\texttt{SpecifySparseModel}}
\label{interfaces/generated/nipype.algorithms.modelgen:specifysparsemodel}
Makes a model specification compatible with spm/fsl designers for
sparse and sparse-clustered designs

see Ghosh et al. (2009) OHBM 2009
\href{http://dl.dropbox.com/u/363467/OHBM2009\_HRF.pdf}{http://dl.dropbox.com/u/363467/OHBM2009\_HRF.pdf}


\subsubsection{Examples}
\label{interfaces/generated/nipype.algorithms.modelgen:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{Bunch}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s} \PYG{o}{=} \PYG{n}{SpecifySparseModel}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{functional\PYGZus{}runs} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{functional2.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{functional3.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{l+m+mi}{6}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}acquisition} \PYG{o}{=} \PYG{l+m+mi}{2}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{high\PYGZus{}pass\PYGZus{}filter\PYGZus{}cutoff} \PYG{o}{=} \PYG{l+m+mf}{128.}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{model\PYGZus{}hrf} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{info} \PYG{o}{=} \PYG{p}{[}\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{180}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}             \PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{conditions}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cond1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{onsets}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{30}\PYG{p}{,} \PYG{l+m+mi}{40}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{150}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{durations}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{s}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}info} \PYG{o}{=} \PYG{n}{info}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
event@_info : (a list of items which are an existing file name)
        list of event description files 1,2 or 3 column format corresponding to onsets, durations and amplitudes
        exclusive: subject@_info
functional@_runs : (a list of items which are an existing file name or an existing file name)
        Data files for model. List of 4D files or list oflist of 3D files per session
high@_pass@_filter@_cutoff : (a float)
        High-pass filter cutoff in secs
input@_units : ('secs' or 'scans')
        Units of event onsets and durations (secs or scans)Output units are always in secs
subject@_info    Bunch of List(Bunch) subject specific condition information. see :class:[]`SpecifyModel[]` or SpecifyModel.@_@_doc@_@_ for details
        exclusive: event@_info
time@_acquisition : (a float)
        Time in seconds to acquire a single image volume
time@_repetition : (a float)
        Time between the start of one volume to the start of the next image volume.

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
model@_hrf : (a boolean)
        model sparse events with hrf
outlier@_files : (an existing file name)
        Files containing scan outlier indices that should be tossed
realignment@_parameters : (an existing file name)
        Realignment parameters returned by motion correction algorithm
save@_plot : (a boolean)
        save plot of sparse design calculation (Requires matplotlib)
scale@_regressors : (a boolean)
        Scale regressors by the peak
scan@_onset : (a float)
        Start of scanning relative to onset of run in secs
stimuli@_as@_impulses : (a boolean)
        Treat each stimulus to be impulse like.
use@_temporal@_deriv : (a boolean)
        Create a temporal derivative in addition to regular regressor
        requires: model@_hrf
volumes@_in@_cluster : (an integer @textgreater[]= 1)
        Number of scan volumes in a cluster
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
session@_info    session info for level1designs
sparse@_png@_file : (a file name)
        PNG file showing sparse design
sparse@_svg@_file : (a file name)
        SVG file showing sparse design
\end{Verbatim}


\subsection{\texttt{SpecifySparseSPMModel}}
\label{interfaces/generated/nipype.algorithms.modelgen:specifysparsespmmodel}

\section{nipype.algorithms.rapidart}
\label{interfaces/generated/nipype.algorithms.rapidart:nipype-algorithms-rapidart}\label{interfaces/generated/nipype.algorithms.rapidart::doc}

\subsection{\texttt{ArtifactDetect}}
\label{interfaces/generated/nipype.algorithms.rapidart:artifactdetect}
Detects outliers in a functional imaging series

Uses intensity and motion parameters to infer outliers. If \emph{use\_norm} is
True, it computes the movement of the center of each face a cuboid centered
around the head and returns the maximal movement across the centers.


\subsubsection{Examples}
\label{interfaces/generated/nipype.algorithms.rapidart:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad} \PYG{o}{=} \PYG{n}{ArtifactDetect}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{realigned\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{realignment\PYGZus{}parameters} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.par}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parameter\PYGZus{}source} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{FSL}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{norm\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}differences} \PYG{o}{=} \PYG{p}{[}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n+nb+bp}{False}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zintensity\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ad}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
norm@_threshold : (a float)
        Threshold to use to detect motion-related outliers whencomposite motion is being used (see []`[]`use@_norm[]`[]`)
        exclusive: rotation@_threshold,translation@_threshold
parameter@_source : ('SPM' or 'FSL' or 'Siemens')
        Are the movement parameters from SPM or FSL or fromSiemens PACE data. Options: SPM, FSL or Siemens
realigned@_files : (an existing file name)
        Names of realigned functional data files
realignment@_parameters : (an existing file name)
        Names of realignment parameterscorresponding to the functional data files
rotation@_threshold : (a float)
        Threshold (in radians) to use to detect rotation-related outliers
        exclusive: norm@_threshold
translation@_threshold : (a float)
        Threshold (in mm) to use to detect translation-related outliers
        exclusive: norm@_threshold
zintensity@_threshold : (a float)
        Intensity Z-threshold use to detection images that deviate from themean

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
intersect@_mask : (a boolean)
        Intersect the masks when computed from spm@_global. (default isTrue)
mask@_file : (an existing file name)
        Mask file to be used if mask@_type is 'file'.
mask@_threshold : (a float)
        Mask threshold to be used if mask@_type is 'thresh'.
mask@_type : ('spm@_global' or 'file' or 'thresh')
        Type of mask that should be used to mask the functional data.*spm@_global* uses an spm@_global like calculation to determine thebrain mask.  *file* specifies a brain mask file (should be an imagefile consisting of 0s and 1s). *thresh* specifies a threshold touse.  By default all voxels are used, unless one of these masktypes are defined.
use@_differences : (a list of items which are an implementor of, or can be adapted to implement, bool or None)
        Use differences between successive motion (first element)and intensity paramter (second element) estimates in orderto determine outliers.  (default is @PYGZlb[]True, True@PYGZrb[])
use@_norm : (a boolean)
        Uses a composite of the motion parameters in order to determineoutliers.  Requires []`[]`norm@_threshold[]`[]` to be set.  (default isTrue)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
intensity@_files : (an existing file name)
        One file for each functional run containing the global intensityvalues determined from the brainmask
outlier@_files : (an existing file name)
        One file for each functional run containing a list of 0-basedindices corresponding to outlier volumes
statistic@_files : (an existing file name)
        One file for each functional run containing information about thedifferent types of artifacts and if design info is provided thendetails of stimulus correlated motion and a listing or artifacts byevent type.
\end{Verbatim}


\subsection{\texttt{StimulusCorrelation}}
\label{interfaces/generated/nipype.algorithms.rapidart:stimuluscorrelation}
Determines if stimuli are correlated with motion or intensity
parameters.

Currently this class supports an SPM generated design matrix and
requires intensity parameters. This implies that one must run
ArtifactDetect and \code{nipype.interfaces.spm.Level1Design}
prior to running this or provide an SPM.mat file and intensity
parameters through some other means.


\subsubsection{Examples}
\label{interfaces/generated/nipype.algorithms.rapidart:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc} \PYG{o}{=} \PYG{n}{StimulusCorrelation}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{realignment\PYGZus{}parameters} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.par}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{intensity\PYGZus{}values} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.rms}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{spm\PYGZus{}mat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenated\PYGZus{}design} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
concatenated@_design : (a boolean)
        state if the design matrix contains concatenated sessions
intensity@_values : (an existing file name)
        Name of file containing intensity values
realignment@_parameters : (an existing file name)
        Names of realignment parameters corresponding to the functional data files
spm@_mat@_file : (an existing file name)
        SPM mat file (use pre-estimate SPM.mat file)

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
stimcorr@_files : (an existing file name)
        List of files containing correlation values
\end{Verbatim}


\section{nipype.interfaces.camino.connectivity}
\label{interfaces/generated/nipype.interfaces.camino.connectivity:nipype-interfaces-camino-connectivity}\label{interfaces/generated/nipype.interfaces.camino.connectivity::doc}

\subsection{\texttt{Conmap}}
\label{interfaces/generated/nipype.interfaces.camino.connectivity:conmap}
Wraps command \textbf{conmap}

Creates a graph representing the tractographic connections between the regions in the segmented image.

This function creates `Connectivity.png', shown in figure 1, with the graph representing the ROIs and the
connections between them. The thickness of the connections is proportional to the number of fibers
connecting those two regions. The vertices of the graph indicate the ROI and their diameter is
proportional to the number of tracts reaching that vertex or ROI. Another file, `ConnectionMatrix.txt',
containing a matrix of the number of tracts connecting different regions, is created at the same location.

If the mapping between few segments in the brain is required, the indices of those regions can be given separately. The labels and the indices of the different segments in wmparc.mgz can be found at brain1/stats/wmparc.stats. Create a file, say indices.txt with comma-separated indices of the required segments.

1001,1002,1003,1004,1005

where 1001,1002.. are the indices of the segments for which graph has to be drawn. The labels of the different vertices can be specified, by creating a file say indices-labels.txt in the following format.

1001:lBSTS
1002:lCAC
1003:lCMF


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.connectivity:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{Conmap}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{brain\PYGZus{}track.Bdouble}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{roi\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{wm\PYGZus{}undersampled.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{index\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{indices.txt}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{index\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{indices-labels.txt}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{threshold} \PYG{o}{=} \PYG{l+m+mi}{100}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mapper}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        tract filename
roi@_file : (an existing file name)
        roi filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
index@_file : (an existing file name)
        index filename (.txt)
label@_file : (an existing file name)
        label filename (.txt)
out@_file : (a file name)
        Unknown
threshold : (an integer)
        threshold indicates the minimum number of fiber connections that has to be drawn in the graph.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
conmap@_txt : (an existing file name)
        connectivity matrix in text file
\end{Verbatim}


\section{nipype.interfaces.camino.convert}
\label{interfaces/generated/nipype.interfaces.camino.convert:nipype-interfaces-camino-convert}\label{interfaces/generated/nipype.interfaces.camino.convert::doc}

\subsection{\texttt{DT2NIfTI}}
\label{interfaces/generated/nipype.interfaces.camino.convert:dt2nifti}
Wraps command \textbf{dt2nii}

Converts camino tensor data to NIfTI format

Reads Camino diffusion tensors, and converts them to NIFTI format as three .nii files.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
header@_file : (an existing file name)
         A Nifti .nii or .hdr file containing the header information
in@_file : (an existing file name)
        tract file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_root : (a file name)
        filename root prepended onto the names of three output files.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dt : (an existing file name)
        diffusion tensors in NIfTI format
exitcode : (an existing file name)
        exit codes from Camino reconstruction in NIfTI format
lns0 : (an existing file name)
        estimated lns0 from Camino reconstruction in NIfTI format
\end{Verbatim}


\subsection{\texttt{Image2Voxel}}
\label{interfaces/generated/nipype.interfaces.camino.convert:image2voxel}
Wraps command \textbf{image2voxel}

Converts Analyze / NIFTI / MHA files to voxel order.

Converts scanner-order data in a supported image format to voxel-order data.
Either takes a 4D file (all measurements in single image)
or a list of 3D images.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.camino.convert:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{img2vox} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{Image2Voxel}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{img2vox}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{4d\PYGZus{}dwi.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{img2vox}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        4d image file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        Unknown
out@_type : ('float' or 'char' or 'short' or 'int' or 'long' or 'double')
        "i.e. Bfloat". Can be "char", "short", "int", "long", "float" or "double"
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
voxel@_order : (an existing file name)
        path/name of 4D volume in voxel order
\end{Verbatim}


\subsection{\texttt{NIfTIDT2Camino}}
\label{interfaces/generated/nipype.interfaces.camino.convert:niftidt2camino}
Wraps command \textbf{niftidt2camino}

Converts NIFTI-1 diffusion tensors to Camino format. The program reads the
NIFTI header but does not apply any spatial transformations to the data. The
NIFTI intensity scaling parameters are applied.

The output is the tensors in Camino voxel ordering: {[}exit, ln(S0), dxx, dxy,
dxz, dyy, dyz, dzz{]}.

The exit code is set to 0 unless a background mask is supplied, in which case
the code is 0 in brain voxels and -1 in background voxels.

The value of ln(S0) in the output is taken from a file if one is supplied,
otherwise it is set to 0.

NOTE FOR FSL USERS - FSL's dtifit can output NIFTI tensors, but they are not
stored in the usual way (which is using NIFTI\_INTENT\_SYMMATRIX). FSL's
tensors follow the ITK / VTK ``upper-triangular'' convention, so you will need
to use the -uppertriangular option to convert these correctly.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        A NIFTI-1 dataset containing diffusion tensors. The tensors are assumed to be in lower-triangular order as specified by the NIFTI standard for the storage of symmetric matrices. This file should be either a .nii or a .hdr file.

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bgmask : (an existing file name)
        Binary valued brain / background segmentation, may be a raw binary file (specify type with -maskdatatype) or a supported image file.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
lns0@_file : (an existing file name)
        File containing the log of the unweighted signal for each voxel, may be a raw binary file (specify type with -inputdatatype) or a supported image file.
out@_file : (a file name)
        Unknown
s0@_file : (an existing file name)
        File containing the unweighted signal for each voxel, may be a raw binary file (specify type with -inputdatatype) or a supported image file.
scaleinter : (a float)
        A value v in the diffusion tensor is scaled to v * s + i. This is applied after any scaling specified by the input image. Default is 0.0.
scaleslope : (a float)
        A value v in the diffusion tensor is scaled to v * s + i. This is applied after any scaling specified by the input image. Default is 1.0.
uppertriangular : (a boolean)
        Specifies input in upper-triangular (VTK style) order.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (a file name)
        diffusion tensors data in Camino format
\end{Verbatim}


\subsection{\texttt{ProcStreamlines}}
\label{interfaces/generated/nipype.interfaces.camino.convert:procstreamlines}
Wraps command \textbf{procstreamlines}

Process streamline data
\begin{description}
\item[{This program does post-processing of streamline output from track. It can either output streamlines or connection probability maps.}] \leavevmode\begin{itemize}
\item {} 
\href{http://web4.cs.ucl.ac.uk/research/medic/camino/pmwiki/pmwiki.php?n=Man.procstreamlines}{http://web4.cs.ucl.ac.uk/research/medic/camino/pmwiki/pmwiki.php?n=Man.procstreamlines}

\end{itemize}

\end{description}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.camino.convert:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{proc} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{ProcStreamlines}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{proc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tract\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{proc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outputtracts} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{oogl}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{proc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        data file

@PYGZlb[]Optional@PYGZrb[]
allowmultitargets : (a boolean)
        Allows streamlines to connect to multiple target volumes.
args : (a string)
        Additional parameters to the command
datadims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
directional : (a list of from 3 to 3 items which are an integer)
        Splits the streamlines at the seed point and computes separate connection probabilities for each segment. Streamline segments are grouped according to their dot product with the vector (X, Y, Z). The ideal vector will be tangential to the streamline trajectory at the seed, such that the streamline projects from the seed along (X, Y, Z) and -(X, Y, Z). However, it is only necessary for the streamline trajectory to not be orthogonal to (X, Y, Z).
discardloops : (a boolean)
        This option allows streamlines to enter a waypoint exactly once. After the streamline leaves the waypoint, the entire streamline is discarded upon a second entry to the waypoint.
endpointfile : (a file name)
        Image containing endpoint ROIs. This should be an Analyze 7.5 header / image file.hdr and file.img.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
exclusionfile : (a file name)
        Image containing exclusion ROIs. This should be an Analyze 7.5 header / image file.hdr and file.img.
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputmodel : ('raw' or 'voxels')
        input model type (raw or voxels)
iterations : (a float)
        Number of streamlines generated for each seed. Not required when outputting streamlines, but needed to create PICo images. The default is 1 if the output is streamlines, and 5000 if the output is connection probability images.
maxtractlength : (an integer)
        maximum length of tracts
maxtractpoints : (an integer)
        maximum number of tract points
mintractlength : (an integer)
        minimum length of tracts
mintractpoints : (an integer)
        minimum number of tract points
noresample : (a boolean)
        Disables resampling of input streamlines. Resampling is automatically disabled if the input model is voxels.
out@_file : (a file name)
        Unknown
outputacm : (a boolean)
        output all tracts in a single connection probability map (Analyze image)
outputcbs : (a boolean)
        outputs connectivity-based segmentation maps; requires target outputfile
outputcp : (a boolean)
        output the connection probability map (Analyze image, float)
outputroot : (a file name)
        root directory for output
outputsc : (a boolean)
        output the connection probability map (raw streamlines, int)
outputtracts : ('raw' or 'voxels' or 'oogl')
        output tract file type
regionindex : (an integer)
        index of specific region to process
resamplestepsize : (a float)
        Each point on a streamline is tested for entry into target, exclusion or waypoint volumes. If the length between points on a tract is not much smaller than the voxel length, then streamlines may pass through part of a voxel without being counted. To avoid this, the program resamples streamlines such that the step size is one tenth of the smallest voxel dimension in the image. This increases the size of raw or oogl streamline output and incurs some performance penalty. The resample resolution can be controlled with this option or disabled altogether by passing a negative step size or by passing the -noresample option.
seedfile : (a file name)
        Image Containing Seed Points
seedpointmm : (a list of from 3 to 3 items which are an integer)
        The coordinates of a single seed point for tractography in mm
seedpointvox : (a list of from 3 to 3 items which are an integer)
        The coordinates of a single seed point for tractography in voxels
targetfile : (a file name)
        Image containing target volumes.
truncateinexclusion : (a boolean)
        Retain segments of a streamline before entry to an exclusion ROI.
truncateloops : (a boolean)
        This option allows streamlines to enter a waypoint exactly once. After the streamline leaves the waypoint, it is truncated upon a second entry to the waypoint.
voxeldims : (a list of from 3 to 3 items which are an integer)
        voxel dimensions in mm
waypointfile : (a file name)
        Image containing waypoints. Waypoints are defined as regions of the image with the same intensity, where 0 is background and any value @textgreater[] 0 is a waypoint.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
proc : (an existing file name)
        Processed Streamlines
\end{Verbatim}


\subsection{\texttt{TractShredder}}
\label{interfaces/generated/nipype.interfaces.camino.convert:tractshredder}
Wraps command \textbf{tractshredder}

Extracts bunches of streamlines.

tractshredder works in a similar way to shredder, but processes streamlines instead of scalar data.
The input is raw streamlines, in the format produced by track or procstreamlines.

The program first makes an initial offset of offset tracts.  It then reads and outputs a group of
bunchsize tracts, skips space tracts, and repeats until there is no more input.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.camino.convert:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TractShredder}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tract\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{offset} \PYG{o}{=} \PYG{l+m+mi}{0}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bunchsize} \PYG{o}{=} \PYG{l+m+mi}{1}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{space} \PYG{o}{=} \PYG{l+m+mi}{2}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shred}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        tract file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bunchsize : (an integer)
        reads and outputs a group of bunchsize tracts
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
offset : (an integer)
        initial offset of offset tracts
out@_file : (a file name)
        Unknown
space : (an integer)
        skips space tracts
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
shredded : (an existing file name)
        Shredded tract file
\end{Verbatim}


\subsection{\texttt{VtkStreamlines}}
\label{interfaces/generated/nipype.interfaces.camino.convert:vtkstreamlines}
Wraps command \textbf{vtkstreamlines}

Use vtkstreamlines to convert raw or voxel format streamlines to VTK polydata


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.camino.convert:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vtk} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{VtkStreamlines}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vtk}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tract\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vtk}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxeldims} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vtk}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        data file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
colourorient : (a boolean)
        Each point on the streamline is coloured by the local orientation.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputmodel : ('raw' or 'voxels')
        input model type (raw or voxels)
interpolate : (a boolean)
        the scalar value at each point on the streamline is calculated by trilinear interpolation
interpolatescalars : (a boolean)
        the scalar value at each point on the streamline is calculated by trilinear interpolation
out@_file : (a file name)
        Unknown
scalar@_file : (a file name)
        image that is in the same physical space as the tracts
seed@_file : (a file name)
        image containing seed points
target@_file : (a file name)
        image containing integer-valued target regions
voxeldims : (a list of from 3 to 3 items which are an integer)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
vtk : (an existing file name)
        Streamlines in VTK format
\end{Verbatim}


\section{nipype.interfaces.camino.dti}
\label{interfaces/generated/nipype.interfaces.camino.dti:nipype-interfaces-camino-dti}\label{interfaces/generated/nipype.interfaces.camino.dti::doc}

\subsection{\texttt{AnalyzeHeader}}
\label{interfaces/generated/nipype.interfaces.camino.dti:analyzeheader}
Wraps command \textbf{analyzeheader}

Create or read an Analyze 7.5 header file.

Analyze image header, provides support for the most common header fields.
Some fields, such as patient\_id, are not currently supported. The program allows
three nonstandard options: the field image\_dimension.funused1 is the image scale.
The intensity of each pixel in the associated .img file is (image value from file) * scale.
Also, the origin of the Talairach coordinates (midline of the anterior commisure) are encoded
in the field data\_history.originator. These changes are included for compatibility with SPM.

All headers written with this program are big endian by default.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{AnalyzeHeader}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{data\PYGZus{}dims} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{256}\PYG{p}{,}\PYG{l+m+mi}{256}\PYG{p}{,}\PYG{l+m+mi}{256}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}dims} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{hdr}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
datatype : ('byte' or 'char' or '@PYGZlb[]u@PYGZrb[]short' or '@PYGZlb[]u@PYGZrb[]int' or 'float' or 'complex' or 'double')
        The char datatype is 8 bit (not the 16 bit char of Java), as specified by the Analyze 7.5 standard.      The byte, ushort and uint types are not part of the Analyze specification but are supported by SPM.
in@_file : (an existing file name)
        Tensor-fitted data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
centre : (a list of from 3 to 3 items which are an integer)
        Voxel specifying origin of Talairach coordinate system for SPM, default         @PYGZlb[]0 0 0@PYGZrb[].
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
description : (a string)
        Short description - No spaces, max length 79 bytes. Will be null terminated automatically.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
greylevels : (a list of from 2 to 2 items which are an integer)
        Minimum and maximum greylevels. Stored as shorts in the header.
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
initfromheader : (an existing file name)
        Reads header information from file and intializes a new header with the valuesread from the file. You may replace any combination of fields in the new header by specifyingsubsequent options.
intelbyteorder : (a boolean)
        Write header in intel byte order (little-endian).
networkbyteorder : (a boolean)
        Write header in network byte order (big-endian). This is the default for new headers.
nimages : (an integer)
        Number of images in the img file. Default 1.
offset : (an integer)
        According to the Analyze 7.5 standard, this is the byte offset in the .img fileat which voxels start. This value can be negative to specify that the absolute value isapplied for every image in the file.
out@_file : (a file name)
        Unknown
picoseed : (a list of from 3 to 3 items which are an integer)
        Voxel specifying the seed (for PICo maps), default @PYGZlb[]0 0 0@PYGZrb[].
printbigendian : (an existing file name)
        Prints 1 if the header is big-endian, 0 otherwise.
printimagedims : (an existing file name)
        Prints image data and voxel dimensions as Camino arguments and exits.
printintelbyteorder : (an existing file name)
        Prints 1 if the header is little-endian, 0 otherwise.
printprogargs : (an existing file name)
        Prints data dimension (and type, if relevant) arguments for a specific Caminoprogram, where prog is one of shredder, scanner2voxel, vcthreshselect, pdview, track.
readheader : (an existing file name)
        Reads header information from file and prints to stdout. If this option is notspecified, then the program writes a header based on the other arguments.
scaleinter : (a float)
        Constant to add to the image intensities. Used by SPM and MRIcro.
scaleslope : (a float)
        Intensities in the image are scaled by this factor by SPM and MRICro. Default is 1.0.
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
header : (an existing file name)
        Analyze header
\end{Verbatim}


\subsection{\texttt{DTEig}}
\label{interfaces/generated/nipype.interfaces.camino.dti:dteig}
Wraps command \textbf{dteig}

Computes the eigensystem from tensor fitted data.

Reads diffusion tensor (single, two-tensor, three-tensor or multitensor) data from the
standard input, computes the eigenvalues and eigenvectors of each tensor and outputs the
results to the standard output. For multiple-tensor data the program outputs the
eigensystem of each tensor. For each tensor the program outputs: \{l\_1, e\_11, e\_12, e\_13,
l\_2, e\_21, e\_22, e\_33, l\_3, e\_31, e\_32, e\_33\}, where l\_1 \textgreater{}= l\_2 \textgreater{}= l\_3 and e\_i = (e\_i1,
e\_i2, e\_i3) is the eigenvector with eigenvalue l\_i. For three-tensor data, for example,
the output contains thirty-six values per voxel.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dteig} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{DTEig}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dteig}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dteig}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        Tensor-fitted data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('double' or 'char' or 'short' or 'int' or 'long' or 'float')
        Specifies the data type of the input file. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".
inputmodel : ('dt' or 'multitensor')
        Specifies the model that the input data contains parameters for. Possible model types are: "dt" (diffusion-tensor data) and "multitensor"
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel of the input data.
out@_file : (a file name)
        Unknown
outputdatatype : ('double' or 'char' or 'short' or 'int' or 'long' or 'float')
        Specifies the data type of the output data. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
eigen : (an existing file name)
        Trace of the diffusion tensor
\end{Verbatim}


\subsection{\texttt{DTIFit}}
\label{interfaces/generated/nipype.interfaces.camino.dti:dtifit}
Wraps command \textbf{dtfit}

Reads diffusion MRI data, acquired using the acquisition scheme detailed in the scheme file, from the data file.

Use non-linear fitting instead of the default linear regression to the log measurements.
The data file stores the diffusion MRI data in voxel order with the measurements stored in big-endian format and ordered as in the scheme file.
The default input data type is four-byte float. The default output data type is eight-byte double.
See modelfit and camino for the format of the data file and scheme file.
The program fits the diffusion tensor to each voxel and outputs the results,
in voxel order and as big-endian eight-byte doubles, to the standard output.
The program outputs eight values in each voxel: {[}exit code, ln(S(0)), D\_xx, D\_xy, D\_xz, D\_yy, D\_yz, D\_zz{]}.
An exit code of zero indicates no problems. For a list of other exit codes, see modelfit(1). The entry S(0) is an estimate of the signal at q=0.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{DTIFit}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        voxel-order data filename
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
non@_linear : (a boolean)
        Use non-linear fitting instead of the default linear regression to the log measurements.
out@_file : (a file name)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tensor@_fitted : (an existing file name)
        path/name of 4D volume in voxel order
\end{Verbatim}


\subsection{\texttt{DTLUTGen}}
\label{interfaces/generated/nipype.interfaces.camino.dti:dtlutgen}
Wraps command \textbf{dtlutgen}

Calibrates the PDFs for PICo probabilistic tractography.

This program needs to be run once for every acquisition scheme.
It outputs a lookup table that is used by the dtpicoparams program to find PICo PDF parameters for an image.
The default single tensor LUT contains parameters of the Bingham distribution and is generated by supplying
a scheme file and an estimated signal to noise in white matter regions of the (q=0) image.
The default inversion is linear (inversion index 1).

Advanced users can control several options, including the extent and resolution of the LUT,
the inversion index, and the type of PDF. See dtlutgen(1) for details.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dtl} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{DTLUTGen}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dtl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{snr} \PYG{o}{=} \PYG{l+m+mi}{16}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dtl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dtl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dtl}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
scheme@_file : (a file name)
        The scheme file of the images to be processed using this LUT.

@PYGZlb[]Optional@PYGZrb[]
acg : (a boolean)
        Compute a LUT for the ACG PDF.
args : (a string)
        Additional parameters to the command
bingham : (a boolean)
        Compute a LUT for the Bingham PDF. This is the default.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
frange : (a list of from 2 to 2 items which are a float)
        Index to two-tensor LUTs. This is the fractional anisotropy         of the two tensors. The default is 0.3 to 0.94
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file : (an existing file name)
        diffusion tensor datafile
inversion : (an integer)
        Index of the inversion to use. The default is 1 (linear single tensor inversion).
lrange : (a list of from 2 to 2 items which are a float)
        Index to one-tensor LUTs. This is the ratio L1/L3 and L2 / L3.The LUT is square, with half the values calculated (because L2 / L3 cannot be less than L1 / L3 by definition).The minimum must be @textgreater[]= 1. For comparison, a ratio L1 / L3 = 10 with L2 / L3 = 1 corresponds to an FA of 0.891, and L1 / L3 = 15 with L2 / L3 = 1 corresponds to an FA of 0.929. The default range is 1 to 10.
out@_file : (a file name)
        Unknown
samples : (an integer)
        The number of synthetic measurements to generate at each point in the LUT. The default is 2000.
snr : (a float)
        The signal to noise ratio of the unweighted (q = 0) measurements.This should match the SNR (in white matter) of the images that the LUTs are used with.
step : (a float)
        Distance between points in the LUT.For example, if lrange is 1 to 10 and the step is 0.1, LUT entries will be computed at L1 / L3 = 1, 1.1, 1.2 ... 10.0 and at L2 / L3 = 1.0, 1.1 ... L1 / L3.For single tensor LUTs, the default step is 0.2, for two-tensor LUTs it is 0.02.
trace : (a float)
        Trace of the diffusion tensor(s) used in the test function in the LUT generation. The default is 2100E-12 m@textasciicircum[]2 s@textasciicircum[]-1.
watson : (a boolean)
        Compute a LUT for the Watson PDF.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dtLUT : (an existing file name)
        Lookup Table
\end{Verbatim}


\subsection{\texttt{FA}}
\label{interfaces/generated/nipype.interfaces.camino.dti:fa}
Wraps command \textbf{fa}

Computes the fractional anisotropy of tensors.

Reads diffusion tensor (single, two-tensor or three-tensor) data from the standard input,
computes the fractional anisotropy (FA) of each tensor and outputs the results to the
standard output. For multiple-tensor data the program outputs the FA of each tensor,
so for three-tensor data, for example, the output contains three fractional anisotropy
values per voxel.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fa} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{FA}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fa}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fa}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fa}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        Tensor-fitted data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the input file. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
inputmodel : ('dt' or 'twotensor' or 'threetensor' or 'multitensor')
        Specifies the model that the input tensor data contains parameters for.Possible model types are: "dt" (diffusion-tensor data), "twotensor" (two-tensor data), "threetensor" (three-tensor data). By default, the program assumes that the input data contains a single diffusion tensor in each voxel.
out@_file : (a file name)
        Unknown
outputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the output data. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
fa : (an existing file name)
        Fractional Anisotropy Map
\end{Verbatim}


\subsection{\texttt{MD}}
\label{interfaces/generated/nipype.interfaces.camino.dti:md}
Wraps command \textbf{md}

Computes the mean diffusivity (trace/3) from diffusion tensors.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{md} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{MD}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{md}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{md}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{md}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        Tensor-fitted data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the input file. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
inputmodel : ('dt' or 'twotensor' or 'threetensor')
        Specifies the model that the input tensor data contains parameters for.Possible model types are: "dt" (diffusion-tensor data), "twotensor" (two-tensor data), "threetensor" (three-tensor data). By default, the program assumes that the input data contains a single diffusion tensor in each voxel.
out@_file : (a file name)
        Unknown
outputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the output data. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
md : (an existing file name)
        Mean Diffusivity Map
\end{Verbatim}


\subsection{\texttt{ModelFit}}
\label{interfaces/generated/nipype.interfaces.camino.dti:modelfit}
Wraps command \textbf{modelfit}

Fits models of the spin-displacement density to diffusion MRI measurements.

This is an interface to various model fitting routines for diffusion MRI data that
fit models of the spin-displacement density function. In particular, it will fit the
diffusion tensor to a set of measurements as well as various other models including
two or three-tensor models. The program can read input data from a file or can
generate synthetic data using various test functions for testing and simulations.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{ModelFit}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{model} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dt}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{snr} \PYG{o}{=} \PYG{l+m+mi}{16}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fit}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        voxel-order data filename
model : ('dt' or 'restore' or 'algdt' or 'nldt@_pos' or 'nldt' or 'ldt@_wtd' or 'adc' or 'ball@_stick' or 'cylcyl dt' or 'cylcyl restore' or 'cylcyl algdt' or 'cylcyl nldt@_pos' or 'cylcyl nldt' or 'cylcyl ldt@_wtd' or 'cylcyl adc' or 'cylcyl ball@_stick' or 'cylcyl@_eq dt' or 'cylcyl@_eq restore' or 'cylcyl@_eq algdt' or 'cylcyl@_eq nldt@_pos' or 'cylcyl@_eq nldt' or 'cylcyl@_eq ldt@_wtd' or 'cylcyl@_eq adc' or 'cylcyl@_eq ball@_stick' or 'pospos dt' or 'pospos restore' or 'pospos algdt' or 'pospos nldt@_pos' or 'pospos nldt' or 'pospos ldt@_wtd' or 'pospos adc' or 'pospos ball@_stick' or 'pospos@_eq dt' or 'pospos@_eq restore' or 'pospos@_eq algdt' or 'pospos@_eq nldt@_pos' or 'pospos@_eq nldt' or 'pospos@_eq ldt@_wtd' or 'pospos@_eq adc' or 'pospos@_eq ball@_stick' or 'poscyl dt' or 'poscyl restore' or 'poscyl algdt' or 'poscyl nldt@_pos' or 'poscyl nldt' or 'poscyl ldt@_wtd' or 'poscyl adc' or 'poscyl ball@_stick' or 'poscyl@_eq dt' or 'poscyl@_eq restore' or 'poscyl@_eq algdt' or 'poscyl@_eq nldt@_pos' or 'poscyl@_eq nldt' or 'poscyl@_eq ldt@_wtd' or 'poscyl@_eq adc' or 'poscyl@_eq ball@_stick' or 'cylcylcyl dt' or 'cylcylcyl restore' or 'cylcylcyl algdt' or 'cylcylcyl nldt@_pos' or 'cylcylcyl nldt' or 'cylcylcyl ldt@_wtd' or 'cylcylcyl adc' or 'cylcylcyl ball@_stick' or 'cylcylcyl@_eq dt' or 'cylcylcyl@_eq restore' or 'cylcylcyl@_eq algdt' or 'cylcylcyl@_eq nldt@_pos' or 'cylcylcyl@_eq nldt' or 'cylcylcyl@_eq ldt@_wtd' or 'cylcylcyl@_eq adc' or 'cylcylcyl@_eq ball@_stick' or 'pospospos dt' or 'pospospos restore' or 'pospospos algdt' or 'pospospos nldt@_pos' or 'pospospos nldt' or 'pospospos ldt@_wtd' or 'pospospos adc' or 'pospospos ball@_stick' or 'pospospos@_eq dt' or 'pospospos@_eq restore' or 'pospospos@_eq algdt' or 'pospospos@_eq nldt@_pos' or 'pospospos@_eq nldt' or 'pospospos@_eq ldt@_wtd' or 'pospospos@_eq adc' or 'pospospos@_eq ball@_stick' or 'posposcyl dt' or 'posposcyl restore' or 'posposcyl algdt' or 'posposcyl nldt@_pos' or 'posposcyl nldt' or 'posposcyl ldt@_wtd' or 'posposcyl adc' or 'posposcyl ball@_stick' or 'posposcyl@_eq dt' or 'posposcyl@_eq restore' or 'posposcyl@_eq algdt' or 'posposcyl@_eq nldt@_pos' or 'posposcyl@_eq nldt' or 'posposcyl@_eq ldt@_wtd' or 'posposcyl@_eq adc' or 'posposcyl@_eq ball@_stick' or 'poscylcyl dt' or 'poscylcyl restore' or 'poscylcyl algdt' or 'poscylcyl nldt@_pos' or 'poscylcyl nldt' or 'poscylcyl ldt@_wtd' or 'poscylcyl adc' or 'poscylcyl ball@_stick' or 'poscylcyl@_eq dt' or 'poscylcyl@_eq restore' or 'poscylcyl@_eq algdt' or 'poscylcyl@_eq nldt@_pos' or 'poscylcyl@_eq nldt' or 'poscylcyl@_eq ldt@_wtd' or 'poscylcyl@_eq adc' or 'poscylcyl@_eq ball@_stick')
        Specifies the model to be fit to the data.
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bgmask : (an existing file name)
        Provides the name of a file containing a background mask computed using, for example, FSL's bet2 program. The mask file contains zero in background voxels and non-zero in foreground.
bgthresh : (a float)
        Sets a threshold on the average q=0 measurement to separate foreground and background. The program does not process background voxels, but outputs the same number of values in background voxels and foreground voxels. Each value is zero in background voxels apart from the exit code which is -1.
cfthresh : (a float)
        Sets a threshold on the average q=0 measurement to determine which voxels are CSF. This program does not treat CSF voxels any different to other voxels.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fixedbvalue : (a list of from 3 to 3 items which are a float)
        As above, but specifies @textless[]M@textgreater[] @textless[]N@textgreater[] @textless[]b@textgreater[]. The resulting scheme is the same whether you specify b directly or indirectly using -fixedmodq.
fixedmodq : (a list of from 4 to 4 items which are a float)
        Specifies @textless[]M@textgreater[] @textless[]N@textgreater[] @textless[]Q@textgreater[] @textless[]tau@textgreater[] a spherical acquisition scheme with M measurements with q=0 and N measurements with @textbar[]q@textbar[]=Q and diffusion time tau. The N measurements with @textbar[]q@textbar[]=Q have unique directions. The program reads in the directions from the files in directory PointSets.
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'char' or 'short' or 'int' or 'long' or 'double')
        Specifies the data type of the input file: "char", "short", "int", "long", "float" or "double". The input file must have BIG-ENDIAN ordering. By default, the input type is "float".
noisemap : (an existing file name)
        Specifies the name of the file to contain the estimated noise variance on the diffusion-weighted signal, generated by a weighted tensor fit. The data type of this file is big-endian double.
out@_file : (a file name)
        Unknown
outlier : (an existing file name)
        Specifies the name of the file to contain the outlier map generated by the RESTORE algorithm.
outputfile : (a file name)
        Filename of the output file.
residualmap : (an existing file name)
        Specifies the name of the file to contain the weighted residual errors after computing a weighted linear tensor fit. One value is produced per measurement, in voxel order.The data type of this file is big-endian double. Images of the residuals for each measurement can be extracted with shredder.
sigma : (a float)
        Specifies the standard deviation of the noise in the data. Required by the RESTORE algorithm.
tau : (a float)
        Sets the diffusion time separately. This overrides the diffusion time specified in a scheme file or by a scheme index for both the acquisition scheme and in the data synthesis.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
fitted@_data : (an existing file name)
        output file of 4D volume in voxel order
\end{Verbatim}


\subsection{\texttt{PicoPDFs}}
\label{interfaces/generated/nipype.interfaces.camino.dti:picopdfs}
Wraps command \textbf{picopdfs}

Constructs a spherical PDF in each voxel for probabilistic tractography.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pdf} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{PicoPDFs}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pdf}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputmodel} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dt}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pdf}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{luts} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{lut\PYGZus{}file}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pdf}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{voxel-order\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pdf}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        voxel-order data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
directmap : (a boolean)
        Only applicable when using pds as the inputmodel. Use direct mapping between the eigenvalues and the distribution parameters instead of the log of the eigenvalues.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputmodel : ('dt' or 'multitensor' or 'pds')
        input model type
luts : (an existing file name)
        Files containing the lookup tables.For tensor data, one lut must be specified for each type of inversion used in the image (one-tensor, two-tensor, three-tensor).For pds, the number of LUTs must match -numpds (it is acceptable to use the same LUT several times - see example, above).These LUTs may be generated with dtlutgen.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel (default 2) for multitensor data.Currently, only the default is supported, but future releases may allow the input of three-tensor data using this option.
numpds : (an integer)
        The maximum number of PDs in a voxel (default 3) for PD data.This option determines the size of the input and output voxels.This means that the data file may be large enough to accomodate three or more PDs,but does not mean that any of the voxels are classified as containing three or more PDs.
out@_file : (a file name)
        Unknown
pdf : ('watson' or 'bingham' or 'acg')
         Specifies the PDF to use. There are three choices:watson - The Watson distribution. This distribution is rotationally symmetric.bingham - The Bingham distributionn, which allows elliptical probability density contours.acg - The Angular Central Gaussian distribution, which also allows elliptical probability density contours
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
pdfs : (an existing file name)
        path/name of 4D volume in voxel order
\end{Verbatim}


\subsection{\texttt{TrD}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trd}
Wraps command \textbf{trd}

Computes the trace of tensors.

Reads diffusion tensor (single, two-tensor or three-tensor) data from the standard input,
computes the trace of each tensor, i.e., three times the mean diffusivity, and outputs
the results to the standard output. For multiple-tensor data the program outputs the
trace of each tensor, so for three-tensor data, for example, the output contains three
values per voxel.

Divide the output by three to get the mean diffusivity.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id8}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{trace} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrD}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{trace}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{trace}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{A.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{trace}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        Tensor-fitted data filename

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the input file. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
inputmodel : ('dt' or 'twotensor' or 'threetensor' or 'multitensor')
        Specifies the model that the input tensor data contains parameters for.Possible model types are: "dt" (diffusion-tensor data), "twotensor" (two-tensor data), "threetensor" (three-tensor data). By default, the program assumes that the input data contains a single diffusion tensor in each voxel.
out@_file : (a file name)
        Unknown
outputdatatype : ('char' or 'short' or 'int' or 'long' or 'float' or 'double')
        Specifies the data type of the output data. The data type can be any of thefollowing strings: "char", "short", "int", "long", "float" or "double".
scheme@_file : (an existing file name)
        Camino scheme file (b values / vectors, see camino.fsl2scheme)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
trace : (an existing file name)
        Trace of the diffusion tensor
\end{Verbatim}


\subsection{\texttt{Track}}
\label{interfaces/generated/nipype.interfaces.camino.dti:track}
Wraps command \textbf{track}

Performs tractography using one of the following models:
dt', `multitensor', `pds', `pico', `bootstrap', `ballstick', `bayesdirac'


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{Track}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputmodel} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dt}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\subsection{\texttt{TrackBallStick}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trackballstick}
Wraps command \textbf{track}

Performs streamline tractography using ball-stick fitted data


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id10}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrackBallStick}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{ballstickfit\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\subsection{\texttt{TrackBayesDirac}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trackbayesdirac}
Wraps command \textbf{track}

Performs streamline tractography using a Bayesian tracking with Dirac priors


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id11}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrackBayesDirac}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvecs.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file
scheme@_file : (a file name)
        The scheme file corresponding to the data being processed.

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
curvepriorg : (a float)
        Concentration parameter for the prior distribution on fibre orientations given the fibre orientation at the previous step. Larger values of g make curvature less likely.
curvepriork : (a float)
        Concentration parameter for the prior distribution on fibre orientations given the fibre orientation at the previous step. Larger values of k make curvature less likely.
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
datamodel : ('cylsymmdt' or 'ballstick')
        Model of the data for Bayesian tracking. The default model is "cylsymmdt", a diffusion tensor with cylindrical symmetry about e@_1, ie L1 @textgreater[]= L@_2 = L@_3. The other model is "ballstick", the partial volume model (see ballstickfit).
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
extpriordatatype : ('float' or 'double')
        Datatype of the prior image. The default is "double".
extpriorfile : (an existing file name)
        Path to a PICo image produced by picopdfs. The PDF in each voxel is used as a prior for the fibre orientation in Bayesian tracking. The prior image must be in the same space as the diffusion data.
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
iterations : (an integer)
        Number of streamlines to generate at each seed point. The default is 5000.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
pdf : ('bingham' or 'watson' or 'acg')
        Specifies the model for PICo priors (not the curvature priors). The default is "bingham".
pointset : (an integer)
        Index to the point set to use for Bayesian likelihood calculation. The index specifies a set of evenly distributed points on the unit sphere, where each point x defines two possible step directions (x or -x) for the streamline path. A larger number indexes a larger point set, which gives higher angular resolution at the expense of computation time. The default is index 1, which gives 1922 points, index 0 gives 1082 points, index 2 gives 3002 points.
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\subsection{\texttt{TrackBootstrap}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trackbootstrap}
Wraps command \textbf{track}

Performs bootstrap streamline tractography using mulitple scans of the same subject


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id12}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrackBootstrap}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{scheme\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvecs.scheme}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bsdatafiles} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{fitted\PYGZus{}data1.Bfloat}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{fitted\PYGZus{}data2.Bfloat}\PYG{l+s}{'}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seedfile} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bsdatafiles : (a list of items which are a file name)
        Specifies files containing raw data for repetition bootstrapping. Use -inputfile for wild bootstrap data.
in@_file : (an existing file name)
        input data file
scheme@_file : (a file name)
        The scheme file corresponding to the data being processed.

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
bgmask : (an existing file name)
        Provides the name of a file containing a background mask computed using, for example, FSL's bet2 program. The mask file contains zero in background voxels and non-zero in foreground.
bsmodel : ('dt' or 'multitensor')
        Model to fit to bootstrap data. This is used for repetition bootstrapping. May be "dt" (default) or "multitensor". This option may be omitted if -inversion is specified.
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
inversion : (an integer)
        Tensor reconstruction algorithm for repetition bootstrapping. Default is 1 (linear reconstruction, single tensor).
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
iterations : (an integer)
        Number of streamlines to generate at each seed point.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
wildbsmodel : ('dt')
        The model to fit to the data, for wild bootstrapping. The same model is used to generate the the wild bootstrap data. Must be "dt", which is the default.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\subsection{\texttt{TrackDT}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trackdt}
Wraps command \textbf{track}

Performs streamline tractography using tensor data


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id13}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrackDT}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tensor\PYGZus{}fitted\PYGZus{}data.Bfloat}\PYG{l+s}{'}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\subsection{\texttt{TrackPICo}}
\label{interfaces/generated/nipype.interfaces.camino.dti:trackpico}
Wraps command \textbf{track}

Performs streamline tractography using the Probabilistic Index of Connectivity (PICo) algorithm


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino.dti:id14}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmon}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track} \PYG{o}{=} \PYG{n}{cmon}\PYG{o}{.}\PYG{n}{TrackPICo}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{pdfs.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{seed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{seed\PYGZus{}mask.nii}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{track}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file

@PYGZlb[]Optional@PYGZrb[]
anisfile : (an existing file name)
        File containing the anisotropy map. This is required to apply an anisotropy threshold with non tensor data. If the map issupplied it is always used, even in tensor data.
anisthresh : (a float)
        Terminate fibres that enter a voxel with lower anisotropy than the threshold.
args : (a string)
        Additional parameters to the command
curvethresh : (a float)
        Curvature threshold for tracking, expressed as the maximum angle (in degrees) between between two streamline orientations calculated over the length of a voxel. If the angle is greater than this, then the streamline terminates.
data@_dims : (a list of from 3 to 3 items which are an integer)
        data dimensions in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip : (a boolean)
        save the output image in gzip format
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inputdatatype : ('float' or 'double')
        input file type
inputmodel : ('dt' or 'multitensor' or 'pds' or 'pico' or 'bootstrap' or 'ballstick' or 'bayesdirac')
        input model type
ipthresh : (a float)
        Curvature threshold for tracking, expressed as the minimum dot product between two streamline orientations calculated over the length of a voxel. If the dot product between the previous and current directions is less than this threshold, then the streamline terminates. The default setting will terminate fibres that curve by more than 80 degrees. Set this to -1.0 to disable curvature checking completely.
iterations : (an integer)
        Number of streamlines to generate at each seed point. The default is 5000.
maxcomponents : (an integer)
        The maximum number of tensor components in a voxel. This determines the size of the input file and does not say anything about the voxel classification. The default is 2 if the input model is multitensor and 1 if the input model is dt.
numpds : (an integer)
        The maximum number of PDs in a voxel. The default is 1 for input model pico. This option determines the size of the voxels in the input file and does not affect tracking.
out@_file : (a file name)
        output data file
output@_root : (a file name)
        root directory for output
outputtracts : ('float' or 'double' or 'oogl')
        output tract file type
pdf : ('bingham' or 'watson' or 'acg')
        Specifies the model for PICo parameters. The default is "bingham.
seed@_file : (an existing file name)
        seed file
voxel@_dims : (a list of from 3 to 3 items which are a float)
        voxel dimensions in mm
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tracked : (an existing file name)
        output file containing reconstructed tracts
\end{Verbatim}


\section{nipype.interfaces.camino2trackvis.convert}
\label{interfaces/generated/nipype.interfaces.camino2trackvis.convert::doc}\label{interfaces/generated/nipype.interfaces.camino2trackvis.convert:nipype-interfaces-camino2trackvis-convert}

\subsection{\texttt{Camino2Trackvis}}
\label{interfaces/generated/nipype.interfaces.camino2trackvis.convert:camino2trackvis}
Wraps command \textbf{camino\_to\_trackvis}

Wraps camino\_to\_trackvis from Camino-Trackvis

Convert files from camino .Bfloat format to trackvis .trk format.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.camino2trackvis.convert:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.camino2trackvis} \PYG{k+kn}{as} \PYG{n+nn}{cam2trk}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t} \PYG{o}{=} \PYG{n}{cam2trk}\PYG{o}{.}\PYG{n}{Camino2Trackvis}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{data.Bfloat}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{streamlines.trk}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{min\PYGZus{}length} \PYG{o}{=} \PYG{l+m+mi}{30}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{data\PYGZus{}dims} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{128}\PYG{p}{,} \PYG{l+m+mi}{104}\PYG{p}{,} \PYG{l+m+mi}{64}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}dims} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mf}{2.0}\PYG{p}{,} \PYG{l+m+mf}{2.0}\PYG{p}{,} \PYG{l+m+mf}{2.0}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}order} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{LAS}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{c2t}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
data@_dims : (a list of from 3 to 3 items which are an integer)
        Three comma-separated integers giving the number of voxels along each dimension of the source scans.
in@_file : (an existing file name)
        The input .Bfloat (camino) file.
voxel@_dims : (a list of from 3 to 3 items which are a float)
        Three comma-separated numbers giving the size of each voxel in mm.
voxel@_order : (a file name)
        Set the order in which various directions were stored.        Specify with three letters consisting of one each          from the pairs LR, AP, and SI. These stand for Left-Right,         Anterior-Posterior, and Superior-Inferior.          Whichever is specified in each position will          be the direction of increasing order.          Read coordinate system from a NIfTI file.

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
min@_length : (a float)
        The minimum length of tracts to output
nifti@_file : (an existing file name)
        Read coordinate system from a NIfTI file.
out@_file : (a file name)
        The filename to which to write the .trk (trackvis) file.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
trackvis : (an existing file name)
        The filename to which to write the .trk (trackvis) file.
\end{Verbatim}


\subsection{\texttt{Trackvis2Camino}}
\label{interfaces/generated/nipype.interfaces.camino2trackvis.convert:trackvis2camino}
Wraps command \textbf{trackvis\_to\_camino}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        The input .trk (trackvis) file.

@PYGZlb[]Optional@PYGZrb[]
append@_file : (an existing file name)
        A file to which the append the .Bfloat data.
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        The filename to which to write the .Bfloat (camino).
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
camino : (an existing file name)
        The filename to which to write the .Bfloat (camino).
\end{Verbatim}


\section{nipype.interfaces.cmtk.base}
\label{interfaces/generated/nipype.interfaces.cmtk.base:nipype-interfaces-cmtk-base}\label{interfaces/generated/nipype.interfaces.cmtk.base::doc}

\subsection{\texttt{CFFConverter}}
\label{interfaces/generated/nipype.interfaces.cmtk.base:cffconverter}
Creates a Connectome File Format (CFF) file from input networks, surfaces, volumes, tracts, etcetera....


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.cmtk.base:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.cmtk.base} \PYG{k+kn}{as} \PYG{n+nn}{ba}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt} \PYG{o}{=} \PYG{n}{ba}\PYG{o}{.}\PYG{n}{CFFConverter}\PYG{p}{(}\PYG{p}{)}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{title} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{subject 1}\PYG{l+s}{'}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{gifti\PYGZus{}surfaces} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{lh.pial\PYGZus{}converted.gii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{rh.pial\PYGZus{}converted.gii}\PYG{l+s}{'}\PYG{p}{]}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{tract\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{streamlines.trk}\PYG{l+s}{'}\PYG{p}{]}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{gpickled\PYGZus{}networks} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{network0.gpickle}\PYG{l+s}{'}\PYG{p}{]}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
creator : (a string)
        Creator
data@_files : (an existing file name)
        list of external data files (i.e. Numpy, HD5, XML)
description : (a string)
        Description
email : (a string)
        Email address
gifti@_labels : (an existing file name)
        list of GIFTI surfaces
gifti@_surfaces : (an existing file name)
        list of GIFTI surfaces
gpickled@_networks : (an existing file name)
        list of gpickled Networkx graphs
graphml@_networks : (an existing file name)
        list of graphML networks
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
license : (a string)
        License
nifti@_volumes : (an existing file name)
        list of NIFTI volumes
out@_file : (a file name)
        Unknown
publisher : (a string)
        Publisher
references : (a string)
        References
relation : (a string)
        Relation
rights : (a string)
        Rights
script@_files : (an existing file name)
        list of script files to include
species : (a string)
        Species
timeseries@_files : (an existing file name)
        list of HDF5 timeseries files
title : (a string)
        Connectome Title
tract@_files : (an existing file name)
        list of Trackvis fiber files
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
connectome@_file : (a file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{MergeCNetworks}}
\label{interfaces/generated/nipype.interfaces.cmtk.base:mergecnetworks}
Merges networks from multiple CFF files into one new CFF file.


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.cmtk.base:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.cmtk.base} \PYG{k+kn}{as} \PYG{n+nn}{ba}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mrg} \PYG{o}{=} \PYG{n}{ba}\PYG{o}{.}\PYG{n}{MergeCNetworks}\PYG{p}{(}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mrg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{subj1.cff}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{subj2.cff}\PYG{l+s}{'}\PYG{p}{]}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mrg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a file name)
        List of CFF files to extract networks from

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
connectome@_file : (a file name)
        Single CFF file with all the networks added
\end{Verbatim}


\section{nipype.interfaces.cmtk.cmtk}
\label{interfaces/generated/nipype.interfaces.cmtk.cmtk:nipype-interfaces-cmtk-cmtk}\label{interfaces/generated/nipype.interfaces.cmtk.cmtk::doc}

\subsection{\texttt{CreateMatrix}}
\label{interfaces/generated/nipype.interfaces.cmtk.cmtk:creatematrix}
Performs connectivity mapping and outputs the result as a NetworkX graph and a Matlab matrix


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.cmtk.cmtk:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.cmtk.cmtk} \PYG{k+kn}{as} \PYG{n+nn}{ck}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{conmap} \PYG{o}{=} \PYG{n}{ck}\PYG{o}{.}\PYG{n}{CreateMatrix}\PYG{p}{(}\PYG{p}{)}               
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{conmap}\PYG{o}{.}\PYG{n}{roi\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsLUT\PYGZus{}aparc+aseg.nii}\PYG{l+s}{'}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{conmap}\PYG{o}{.}\PYG{n}{dict\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsLUT\PYGZus{}aparc+aseg.pck}\PYG{l+s}{'}                
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{conmap}\PYG{o}{.}\PYG{n}{tract\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fibers.trk}\PYG{l+s}{'}                 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{conmap}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
dict@_file : (an existing file name)
        Pickle file containing the label dictionary (see ROIGen)
resolution@_network@_file : (an existing file name)
        Parcellation files from Connectome Mapping Toolkit
roi@_file : (an existing file name)
        Freesurfer aparc+aseg file
tract@_file : (an existing file name)
        Trackvis tract file

@PYGZlb[]Optional@PYGZrb[]
out@_endpoint@_array@_name : (a file name)
        Name for the generated endpoint arrays
out@_matrix@_file : (a file name)
        NetworkX graph describing the connectivity
out@_matrix@_mat@_file : (a file name)
        Matlab matrix describing the connectivity
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
endpoint@_file : (a file name)
        Saved Numpy array with the endpoints of each fiber
endpoint@_file@_mm : (a file name)
        Saved Numpy array with the endpoints of each fiber (in millimeters)
fiber@_label@_file : (a file name)
        Saved Numpy array with the labels for each fiber
fiber@_length@_file : (a file name)
        Saved Numpy array with the lengths of each fiber
matrix@_file : (a file name)
        NetworkX graph describing the connectivity
matrix@_mat@_file : (a file name)
        Matlab matrix describing the connectivity
\end{Verbatim}


\subsection{\texttt{ROIGen}}
\label{interfaces/generated/nipype.interfaces.cmtk.cmtk:roigen}
Generates a ROI file for connectivity mapping and a dictionary file containing relevant node information


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.cmtk.cmtk:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.cmtk.cmtk} \PYG{k+kn}{as} \PYG{n+nn}{ck}                    
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rg} \PYG{o}{=} \PYG{n}{ck}\PYG{o}{.}\PYG{n}{ROIGen}\PYG{p}{(}\PYG{p}{)}                    
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{aparc\PYGZus{}aseg\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{aparc+aseg.nii}\PYG{l+s}{'}                    
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{use\PYGZus{}freesurfer\PYGZus{}LUT} \PYG{o}{=} \PYG{n+nb+bp}{True}                     
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{freesurfer\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{/usr/local/freesurfer}\PYG{l+s}{'}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

The label dictionary is written to disk using Pickle. Resulting data can be loaded using:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{file} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{FreeSurferColorLUT\PYGZus{}adapted\PYGZus{}aparc+aseg\PYGZus{}out.pck}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{r}\PYG{l+s}{"}\PYG{p}{)}                   
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{file} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{fsLUT\PYGZus{}aparc+aseg.pck}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{r}\PYG{l+s}{"}\PYG{p}{)}                    
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{labelDict} \PYG{o}{=} \PYG{n}{pickle}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n+nb}{file}\PYG{p}{)}                   
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{print} \PYG{n}{labelDict}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
aparc@_aseg@_file : (an existing file name)
        Freesurfer aparc+aseg file

@PYGZlb[]Optional@PYGZrb[]
LUT@_file : (an existing file name)
        Custom lookup table (cf. FreeSurferColorLUT.txt)
        exclusive: use@_freesurfer@_LUT
freesurfer@_dir : (a directory name)
        Freesurfer main directory
        requires: use@_freesurfer@_LUT
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_dict@_file : (a file name)
        Label dictionary saved in Pickle format
out@_roi@_file : (a file name)
        Region of Interest file for connectivity mapping
use@_freesurfer@_LUT : (a boolean)
        Boolean value; Set to True to use default Freesurfer LUT, False for custom LUT
        exclusive: LUT@_file
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dict@_file : (a file name)
        Label dictionary saved in Pickle format
roi@_file : (a file name)
        Region of Interest file for connectivity mapping
\end{Verbatim}


\section{nipype.interfaces.dcm2nii}
\label{interfaces/generated/nipype.interfaces.dcm2nii:nipype-interfaces-dcm2nii}\label{interfaces/generated/nipype.interfaces.dcm2nii::doc}

\subsection{\texttt{Dcm2nii}}
\label{interfaces/generated/nipype.interfaces.dcm2nii:dcm2nii}
Wraps command \textbf{dcm2nii}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
source@_names : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
anonymize : (a boolean)
        Unknown
args : (a string)
        Additional parameters to the command
config@_file : (an existing file name)
        Unknown
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gzip@_output : (a boolean)
        Unknown
id@_in@_filename : (a boolean)
        Unknown
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
nii@_output : (a boolean)
        Unknown
output@_dir : (an existing directory name)
        Unknown
reorient : (a boolean)
        Unknown
reorient@_and@_crop : (a boolean)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
bvals : (an existing file name)
        Unknown
bvecs : (an existing file name)
        Unknown
converted@_files : (an existing file name)
        Unknown
reoriented@_and@_cropped@_files : (an existing file name)
        Unknown
reoriented@_files : (an existing file name)
        Unknown
\end{Verbatim}


\section{nipype.interfaces.diffusion\_toolkit.base}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.base::doc}\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.base:nipype-interfaces-diffusion-toolkit-base}

\subsection{\texttt{Info}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.base:info}
Handle dtk output type and version information.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.base:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.diffusion\PYGZus{}toolkit} \PYG{k+kn}{import} \PYG{n}{Info}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{Info}\PYG{o}{.}\PYG{n}{version}\PYG{p}{(}\PYG{p}{)}  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{Info}\PYG{o}{.}\PYG{n}{subjectsdir}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\section{nipype.interfaces.diffusion\_toolkit.dti}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.dti::doc}\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.dti:nipype-interfaces-diffusion-toolkit-dti}

\subsection{\texttt{DTIRecon}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.dti:dtirecon}
Wraps command \textbf{dti\_recon}

Use dti\_recon to generate tensors and other maps

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
DWI : (an existing file name)
        Input diffusion volume
bvals : (an existing file name)
        b values file
bvecs : (an existing file name)
        b vectors file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
b0@_threshold : (a float)
        program will use b0 image with the given threshold to mask out high
background of fa/adc maps. by default it will calculate threshold
automatically. but if it failed, you need to set it manually.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
image@_orientation@_vectors : (a list of from 6 to 6 items which are a float)
        specify image orientation vectors. if just one argument given,
will treat it as filename and read the orientation vectors from
the file. if 6 arguments are given, will treat them as 6 float
numbers and construct the 1st and 2nd vector and calculate the 3rd
one automatically.
this information will be used to determine image orientation,
as well as to adjust gradient vectors with oblique angle when
n@_averages : (an integer)
        Number of averages
oblique@_correction : (a boolean)
        when oblique angle(s) applied, some SIEMENS dti protocols do not
adjust gradient accordingly, thus it requires adjustment for correct
diffusion tensor calculation
out@_prefix : (a string)
        Output file prefix
output@_type : ('nii' or 'analyze' or 'ni1' or 'nii.gz')
        output file type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
ADC : (an existing file name)
        Unknown
B0 : (an existing file name)
        Unknown
FA : (an existing file name)
        Unknown
FA@_color : (an existing file name)
        Unknown
L1 : (an existing file name)
        Unknown
L2 : (an existing file name)
        Unknown
L3 : (an existing file name)
        Unknown
V1 : (an existing file name)
        Unknown
V2 : (an existing file name)
        Unknown
V3 : (an existing file name)
        Unknown
exp : (an existing file name)
        Unknown
tensor : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{DTITracker}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.dti:dtitracker}
Wraps command \textbf{dti\_tracker}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
mask1@_file : (a file name)
        first mask image

@PYGZlb[]Optional@PYGZrb[]
angle@_threshold : (a float)
        set angle threshold. default value is 35 degree
angle@_threshold@_weight : (a float)
        set angle threshold weighting factor. weighting will be be applied         on top of the angle@_threshold
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
input@_data@_prefix : (a string)
        for internal naming use only
input@_type : ('nii' or 'analyze' or 'ni1' or 'nii.gz')
        input and output file type. accepted values are:
analyze -@textgreater[] analyze format 7.5
ni1     -@textgreater[] nifti format saved in seperate .hdr and .img file
nii     -@textgreater[] nifti format with one .nii file
nii.gz  -@textgreater[] nifti format with compression
default type is 'nii'
invert@_x : (a boolean)
        invert x component of the vector
invert@_y : (a boolean)
        invert y component of the vector
invert@_z : (a boolean)
        invert z component of the vector
mask1@_threshold : (a float)
        threshold value for the first mask image, if not given, the program will         try automatically find the threshold
mask2@_file : (a file name)
        second mask image
mask2@_threshold : (a float)
        threshold value for the second mask image, if not given, the program will         try automatically find the threshold
output@_file : (a file name)
        Unknown
output@_mask : (a file name)
        output a binary mask file in analyze format
primary@_vector : ('v2' or 'v3')
        which vector to use for fibre tracking: v2 or v3. If not set use v1
random@_seed : (an integer)
        use random location in a voxel instead of the center of the voxel           to seed. can also define number of seed per voxel. default is 1
step@_length : (a float)
        set step length, in the unit of minimum voxel size.
default value is 0.5 for interpolated streamline method
and 0.1 for other methods
swap@_xy : (a boolean)
        swap x @& y vectors while tracking
swap@_yz : (a boolean)
        swap y @& z vectors while tracking
swap@_zx : (a boolean)
        swap x @& z vectors while tracking
tensor@_file : (an existing file name)
        reconstructed tensor file
tracking@_method : ('fact' or 'rk2' or 'tl' or 'sl')
        fact -@textgreater[] use FACT method for tracking. this is the default method.
rk2  -@textgreater[] use 2nd order runge-kutta method for tracking.
tl   -@textgreater[] use tensorline method for tracking.
sl   -@textgreater[] use interpolated streamline method with fixed step-length
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
mask@_file : (an existing file name)
        Unknown
track@_file : (an existing file name)
        Unknown
\end{Verbatim}


\section{nipype.interfaces.diffusion\_toolkit.odf}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.odf:nipype-interfaces-diffusion-toolkit-odf}\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.odf::doc}

\subsection{\texttt{HARDIMat}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.odf:hardimat}
Wraps command \textbf{hardi\_mat}

Use hardi\_mat to calculate a reconstruction matrix from a gradient table

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bvals : (an existing file name)
        b values file
bvecs : (an existing file name)
        b vectors file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
image@_info : (an existing file name)
        specify image information file. the image info file is generated
from original dicom image by diff@_unpack program and contains image
orientation and other information needed for reconstruction and
tracking. by default will look into the image folder for .info file
image@_orientation@_vectors : (a list of from 6 to 6 items which are a float)
        specify image orientation vectors. if just one argument given,
will treat it as filename and read the orientation vectors from
the file. if 6 arguments are given, will treat them as 6 float
numbers and construct the 1st and 2nd vector and calculate the 3rd
one automatically.
this information will be used to determine image orientation,
as well as to adjust gradient vectors with oblique angle when
oblique@_correction : (a boolean)
        when oblique angle(s) applied, some SIEMENS dti protocols do not
adjust gradient accordingly, thus it requires adjustment for correct
diffusion tensor calculation
odf@_file : (an existing file name)
        filename that contains the reconstruction points on a HEMI-sphere.
use the pre-set 181 points by default
order : (an integer)
        maximum order of spherical harmonics. must be even number. default
is 4
out@_file : (a file name)
        output matrix file
reference@_file : (an existing file name)
        provide a dicom or nifti image as the reference for the program to
figure out the image orientation information. if no such info was
found in the given image header, the next 5 options -info, etc.,
will be used if provided. if image orientation info can be found
in the given reference, all other 5 image orientation options will
be IGNORED
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        output matrix file
\end{Verbatim}


\subsection{\texttt{ODFRecon}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.odf:odfrecon}
Wraps command \textbf{odf\_recon}

Use odf\_recon to generate tensors and other maps

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
DWI : (an existing file name)
        Input raw data
matrix : (an existing file name)
        use given file as reconstruction matrix.
n@_b0 : (an integer)
        number of b0 scans. by default the program gets this information
from the number of directions and number of volumes in
the raw data. useful when dealing with incomplete raw
data set or only using part of raw data set to reconstruct
n@_directions : (an integer)
        Number of directions
n@_output@_directions : (an integer)
        Number of output directions

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dsi : (a boolean)
        indicates that the data is dsi
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
filter : (a boolean)
        apply a filter (e.g. high pass) to the raw image
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
image@_orientation@_vectors : (a list of from 6 to 6 items which are a float)
        specify image orientation vectors. if just one argument given,
will treat it as filename and read the orientation vectors from
the file. if 6 arguments are given, will treat them as 6 float
numbers and construct the 1st and 2nd vector and calculate the 3rd
one automatically.
this information will be used to determine image orientation,
as well as to adjust gradient vectors with oblique angle when
oblique@_correction : (a boolean)
        when oblique angle(s) applied, some SIEMENS dti protocols do not
adjust gradient accordingly, thus it requires adjustment for correct
diffusion tensor calculation
out@_prefix : (a string)
        Output file prefix
output@_entropy : (a boolean)
        output entropy map
output@_type : ('nii' or 'analyze' or 'ni1' or 'nii.gz')
        output file type
sharpness : (a float)
        smooth or sharpen the raw data. factor @textgreater[] 0 is smoothing.
factor @textless[] 0 is sharpening. default value is 0
NOTE: this option applies to DSI study only
subtract@_background : (a boolean)
        subtract the background value before reconstruction
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
B0 : (an existing file name)
        Unknown
DWI : (an existing file name)
        Unknown
ODF : (an existing file name)
        Unknown
entropy : (a file name)
        Unknown
max : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{ODFTracker}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.odf:odftracker}
Wraps command \textbf{odf\_tracker}

Use odf\_tracker to generate track file

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
ODF : (an existing file name)
        Unknown
mask1@_file : (a file name)
        first mask image
max : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
angle@_threshold : (a float)
        set angle threshold. default value is 35 degree for
default tracking method and 25 for rk2
args : (a string)
        Additional parameters to the command
disc : (a boolean)
        use disc tracking
dsi : (a boolean)
         specify the input odf data is dsi. because dsi recon uses fixed
pre-calculated matrix, some special orientation patch needs to
be applied to keep dti/dsi/q-ball consistent.
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
image@_orientation@_vectors : (a list of from 6 to 6 items which are a float)
        specify image orientation vectors. if just one argument given,
will treat it as filename and read the orientation vectors from
the file. if 6 arguments are given, will treat them as 6 float
numbers and construct the 1st and 2nd vector and calculate the 3rd
one automatically.
this information will be used to determine image orientation,
as well as to adjust gradient vectors with oblique angle when
input@_data@_prefix : (a string)
        recon data prefix
input@_output@_type : ('nii' or 'analyze' or 'ni1' or 'nii.gz')
        input and output file type
invert@_x : (a boolean)
        invert x component of the vector
invert@_y : (a boolean)
        invert y component of the vector
invert@_z : (a boolean)
        invert z component of the vector
limit : (an integer)
        in some special case, such as heart data, some track may go into
infinite circle and take long time to stop. this option allows
setting a limit for the longest tracking steps (voxels)
mask1@_threshold : (a float)
        threshold value for the first mask image, if not given, the program will         try automatically find the threshold
mask2@_file : (a file name)
        second mask image
mask2@_threshold : (a float)
        threshold value for the second mask image, if not given, the program will         try automatically find the threshold
out@_file : (a file name)
        output track file
random@_seed : (an integer)
        use random location in a voxel instead of the center of the voxel
to seed. can also define number of seed per voxel. default is 1
runge@_kutta2 : (a boolean)
        use 2nd order runge-kutta method for tracking.
default tracking method is non-interpolate streamline
slice@_order : (an integer)
        set the slice order. 1 means normal, -1 means reversed. default value is 1
step@_length : (a float)
        set step length, in the unit of minimum voxel size.
default value is 0.1.
swap@_xy : (a boolean)
        swap x and y vectors while tracking
swap@_yz : (a boolean)
        swap y and z vectors while tracking
swap@_zx : (a boolean)
        swap x and z vectors while tracking
voxel@_order : ('RAS' or 'RPS' or 'RAI' or 'RPI' or 'LAI' or 'LAS' or 'LPS' or 'LPI')
        specify the voxel order in RL/AP/IS (human brain) reference. must be
3 letters with no space in between.
for example, RAS means the voxel row is from L-@textgreater[]R, the column
is from P-@textgreater[]A and the slice order is from I-@textgreater[]S.
by default voxel order is determined by the image orientation
(but NOT guaranteed to be correct because of various standards).
for example, siemens axial image is LPS, coronal image is LIP and
sagittal image is PIL.
this information also is NOT needed for tracking but will be saved
in the track file and is essential for track display to map onto
the right coordinates
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
track@_file : (an existing file name)
        output track file
\end{Verbatim}


\section{nipype.interfaces.diffusion\_toolkit.postproc}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.postproc::doc}\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.postproc:nipype-interfaces-diffusion-toolkit-postproc}

\subsection{\texttt{SplineFilter}}
\label{interfaces/generated/nipype.interfaces.diffusion_toolkit.postproc:splinefilter}
Wraps command \textbf{spline\_filter}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
step@_length : (a float)
        in the unit of minimum voxel size
track@_file : (an existing file name)
        file containing tracks to be filtered

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_file : (a file name)
        target file for smoothed tracks
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
smoothed@_track@_file : (an existing file name)
        Unknown
\end{Verbatim}


\section{nipype.interfaces.freesurfer.base}
\label{interfaces/generated/nipype.interfaces.freesurfer.base:nipype-interfaces-freesurfer-base}\label{interfaces/generated/nipype.interfaces.freesurfer.base::doc}

\subsection{\texttt{Info}}
\label{interfaces/generated/nipype.interfaces.freesurfer.base:info}
Freesurfer subject directory and version information.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.base:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{Info}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{Info}\PYG{o}{.}\PYG{n}{version}\PYG{p}{(}\PYG{p}{)}  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{Info}\PYG{o}{.}\PYG{n}{subjectsdir}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\section{nipype.interfaces.freesurfer.model}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:nipype-interfaces-freesurfer-model}\label{interfaces/generated/nipype.interfaces.freesurfer.model::doc}

\subsection{\texttt{Binarize}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:binarize}
Wraps command \textbf{mri\_binarize}

Use FreeSurfer mri\_binarize to threshold an input volume


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{binvol} \PYG{o}{=} \PYG{n}{Binarize}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n+nb}{min}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{binary\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo\PYGZus{}out.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{binvol}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}binarize --o foo\PYGZus{}out.nii --i structural.nii --min 10.000000'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input volume

@PYGZlb[]Optional@PYGZrb[]
abs : (a boolean)
        take abs of invol first (ie, make unsigned)
args : (a string)
        Additional parameters to the command
bin@_col@_num : (a boolean)
        set binarized voxel value to its column number
bin@_val : (an integer)
        set vox within thresh to val (default is 1)
bin@_val@_not : (an integer)
        set vox outside range to val (default is 0)
binary@_file : (a file name)
        binary output volume
count@_file : (a boolean or a file name)
        save number of hits in ascii file (hits,ntotvox,pct)
dilate : (an integer)
        niters: dilate binarization in 3D
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
erode : (an integer)
        nerode: erode binarization in 3D (after any dilation)
erode2d : (an integer)
        nerode2d: erode binarization in 2D (after any 3D erosion)
frame@_no : (an integer)
        use 0-based frame of input (default is 0)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert : (a boolean)
        set binval=0, binvalnot=1
mask@_file : (an existing file name)
        must be within mask
mask@_thresh : (a float)
        set thresh for mask
match : (a list of items which are an integer)
        match instead of threshold
max : (a float)
        max thresh
merge@_file : (an existing file name)
        merge with mergevol
min : (a float)
        min thresh
out@_type : ('nii' or 'nii.gz' or 'mgz')
        output file type
rmax : (a float)
        compute max based on rmax*globalmean
rmin : (a float)
        compute min based on rmin*globalmean
subjects@_dir : (an existing directory name)
        subjects directory
ventricles : (a boolean)
        set match vals those for aseg ventricles+choroid (not 4th)
wm : (a boolean)
        set match vals to 2 and 41 (aseg for cerebral WM)
wm@_ven@_csf : (a boolean)
        WM and ventricular CSF, including choroid (not 4th)
zero@_edges : (a boolean)
        zero the edge voxels
zero@_slice@_edge : (a boolean)
        zero the edge slice voxels
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
binary@_file : (an existing file name)
        binarized output volume
count@_file : (a file name)
        ascii file containing number of hits
\end{Verbatim}


\subsection{\texttt{Concatenate}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:concatenate}
Wraps command \textbf{mri\_concat}

Use Freesurfer mri\_concat to combine several input volumes
into one output volume.  Can concatenate by frames, or compute
a variety of statistics on the input volumes.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:id1}
Combine two input volumes into one volume with two frames

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{concat} \PYG{o}{=} \PYG{n}{Concatenate}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{concat}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{concat}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{concatenated\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{concat}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}concat --o bar.nii --i cont1.nii --i cont2.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (an existing file name)
        Individual volumes to be concatenated

@PYGZlb[]Optional@PYGZrb[]
add@_val : (a float)
        Add some amount to the input volume
args : (a string)
        Additional parameters to the command
combine : (a boolean)
        Combine non-zero values into single frame volume
concatenated@_file : (a file name)
        Output volume
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
gmean : (an integer)
        create matrix to average Ng groups, Nper=Ntot/Ng
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
keep@_dtype : (a boolean)
        Keep voxelwise precision type (default is float
mask@_file : (an existing file name)
        Mask input with a volume
max@_bonfcor : (a boolean)
        Compute max and bonferroni correct (assumes -log10(ps))
max@_index : (a boolean)
        Compute the index of max voxel in concatenated volumes
mean@_div@_n : (a boolean)
        compute mean/nframes (good for var)
multiply@_by : (a float)
        Multiply input volume by some amount
multiply@_matrix@_file : (an existing file name)
        Multiply input by an ascii matrix in file
paired@_stats : ('sum' or 'avg' or 'diff' or 'diff-norm' or 'diff-norm1' or 'diff-norm2')
        Compute paired sum, avg, or diff
sign : ('abs' or 'pos' or 'neg')
        Take only pos or neg voxles from input, or take abs
sort : (a boolean)
        Sort each voxel by ascending frame value
stats : ('sum' or 'var' or 'std' or 'max' or 'min' or 'mean')
        Compute the sum, var, std, max, min or mean of the input volumes
subjects@_dir : (an existing directory name)
        subjects directory
vote : (a boolean)
        Most frequent value at each voxel and fraction of occurances
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
concatenated@_file : (an existing file name)
        Path/name of the output volume
\end{Verbatim}


\subsection{\texttt{GLMFit}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:glmfit}
Wraps command \textbf{mri\_glmfit}

Use FreeSurfer's mri\_glmfit to specify and estimate a general linear model.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{glmfit} \PYG{o}{=} \PYG{n}{GLMFit}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{glmfit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{glmfit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{one\PYGZus{}sample} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{glmfit}\PYG{o}{.}\PYG{n}{cmdline} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{mri\PYGZus{}glmfit --glmdir }\PYG{l+s+si}{\%s}\PYG{l+s}{ --y functional.nii --osgm}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{os}\PYG{o}{.}\PYG{n}{getcwd}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{True}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (a file name)
        input 4D file

@PYGZlb[]Optional@PYGZrb[]
allow@_ill@_cond : (a boolean)
        allow ill-conditioned design matrices
allow@_repeated@_subjects : (a boolean)
        allow subject names to repeat in the fsgd file (must appear before --fsgd
args : (a string)
        Additional parameters to the command
calc@_AR1 : (a boolean)
        compute and save temporal AR1 of residual
check@_opts : (a boolean)
        don't run anything, just check options and exit
compute@_log@_y : (a boolean)
        compute natural log of y prior to analysis
contrast : (an existing file name)
        contrast file
cortex : (a boolean)
        use subjects ?h.cortex.label as label
        exclusive: label@_file
debug : (a boolean)
        turn on debugging
design : (an existing file name)
        design matrix file
        exclusive: fsgd,design,one@_sample
diag : (an integer)
        Gdiag@_no : set diagnositc level
diag@_cluster : (a boolean)
        save sig volume and exit from first sim loop
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fixed@_fx@_dof : (an integer)
        dof for fixed effects analysis
        exclusive: fixed@_fx@_dof@_file
fixed@_fx@_dof@_file : (a file name)
        text file with dof for fixed effects analysis
        exclusive: fixed@_fx@_dof
fixed@_fx@_var : (an existing file name)
        for fixed effects analysis
force@_perm : (a boolean)
        force perumtation test, even when design matrix is not orthog
fsgd : (a tuple of the form: (an existing file name, 'doss' or 'dods'))
        freesurfer descriptor file
        exclusive: fsgd,design,one@_sample
fwhm : (a float)
        smooth input by fwhm
glm@_dir : (a string)
        save outputs to dir
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_mask : (a boolean)
        invert mask
label@_file : (an existing file name)
        use label as mask, surfaces only
        exclusive: cortex
mask@_file : (an existing file name)
        binary mask
no@_contrast@_sok : (a boolean)
        do not fail if no contrasts specified
no@_est@_fwhm : (a boolean)
        turn off FWHM output estimation
no@_mask@_smooth : (a boolean)
        do not mask when smoothing
no@_prune : (a boolean)
        do not prune
        exclusive: prunethresh
one@_sample : (a boolean)
        construct X and C as a one-sample group mean
        exclusive: one@_sample,fsgd,design,contrast
pca : (a boolean)
        perform pca/svd analysis on residual
per@_voxel@_reg : (an existing file name)
        per-voxel regressors
profile : (an integer)
        niters : test speed
prune : (a boolean)
        remove voxels that do not have a non-zero value at each frame (def)
prune@_thresh : (a float)
        prune threshold. Default is FLT@_MIN
        exclusive: noprune
resynth@_test : (an integer)
        test GLM by resynthsis
save@_cond : (a boolean)
        flag to save design matrix condition at each voxel
save@_estimate : (a boolean)
        save signal estimate (yhat)
save@_res@_corr@_mtx : (a boolean)
        save residual error spatial correlation matrix (eres.scm). Big!
save@_residual : (a boolean)
        save residual error (eres)
seed : (an integer)
        used for synthesizing noise
self@_reg : (a tuple of the form: (an integer, an integer, an integer))
        self-regressor from index col row slice
sim@_done@_file : (a file name)
        create file when simulation finished
sim@_sign : ('abs' or 'pos' or 'neg')
        abs, pos, or neg
simulation : (a tuple of the form: ('perm' or 'mc-full' or 'mc-z', an integer, a float, a string))
        nulltype nsim thresh csdbasename
subjects@_dir : (an existing directory name)
        subjects directory
surf : (a tuple of the form: (a string, 'lh' or 'rh', 'white' or 'pial' or 'smoothwm' or 'inflated'))
        needed for some flags (uses white by default)
synth : (a boolean)
        replace input with gaussian
uniform : (a tuple of the form: (a float, a float))
        use uniform distribution instead of gaussian
var@_fwhm : (a float)
        smooth variance by fwhm
vox@_dump : (a tuple of the form: (an integer, an integer, an integer))
        dump voxel GLM and exit
weight@_file : (an existing file name)
        weight for each input at each voxel
        exclusive: weighted@_ls
weight@_inv : (a boolean)
        invert weights
        exclusive: weighted@_ls
weight@_sqrt : (a boolean)
        sqrt of weights
        exclusive: weighted@_ls
weighted@_ls : (an existing file name)
        weighted least squares
        exclusive: weight@_file,weight@_inv,weight@_sqrt
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
beta@_file : (an existing file name)
        map of regression coefficients
dof@_file : (a file name)
        text file with effective degrees-of-freedom for the analysis
error@_file : (a file name)
        map of residual error
error@_stddev@_file : (a file name)
        map of residual error standard deviation
error@_var@_file : (a file name)
        map of residual error variance
estimate@_file : (a file name)
        map of the estimated Y values
frame@_eigenvectors : (a file name)
        matrix of frame eigenvectors from residual PCA
ftest@_file      map of test statistic values
fwhm@_file : (a file name)
        text file with estimated smoothness
gamma@_file      map of contrast of regression coefficients
gamma@_var@_file  map of regression contrast variance
glm@_dir : (an existing directory name)
        output directory
mask@_file : (a file name)
        map of the mask used in the analysis
sig@_file        map of F-test significance (in -log10p)
singular@_values : (a file name)
        matrix singular values from residual PCA
spatial@_eigenvectors : (a file name)
        map of spatial eigenvectors from residual PCA
svd@_stats@_file : (a file name)
        text file summarizing the residual PCA
\end{Verbatim}


\subsection{\texttt{Label2Vol}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:label2vol}
Wraps command \textbf{mri\_label2vol}

Make a binary volume from a Freesurfer label


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{binvol} \PYG{o}{=} \PYG{n}{Label2Vol}\PYG{p}{(}\PYG{n}{label\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{cortex.label}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{template\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{reg\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{register.dat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{fill\PYGZus{}thresh}\PYG{o}{=}\PYG{l+m+mf}{0.5}\PYG{p}{,} \PYG{n}{vol\PYGZus{}label\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo\PYGZus{}out.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{binvol}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}label2vol --fillthresh 0 --label cortex.label --reg register.dat --temp structural.nii --o foo\PYGZus{}out.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
annot@_file : (an existing file name)
        surface annotation file
        exclusive: label@_file,annot@_file,seg@_file,aparc@_aseg
        requires: subjectid,hemi
aparc@_aseg : (a boolean)
        use aparc+aseg.mgz in subjectdir as seg
        exclusive: label@_file,annot@_file,seg@_file,aparc@_aseg
label@_file : (an existing file name)
        list of label files
        exclusive: label@_file,annot@_file,seg@_file,aparc@_aseg
seg@_file : (an existing file name)
        segmentation file
        exclusive: label@_file,annot@_file,seg@_file,aparc@_aseg
template@_file : (an existing file name)
        output template volume

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fill@_thresh : (0.0 @textless[]= a floating point number @textless[]= 1.0)
        thresh : between 0 and 1
hemi : ('lh' or 'rh')
        hemisphere to use lh or rh
identity : (a boolean)
        set R=I
        exclusive: reg@_file,reg@_header,identity
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_mtx : (a boolean)
        Invert the registration matrix
label@_hit@_file : (a file name)
        file with each frame is nhits for a label
label@_voxel@_volume : (a float)
        volume of each label point (def 1mm3)
map@_label@_stat : (a file name)
        map the label stats field into the vol
native@_vox2ras : (a boolean)
        use native vox2ras xform instead of  tkregister-style
proj : (a tuple of the form: ('abs' or 'frac', a float, a float, a float))
        project along surface normal
reg@_file : (an existing file name)
        tkregister style matrix VolXYZ = R*LabelXYZ
        exclusive: reg@_file,reg@_header,identity
reg@_header : (an existing file name)
        label template volume
        exclusive: reg@_file,reg@_header,identity
subject@_id : (a string)
        subject id
subjects@_dir : (an existing directory name)
        subjects directory
surface : (a string)
        use surface instead of white
vol@_label@_file : (a file name)
        output volume
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
vol@_label@_file : (an existing file name)
        output volume
\end{Verbatim}


\subsection{\texttt{MRISPreproc}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:mrispreproc}
Wraps command \textbf{mris\_preproc}

Use FreeSurfer mris\_preproc to prepare a group of contrasts for
a second level analysis


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{MRISPreproc}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{target} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsaverage}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{lh}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{vol\PYGZus{}measure\PYGZus{}file} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{register.dat}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}                                            \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{cont1a.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{register.dat}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{concatenated\PYGZus{}file.mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mris\PYGZus{}preproc --hemi lh --out concatenated\PYGZus{}file.mgz --target fsaverage --iv cont1.nii register.dat --iv cont1a.nii register.dat'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
hemi : ('lh' or 'rh')
        hemisphere for source and target
target : (a string)
        target subject name

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fsgd@_file : (an existing file name)
        specify subjects using fsgd file
        exclusive: subjects,fsgd@_file,subject@_file
fwhm : (a float)
        smooth by fwhm mm on the target surface
        exclusive: num@_iters
fwhm@_source : (a float)
        smooth by fwhm mm on the source surface
        exclusive: num@_iters@_source
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
num@_iters : (an integer)
        niters : smooth by niters on the target surface
        exclusive: fwhm
num@_iters@_source : (an integer)
        niters : smooth by niters on the source surface
        exclusive: fwhm@_source
out@_file : (a file name)
        output filename
proj@_frac : (a float)
        projection fraction for vol2surf
smooth@_cortex@_only : (a boolean)
        only smooth cortex (ie, exclude medial wall)
source@_format : (a string)
        source format
subject@_file : (an existing file name)
        file specifying subjects separated by white space
        exclusive: subjects,fsgd@_file,subject@_file
subjects : (a list of items which are any value)
        subjects from who measures are calculated
        exclusive: subjects,fsgd@_file,subject@_file
subjects@_dir : (an existing directory name)
        subjects directory
surf@_area : (a string)
        Extract vertex area from subject/surf/hemi.surfname to use as input.
        exclusive: surf@_measure,surf@_measure@_file,surf@_area
surf@_dir : (a string)
        alternative directory (instead of surf)
surf@_measure : (a string)
        Use subject/surf/hemi.surf@_measure as input
        exclusive: surf@_measure,surf@_measure@_file,surf@_area
surf@_measure@_file : (an existing file name)
        file alternative to surfmeas, still requires list of subjects
        exclusive: surf@_measure,surf@_measure@_file,surf@_area
vol@_measure@_file : (a tuple of the form: (an existing file name, an existing file name))
        list of volume measure and reg file tuples
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        preprocessed output file
\end{Verbatim}


\subsection{\texttt{OneSampleTTest}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:onesamplettest}
Wraps command \textbf{mri\_glmfit}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (a file name)
        input 4D file

@PYGZlb[]Optional@PYGZrb[]
allow@_ill@_cond : (a boolean)
        allow ill-conditioned design matrices
allow@_repeated@_subjects : (a boolean)
        allow subject names to repeat in the fsgd file (must appear before --fsgd
args : (a string)
        Additional parameters to the command
calc@_AR1 : (a boolean)
        compute and save temporal AR1 of residual
check@_opts : (a boolean)
        don't run anything, just check options and exit
compute@_log@_y : (a boolean)
        compute natural log of y prior to analysis
contrast : (an existing file name)
        contrast file
cortex : (a boolean)
        use subjects ?h.cortex.label as label
        exclusive: label@_file
debug : (a boolean)
        turn on debugging
design : (an existing file name)
        design matrix file
        exclusive: fsgd,design,one@_sample
diag : (an integer)
        Gdiag@_no : set diagnositc level
diag@_cluster : (a boolean)
        save sig volume and exit from first sim loop
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fixed@_fx@_dof : (an integer)
        dof for fixed effects analysis
        exclusive: fixed@_fx@_dof@_file
fixed@_fx@_dof@_file : (a file name)
        text file with dof for fixed effects analysis
        exclusive: fixed@_fx@_dof
fixed@_fx@_var : (an existing file name)
        for fixed effects analysis
force@_perm : (a boolean)
        force perumtation test, even when design matrix is not orthog
fsgd : (a tuple of the form: (an existing file name, 'doss' or 'dods'))
        freesurfer descriptor file
        exclusive: fsgd,design,one@_sample
fwhm : (a float)
        smooth input by fwhm
glm@_dir : (a string)
        save outputs to dir
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_mask : (a boolean)
        invert mask
label@_file : (an existing file name)
        use label as mask, surfaces only
        exclusive: cortex
mask@_file : (an existing file name)
        binary mask
no@_contrast@_sok : (a boolean)
        do not fail if no contrasts specified
no@_est@_fwhm : (a boolean)
        turn off FWHM output estimation
no@_mask@_smooth : (a boolean)
        do not mask when smoothing
no@_prune : (a boolean)
        do not prune
        exclusive: prunethresh
one@_sample : (a boolean)
        construct X and C as a one-sample group mean
        exclusive: one@_sample,fsgd,design,contrast
pca : (a boolean)
        perform pca/svd analysis on residual
per@_voxel@_reg : (an existing file name)
        per-voxel regressors
profile : (an integer)
        niters : test speed
prune : (a boolean)
        remove voxels that do not have a non-zero value at each frame (def)
prune@_thresh : (a float)
        prune threshold. Default is FLT@_MIN
        exclusive: noprune
resynth@_test : (an integer)
        test GLM by resynthsis
save@_cond : (a boolean)
        flag to save design matrix condition at each voxel
save@_estimate : (a boolean)
        save signal estimate (yhat)
save@_res@_corr@_mtx : (a boolean)
        save residual error spatial correlation matrix (eres.scm). Big!
save@_residual : (a boolean)
        save residual error (eres)
seed : (an integer)
        used for synthesizing noise
self@_reg : (a tuple of the form: (an integer, an integer, an integer))
        self-regressor from index col row slice
sim@_done@_file : (a file name)
        create file when simulation finished
sim@_sign : ('abs' or 'pos' or 'neg')
        abs, pos, or neg
simulation : (a tuple of the form: ('perm' or 'mc-full' or 'mc-z', an integer, a float, a string))
        nulltype nsim thresh csdbasename
subjects@_dir : (an existing directory name)
        subjects directory
surf : (a tuple of the form: (a string, 'lh' or 'rh', 'white' or 'pial' or 'smoothwm' or 'inflated'))
        needed for some flags (uses white by default)
synth : (a boolean)
        replace input with gaussian
uniform : (a tuple of the form: (a float, a float))
        use uniform distribution instead of gaussian
var@_fwhm : (a float)
        smooth variance by fwhm
vox@_dump : (a tuple of the form: (an integer, an integer, an integer))
        dump voxel GLM and exit
weight@_file : (an existing file name)
        weight for each input at each voxel
        exclusive: weighted@_ls
weight@_inv : (a boolean)
        invert weights
        exclusive: weighted@_ls
weight@_sqrt : (a boolean)
        sqrt of weights
        exclusive: weighted@_ls
weighted@_ls : (an existing file name)
        weighted least squares
        exclusive: weight@_file,weight@_inv,weight@_sqrt
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
beta@_file : (an existing file name)
        map of regression coefficients
dof@_file : (a file name)
        text file with effective degrees-of-freedom for the analysis
error@_file : (a file name)
        map of residual error
error@_stddev@_file : (a file name)
        map of residual error standard deviation
error@_var@_file : (a file name)
        map of residual error variance
estimate@_file : (a file name)
        map of the estimated Y values
frame@_eigenvectors : (a file name)
        matrix of frame eigenvectors from residual PCA
ftest@_file      map of test statistic values
fwhm@_file : (a file name)
        text file with estimated smoothness
gamma@_file      map of contrast of regression coefficients
gamma@_var@_file  map of regression contrast variance
glm@_dir : (an existing directory name)
        output directory
mask@_file : (a file name)
        map of the mask used in the analysis
sig@_file        map of F-test significance (in -log10p)
singular@_values : (a file name)
        matrix singular values from residual PCA
spatial@_eigenvectors : (a file name)
        map of spatial eigenvectors from residual PCA
svd@_stats@_file : (a file name)
        text file summarizing the residual PCA
\end{Verbatim}


\subsection{\texttt{SegStats}}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:segstats}
Wraps command \textbf{mri\_segstats}

Use FreeSurfer mri\_segstats for ROI analysis


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.model:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{SegStats}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{annot} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{PWS04}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{lh}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{aparc}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{avgwf\PYGZus{}txt\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{./avgwf.txt}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{summary\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{./summary.stats}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ss}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}segstats --annot PWS04 lh aparc --avgwf ./avgwf.txt --i functional.nii --sum ./summary.stats'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
annot : (a tuple of the form: (a string, 'lh' or 'rh', a string))
        subject hemi parc : use surface parcellation
        exclusive: segmentation@_file,annot,surf@_label
segmentation@_file : (an existing file name)
        segmentation volume path
        exclusive: segmentation@_file,annot,surf@_label
surf@_label : (a tuple of the form: (a string, 'lh' or 'rh', a string))
        subject hemi label : use surface label
        exclusive: segmentation@_file,annot,surf@_label

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
avgwf@_file : (a boolean or a file name)
        Save as binary volume (bool or filename)
avgwf@_txt@_file : (a boolean or a file name)
        Save average waveform into file (bool or filename)
brain@_vol : ('brain-vol-from-seg' or 'brainmask' or '--@%s')
        Compute brain volume either with []`[]`brainmask[]`[]` or []`[]`brain-vol-from-seg[]`[]`
calc@_power : ('sqr' or 'sqrt')
        Compute either the sqr or the sqrt of the input
calc@_snr : (a boolean)
        save mean/std as extra column in output table
color@_table@_file : (an existing file name)
        color table file with seg id names
        exclusive: color@_table@_file,default@_color@_table,gca@_color@_table
cortex@_vol@_from@_surf : (a boolean)
        Compute cortex volume from surf
default@_color@_table : (a boolean)
        use @$FREESURFER@_HOME/FreeSurferColorLUT.txt
        exclusive: color@_table@_file,default@_color@_table,gca@_color@_table
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
etiv : (a boolean)
        Compute ICV from talairach transform
etiv@_only : ('etiv' or 'old-etiv' or '--@%s-only')
        Compute etiv and exit.  Use []`[]`etiv[]`[]` or []`[]`old-etiv[]`[]`
exclude@_ctx@_gm@_wm : (a boolean)
        exclude cortical gray and white matter
exclude@_id : (an integer)
        Exclude seg id from report
frame : (an integer)
        Report stats on nth frame of input volume
gca@_color@_table : (an existing file name)
        get color table from GCA (CMA)
        exclusive: color@_table@_file,default@_color@_table,gca@_color@_table
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file : (an existing file name)
        Use the segmentation to report stats on this volume
mask@_erode : (an integer)
        Erode mask by some amount
mask@_file : (an existing file name)
        Mask volume (same size as seg
mask@_frame : (an integer)
        Mask with this (0 based) frame of the mask volume
        requires: mask@_file
mask@_invert : (a boolean)
        Invert binarized mask volume
mask@_sign : ('abs' or 'pos' or 'neg' or '--masksign @%s')
        Sign for mask threshold: pos, neg, or abs
mask@_thresh : (a float)
        binarize mask with this threshold @textless[]0.5@textgreater[]
multiply : (a float)
        multiply input by val
non@_empty@_only : (a boolean)
        Only report nonempty segmentations
partial@_volume@_file : (an existing file name)
        Compensate for partial voluming
segment@_id : (a list of items which are any value)
        Manually specify segmentation ids
sf@_avg@_file : (a boolean or a file name)
        Save mean across space and time
subjects@_dir : (an existing directory name)
        subjects directory
summary@_file : (a file name)
        Segmentation stats summary table file
vox : (a list of items which are an integer)
        Replace seg with all 0s except at C R S (three int inputs)
wm@_vol@_from@_surf : (a boolean)
        Compute wm volume from surf
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
avgwf@_file : (a file name)
        Volume with functional statistics averaged over segs
avgwf@_txt@_file : (a file name)
        Text file with functional statistics averaged over segs
sf@_avg@_file : (a file name)
        Text file with func statistics averaged over segs and framss
summary@_file : (an existing file name)
        Segmentation summary statistics table
\end{Verbatim}


\section{nipype.interfaces.freesurfer.preprocess}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess::doc}\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:nipype-interfaces-freesurfer-preprocess}

\subsection{\texttt{ApplyVolTransform}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:applyvoltransform}
Wraps command \textbf{mri\_vol2vol}

Use FreeSurfer mri\_vol2vol to apply a transform.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{ApplyVolTransform}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg} \PYG{o}{=} \PYG{n}{ApplyVolTransform}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{reg\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{register.dat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{transformed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{struct\PYGZus{}warped.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fs\PYGZus{}target} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyreg}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}vol2vol --fstarg --reg register.dat --mov structural.nii --o struct\PYGZus{}warped.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
fs@_target : (a boolean)
        use orig.mgz from subject in regfile as target
        exclusive: target@_file,tal,fs@_target
        requires: reg@_file
fsl@_reg@_file : (an existing file name)
        fslRAS-to-fslRAS matrix (FSL format)
        exclusive: reg@_file,fsl@_reg@_file,xfm@_reg@_file,reg@_header,subject
reg@_file : (an existing file name)
        tkRAS-to-tkRAS matrix   (tkregister2 format)
        exclusive: reg@_file,fsl@_reg@_file,xfm@_reg@_file,reg@_header,subject
reg@_header : (a boolean)
        ScannerRAS-to-ScannerRAS matrix = identity
        exclusive: reg@_file,fsl@_reg@_file,xfm@_reg@_file,reg@_header,subject
source@_file : (an existing file name)
        Input volume you wish to transform
subject : (a string)
        set matrix = identity and use subject for any templates
        exclusive: reg@_file,fsl@_reg@_file,xfm@_reg@_file,reg@_header,subject
tal : (a boolean)
        map to a sub FOV of MNI305 (with --reg only)
        exclusive: target@_file,tal,fs@_target
target@_file : (an existing file name)
        Output template volume
        exclusive: target@_file,tal,fs@_target
xfm@_reg@_file : (an existing file name)
        ScannerRAS-to-ScannerRAS matrix (MNI format)
        exclusive: reg@_file,fsl@_reg@_file,xfm@_reg@_file,reg@_header,subject

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
interp : ('trilin' or 'nearest')
        Interpolation method (@textless[]trilin@textgreater[] or nearest)
inverse : (a boolean)
        sample from target to source
no@_resample : (a boolean)
        Do not resample; just change vox2ras matrix
subjects@_dir : (an existing directory name)
        subjects directory
transformed@_file : (a file name)
        Output volume
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
transformed@_file : (an existing file name)
        Path to output file if used normally
\end{Verbatim}


\subsection{\texttt{BBRegister}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:bbregister}
Wraps command \textbf{bbregister}

Use FreeSurfer bbregister to register a volume to the Freesurfer anatomical.

This program performs within-subject, cross-modal registration using a
boundary-based cost function. The registration is constrained to be 6
DOF (rigid). It is required that you have an anatomical scan of the
subject that has already been recon-all-ed using freesurfer.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{BBRegister}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bbreg} \PYG{o}{=} \PYG{n}{BBRegister}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{me}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{source\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{init}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{header}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{contrast\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{t2}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bbreg}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'bbregister --t2 --init-header --reg structural\PYGZus{}bbreg\PYGZus{}me.dat --mov structural.nii --s me'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
contrast@_type : ('t1' or 't2')
        contrast type of image
init : ('spm' or 'fsl' or 'header')
        initialize registration spm, fsl, header
        exclusive: init@_reg@_file
init@_reg@_file : (an existing file name)
        existing registration file
        exclusive: init
source@_file : (a file name)
        source file to be registered
subject@_id : (a string)
        freesurfer subject id

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
epi@_mask : (a boolean)
        mask out B0 regions in stages 1 and 2
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_fsl@_file : (a boolean or a file name)
        write the transformation matrix in FSL FLIRT format
out@_reg@_file : (a file name)
        output registration file
registered@_file : (a boolean or a file name)
        output warped sourcefile either True or filename
spm@_nifti : (a boolean)
        force use of nifti rather than analyze with SPM
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
min@_cost@_file : (an existing file name)
        Output registration minimum cost file
out@_fsl@_file : (a file name)
        Output FLIRT-style registration file
out@_reg@_file : (an existing file name)
        Output registration file
registered@_file : (a file name)
        Registered and resampled source file
\end{Verbatim}


\subsection{\texttt{DICOMConvert}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:dicomconvert}
Wraps command \textbf{mri\_convert}

use fs mri\_convert to convert dicom files


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{DICOMConvert}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt} \PYG{o}{=} \PYG{n}{DICOMConvert}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dicom\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{dicomdir}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cvt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{file\PYGZus{}mapping} \PYG{o}{=} \PYG{p}{[}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{nifti}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{*.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{info}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{dicom*.txt}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dti}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{*dti.bv*}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{]}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
base@_output@_dir : (a directory name)
        directory in which subject directories are created
dicom@_dir : (an existing directory name)
        dicom directory from which to convert dicom files

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dicom@_info : (an existing file name)
        File containing summary information from mri@_parse@_sdcmdir
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
file@_mapping : (a list of items which are a tuple of the form: (a string, a string))
        defines the output fields of interface
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
ignore@_single@_slice : (a boolean)
        ignore volumes containing a single slice
        requires: dicom@_info
out@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz')
        defines the type of output file produced
seq@_list : (a list of items which are a string)
        list of pulse sequence names to be converted.
        requires: dicom@_info
subject@_dir@_template : (a string)
        template for subject directory name
subject@_id      subject identifier to insert into template
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}


\subsection{\texttt{FitMSParams}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:fitmsparams}
Wraps command \textbf{mri\_ms\_fitparms}

Estimate tissue paramaters from a set of FLASH images.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{FitMSParams}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{msfit} \PYG{o}{=} \PYG{n}{FitMSParams}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{msfit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{flash\PYGZus{}05.mgz}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{flash\PYGZus{}30.mgz}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{msfit}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{flash\PYGZus{}parameters}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{msfit}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}ms\PYGZus{}fitparms  flash\PYGZus{}05.mgz flash\PYGZus{}30.mgz flash\PYGZus{}parameters'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of items which are a file name)
        list of FLASH images (must be in mgh format)

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
flip@_list : (a list of items which are an integer)
        list of flip angles of the input files
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_dir : (a directory name)
        directory to store output in
subjects@_dir : (an existing directory name)
        subjects directory
te@_list : (a list of items which are a float)
        list of TEs of the input files (in msec)
tr@_list : (a list of items which are an integer)
        list of TRs of the input files (in msec)
xfm@_list : (a list of items which are a file name)
        list of transform files to apply to each FLASH image
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
pd@_image : (an existing file name)
        image of estimated proton density values
t1@_image : (an existing file name)
        image of estimated T1 relaxation values
t2star@_image : (an existing file name)
        image of estimated T2* values
\end{Verbatim}


\subsection{\texttt{MRIConvert}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:mriconvert}
Wraps command \textbf{mri\_convert}

use fs mri\_convert to manipulate files

\begin{notice}{note}{Note:}
Adds niigz as an output type option
\end{notice}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mc} \PYG{o}{=} \PYG{n}{MRIConvert}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{outfile.mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mc}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}convert --out\PYGZus{}type mgz --input\PYGZus{}volume structural.nii --output\PYGZus{}volume outfile.mgz'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        File to read/convert

@PYGZlb[]Optional@PYGZrb[]
apply@_inv@_transform : (an existing file name)
        apply inverse transformation xfm file
apply@_transform : (an existing file name)
        apply xfm file
args : (a string)
        Additional parameters to the command
ascii : (a boolean)
        save output as ascii col@textgreater[]row@textgreater[]slice@textgreater[]frame
autoalign@_matrix : (an existing file name)
        text file with autoalign matrix
color@_file : (an existing file name)
        color file
conform : (a boolean)
        conform to 256@textasciicircum[]3
conform@_min : (a boolean)
        conform to smallest size
conform@_size : (a float)
        conform to size@_in@_mm
crop@_center : (a tuple of the form: (an integer, an integer, an integer))
        @textless[]x@textgreater[] @textless[]y@textgreater[] @textless[]z@textgreater[] crop to 256 around center (x,y,z)
crop@_gdf : (a boolean)
        apply GDF cropping
crop@_size : (a tuple of the form: (an integer, an integer, an integer))
        @textless[]dx@textgreater[] @textless[]dy@textgreater[] @textless[]dz@textgreater[] crop to size @textless[]dx, dy, dz@textgreater[]
cut@_ends : (an integer)
        remove ncut slices from the ends
devolve@_transform : (a string)
        subject id
drop@_n : (an integer)
        drop the last n frames
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fill@_parcellation : (a boolean)
        fill parcellation
force@_ras : (a boolean)
        use default when orientation info absent
frame : (an integer)
        keep only 0-based frame number
frame@_subsample : (a tuple of the form: (an integer, an integer, an integer))
        start delta end : frame subsampling (end = -1 for end)
fwhm : (a float)
        smooth input volume by fwhm mm
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_center : (a list of at most 3 items which are a float)
        @textless[]R coordinate@textgreater[] @textless[]A coordinate@textgreater[] @textless[]S coordinate@textgreater[]
in@_i@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
in@_i@_size : (an integer)
        input i size
in@_info : (a boolean)
        display input info
in@_j@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
in@_j@_size : (an integer)
        input j size
in@_k@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
in@_k@_size : (an integer)
        input k size
in@_like : (an existing file name)
        input looks like
in@_matrix : (a boolean)
        display input matrix
in@_orientation : ('LAI' or 'LIA' or 'ALI' or 'AIL' or 'ILA' or 'IAL' or 'LAS' or 'LSA' or 'ALS' or 'ASL' or 'SLA' or 'SAL' or 'LPI' or 'LIP' or 'PLI' or 'PIL' or 'ILP' or 'IPL' or 'LPS' or 'LSP' or 'PLS' or 'PSL' or 'SLP' or 'SPL' or 'RAI' or 'RIA' or 'ARI' or 'AIR' or 'IRA' or 'IAR' or 'RAS' or 'RSA' or 'ARS' or 'ASR' or 'SRA' or 'SAR' or 'RPI' or 'RIP' or 'PRI' or 'PIR' or 'IRP' or 'IPR' or 'RPS' or 'RSP' or 'PRS' or 'PSR' or 'SRP' or 'SPR')
        specify the input orientation
in@_scale : (a float)
        input intensity scale factor
in@_stats : (a boolean)
        display input stats
in@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz' or 'ge' or 'gelx' or 'lx' or 'ximg' or 'siemens' or 'dicom' or 'siemens@_dicom')
        input file type
invert@_contrast : (a float)
        threshold for inversting contrast
midframe : (a boolean)
        keep only the middle frame
no@_change : (a boolean)
        don't change type of input to that of template
no@_scale : (a boolean)
        dont rescale values for COR
no@_translate : (a boolean)
        ???
no@_write : (a boolean)
        do not write output
out@_center : (a tuple of the form: (a float, a float, a float))
        @textless[]R coordinate@textgreater[] @textless[]A coordinate@textgreater[] @textless[]S coordinate@textgreater[]
out@_datatype : ('uchar' or 'short' or 'int' or 'float')
        Unknown
out@_file : (a file name)
        output filename or True to generate one
out@_i@_count : (an integer)
        some count ?? in i direction
out@_i@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
out@_i@_size : (an integer)
        output i size
out@_info : (a boolean)
        display output info
out@_j@_count : (an integer)
        some count ?? in j direction
out@_j@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
out@_j@_size : (an integer)
        output j size
out@_k@_count : (an integer)
        some count ?? in k direction
out@_k@_dir : (a tuple of the form: (a float, a float, a float))
        @textless[]R direction@textgreater[] @textless[]A direction@textgreater[] @textless[]S direction@textgreater[]
out@_k@_size : (an integer)
        output k size
out@_matrix : (a boolean)
        display output matrix
out@_orientation : ('LAI' or 'LIA' or 'ALI' or 'AIL' or 'ILA' or 'IAL' or 'LAS' or 'LSA' or 'ALS' or 'ASL' or 'SLA' or 'SAL' or 'LPI' or 'LIP' or 'PLI' or 'PIL' or 'ILP' or 'IPL' or 'LPS' or 'LSP' or 'PLS' or 'PSL' or 'SLP' or 'SPL' or 'RAI' or 'RIA' or 'ARI' or 'AIR' or 'IRA' or 'IAR' or 'RAS' or 'RSA' or 'ARS' or 'ASR' or 'SRA' or 'SAR' or 'RPI' or 'RIP' or 'PRI' or 'PIR' or 'IRP' or 'IPR' or 'RPS' or 'RSP' or 'PRS' or 'PSR' or 'SRP' or 'SPR')
        specify the output orientation
out@_scale : (a float)
        output intensity scale factor
out@_stats : (a boolean)
        display output stats
out@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz')
        output file type
parse@_only : (a boolean)
        parse input only
read@_only : (a boolean)
        read the input volume
reorder : (a tuple of the form: (an integer, an integer, an integer))
        olddim1 olddim2 olddim3
resample@_type : ('interpolate' or 'weighted' or 'nearest' or 'sinc' or 'cubic')
        @textless[]interpolate@textbar[]weighted@textbar[]nearest@textbar[]sinc@textbar[]cubic@textgreater[] (default is interpolate)
reslice@_like : (an existing file name)
        reslice output to match file
sdcm@_list : (an existing file name)
        list of DICOM files for conversion
skip@_n : (an integer)
        skip the first n frames
slice@_bias : (a float)
        apply half-cosine bias field
slice@_crop : (a tuple of the form: (an integer, an integer))
        s@_start s@_end : keep slices s@_start to s@_end
slice@_reverse : (a boolean)
        reverse order of slices, update vox2ras
smooth@_parcellation : (a boolean)
        smooth parcellation
sphinx : (a boolean)
        change orientation info to sphinx
split : (a boolean)
        split output frames into separate output files.
status@_file : (a file name)
        status file for DICOM conversion
subject@_name : (a string)
        subject name ???
subjects@_dir : (an existing directory name)
        subjects directory
template@_info : (a boolean)
        dump info about template
template@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz' or 'ge' or 'gelx' or 'lx' or 'ximg' or 'siemens' or 'dicom' or 'siemens@_dicom')
        template file type
unwarp@_gradient : (a boolean)
        unwarp gradient nonlinearity
vox@_size : (a tuple of the form: (a float, a float, a float))
        @textless[]size@_x@textgreater[] @textless[]size@_y@textgreater[] @textless[]size@_z@textgreater[] specify the size (mm) - useful for upsampling or downsampling
zero@_ge@_z@_offset : (a boolean)
        zero ge z offset ???
zero@_outlines : (a boolean)
        zero outlines
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        converted output file
\end{Verbatim}


\subsection{\texttt{ParseDICOMDir}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:parsedicomdir}
Wraps command \textbf{mri\_parse\_sdcmdir}

Uses mri\_parse\_sdcmdir to get information from dicom directories


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{ParseDICOMDir}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dcminfo} \PYG{o}{=} \PYG{n}{ParseDICOMDir}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dcminfo}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dicom\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dcminfo}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sortbyrun} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dcminfo}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{summarize} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dcminfo}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}parse\PYGZus{}sdcmdir --d . --o dicominfo.txt --sortbyrun --summarize'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
dicom@_dir : (an existing directory name)
        path to siemens dicom directory

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dicom@_info@_file : (a file name)
        file to which results are written
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
sortbyrun : (a boolean)
        assign run numbers
subjects@_dir : (an existing directory name)
        subjects directory
summarize : (a boolean)
        only print out info for run leaders
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dicom@_info@_file : (an existing file name)
        text file containing dicom information
\end{Verbatim}


\subsection{\texttt{ReconAll}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:reconall}
Wraps command \textbf{recon-all}

Uses recon-all to generate surfaces and parcellations of structural data
from anatomical images of a subject.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{ReconAll}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall} \PYG{o}{=} \PYG{n}{ReconAll}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{directive} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{all}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subjects\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{T1\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reconall}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'recon-all -i structural.nii -all -subjid foo -sd .'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
T1@_files : (an existing file name)
        name of T1 file to process
args : (a string)
        Additional parameters to the command
directive : ('all' or 'autorecon1' or 'autorecon2' or 'autorecon2-cp' or 'autorecon2-wm' or 'autorecon2-inflate1' or 'autorecon2-perhemi' or 'autorecon3' or 'localGI' or 'qcache')
        process directive
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
flags : (a string)
        additional parameters
hemi : ('lh' or 'rh')
        hemisphere to process
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
subject@_id : (a string)
        subject name
subjects@_dir : (an existing directory name)
        path to subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
T1 : (an existing file name)
        Intensity normalized whole-head volume
annot : (an existing file name)
        Surface annotation files
aparc@_aseg : (an existing file name)
        Aparc parcellation projected into aseg volume
aseg : (an existing file name)
        Volumetric map of regions from automatic segmentation
brain : (an existing file name)
        Intensity normalized brain-only volume
brainmask : (an existing file name)
        Skull-stripped (brain-only) volume
curv : (an existing file name)
        Maps of surface curvature
filled : (an existing file name)
        Subcortical mass volume
inflated : (an existing file name)
        Inflated surface meshes
label : (an existing file name)
        Volume and surface label files
norm : (an existing file name)
        Normalized skull-stripped volume
nu : (an existing file name)
        Non-uniformity corrected whole-head volume
orig : (an existing file name)
        Base image conformed to Freesurfer space
pial : (an existing file name)
        Gray matter/pia mater surface meshes
rawavg : (an existing file name)
        Volume formed by averaging input images
ribbon : (an existing file name)
        Volumetric maps of cortical ribbons
smoothwm : (an existing file name)
        Smoothed original surface meshes
sphere : (an existing file name)
        Spherical surface meshes
sphere@_reg : (an existing file name)
        Spherical registration file
subject@_id : (a string)
        Subject name for whom to retrieve data
subjects@_dir : (an existing directory name)
        Freesurfer subjects directory.
sulc : (an existing file name)
        Surface maps of sulcal depth
thickness : (an existing file name)
        Surface maps of cortical thickness
volume : (an existing file name)
        Surface maps of cortical volume
white : (an existing file name)
        White/gray matter surface meshes
wm : (an existing file name)
        Segmented white-matter volume
wmparc : (an existing file name)
        Aparc parcellation projected into subcortical white matter
\end{Verbatim}


\subsection{\texttt{Resample}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:resample}
Wraps command \textbf{mri\_convert}

Use FreeSurfer mri\_convert to up or down-sample image files


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{freesurfer}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{resampler} \PYG{o}{=} \PYG{n}{freesurfer}\PYG{o}{.}\PYG{n}{Resample}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{resampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{resampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{resampled\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{resampled.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{resampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{voxel\PYGZus{}size} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mf}{2.1}\PYG{p}{,} \PYG{l+m+mf}{2.1}\PYG{p}{,} \PYG{l+m+mf}{2.1}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{resampler}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}convert -vs 2.10 2.10 2.10 -i structural.nii -o resampled.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        file to resample
voxel@_size : (a tuple of the form: (a float, a float, a float))
        triplet of output voxel sizes

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
resampled@_file : (a file name)
        output filename
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
resampled@_file : (an existing file name)
        output filename
\end{Verbatim}


\subsection{\texttt{RobustRegister}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:robustregister}
Wraps command \textbf{mri\_robust\_register}

Perform intramodal linear registration (translation and rotation) using robust statistics.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id8}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{RobustRegister}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg} \PYG{o}{=} \PYG{n}{RobustRegister}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{target\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{T1.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{auto\PYGZus{}sens} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{init\PYGZus{}orient} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{reg}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}robust\PYGZus{}register --satit --initorient --lta structural\PYGZus{}robustreg.lta --mov structural.nii --dst T1.nii'}
\end{Verbatim}


\subsubsection{References}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:references}
Reuter, M, Rosas, HD, and Fischl, B, (2010). Highly Accurate Inverse Consistent Registration:
A Robust Approach.  Neuroimage 53(4) 1181-96.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
auto@_sens : (a boolean)
        auto-detect good sensitivity
        exclusive: outlier@_sens
outlier@_sens : (a float)
        set outlier sensitivity explicitly
        exclusive: auto@_sens
source@_file : (a file name)
        volume to be registered
target@_file : (a file name)
        target volume for the registration

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
est@_int@_scale : (a boolean)
        estimate intensity scale (recommended for unnormalized images)
force@_double : (a boolean)
        use double-precision intensities
force@_float : (a boolean)
        use float intensities
half@_source : (a boolean or a file name)
        write source volume mapped to halfway space
half@_source@_xfm : (a boolean or a file name)
        write transform from source to halfway space
half@_targ : (a boolean or a file name)
        write target volume mapped to halfway space
half@_targ@_xfm : (a boolean or a file name)
        write transform from target to halfway space
half@_weights : (a boolean or a file name)
        write weights volume mapped to halfway space
high@_iterations : (an integer)
        max @# of times on highest resolution
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_xfm@_file : (an existing file name)
        use initial transform on source
init@_orient : (a boolean)
        use moments for initial orient (recommended for stripped brains)
iteration@_thresh : (a float)
        stop iterations when below threshold
least@_squares : (a boolean)
        use least squares instead of robust estimator
mask@_source : (an existing file name)
        image to mask source volume with
mask@_target : (an existing file name)
        image to mask target volume with
max@_iterations : (an integer)
        maximum @# of times on each resolution
no@_init : (a boolean)
        skip transform init
no@_multi : (a boolean)
        work on highest resolution
out@_reg@_file : (a file name)
        registration file to write
outlier@_limit : (a float)
        set maximal outlier limit in satit
registered@_file : (a boolean or a file name)
        registered image; either True or filename
subjects@_dir : (an existing directory name)
        subjects directory
subsample@_thresh : (an integer)
        subsample if dimension is above threshold size
trans@_only : (a boolean)
        find 3 parameter translation only
weights@_file : (a boolean or a file name)
        weights image to write; either True or filename
write@_vo2vox : (a boolean)
        output vox2vox matrix (default is RAS2RAS)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
half@_source : (a file name)
        source image mapped to halfway space
half@_source@_xfm : (a file name)
        transform file to map source image to halfway space
half@_targ : (a file name)
        target image mapped to halfway space
half@_targ@_xfm : (a file name)
        transform file to map target image to halfway space
half@_weights : (a file name)
        weights image mapped to halfway space
out@_reg@_file : (an existing file name)
        output registration file
registered@_file : (a file name)
        output image with registration applied
weights@_file : (a file name)
        image of weights used
\end{Verbatim}


\subsection{\texttt{Smooth}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:smooth}
Wraps command \textbf{mris\_volsmooth}

Use FreeSurfer mris\_volsmooth to smooth a volume

This function smoothes cortical regions on a surface and non-cortical
regions in volume.

\begin{notice}{note}{Note:}
Cortical voxels are mapped to the surface (3D-\textgreater{}2D) and then the
smoothed values from the surface are put back into the volume to fill
the cortical ribbon. If data is smoothed with this algorithm, one has to
be careful about how further processing is interpreted.
\end{notice}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{Smooth}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoothvol} \PYG{o}{=} \PYG{n}{Smooth}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{smoothed\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo\PYGZus{}out.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{reg\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{register.dat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{surface\PYGZus{}fwhm}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{vol\PYGZus{}fwhm}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoothvol}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mris\PYGZus{}volsmooth --i functional.nii --reg register.dat --o foo\PYGZus{}out.nii --fwhm 10 --vol-fwhm 6'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        source volume
num@_iters : (an integer)
        number of iterations instead of fwhm
        exclusive: surface@_fwhm
reg@_file : (an existing file name)
        registers volume to surface anatomical
surface@_fwhm : (a float)
        surface FWHM in mm
        exclusive: num@_iters
        requires: reg@_file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
proj@_frac : (a float)
        project frac of thickness a long surface normal
        exclusive: proj@_frac@_avg
proj@_frac@_avg : (a tuple of the form: (a float, a float, a float))
        average a long normal min max delta
        exclusive: proj@_frac
smoothed@_file : (a file name)
        output volume
subjects@_dir : (an existing directory name)
        subjects directory
vol@_fwhm : (a float)
        volumesmoothing outside of surface
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
smoothed@_file : (a file name)
        smoothed input volume
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}


\subsection{\texttt{SynthesizeFLASH}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:synthesizeflash}
Wraps command \textbf{mri\_synthesize}

Synthesize a FLASH acquisition from T1 and proton density maps.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id10}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{SynthesizeFLASH}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{syn} \PYG{o}{=} \PYG{n}{SynthesizeFLASH}\PYG{p}{(}\PYG{n}{tr}\PYG{o}{=}\PYG{l+m+mi}{20}\PYG{p}{,} \PYG{n}{te}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{n}{flip\PYGZus{}angle}\PYG{o}{=}\PYG{l+m+mi}{30}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{syn}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t1\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{T1.mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{syn}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{pd\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{PD.mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{syn}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{flash\PYGZus{}30syn.mgz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{syn}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'mri\PYGZus{}synthesize 20.00 30.00 3.000 T1.mgz PD.mgz flash\PYGZus{}30syn.mgz'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
flip@_angle : (a float)
        flip angle (in degrees)
pd@_image : (an existing file name)
        image of proton density values
t1@_image : (an existing file name)
        image of T1 values
te : (a float)
        echo time (in msec)
tr : (a float)
        repetition time (in msec)

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fixed@_weighting : (a boolean)
        use a fixed weighting to generate optimal gray/white contrast
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        image to write
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        synthesized FLASH acquisition
\end{Verbatim}


\subsection{\texttt{UnpackSDICOMDir}}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:unpacksdicomdir}
Wraps command \textbf{unpacksdcmdir}

Use unpacksdcmdir to convert dicom files

Call unpacksdcmdir -help from the command line to see more information on
using this command.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.preprocess:id11}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{UnpackSDICOMDir}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack} \PYG{o}{=} \PYG{n}{UnpackSDICOMDir}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{output\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{run\PYGZus{}info} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{mprage}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dir\PYGZus{}structure} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{generic}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{unpack}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'unpacksdcmdir -generic -targ . -run 5 mprage nii struct -src .'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
config : (an existing file name)
        specify unpacking rules in file
        exclusive: run@_info,config,seq@_config
run@_info : (a tuple of the form: (an integer, a string, a string, a string))
        runno subdir format name : spec unpacking rules on cmdline
        exclusive: run@_info,config,seq@_config
seq@_config : (an existing file name)
        specify unpacking rules based on sequence
        exclusive: run@_info,config,seq@_config
source@_dir : (an existing directory name)
        directory with the DICOM files

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dir@_structure : ('fsfast' or 'generic')
        unpack to specified directory structures
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
log@_file : (an existing file name)
        explicilty set log file
no@_info@_dump : (a boolean)
        do not create infodump file
no@_unpack@_err : (a boolean)
        do not try to unpack runs with errors
output@_dir : (a directory name)
        top directory into which the files will be unpacked
scan@_only : (an existing file name)
        only scan the directory and put result in file
spm@_zeropad : (an integer)
        set frame number zero padding width for SPM
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}


\section{nipype.interfaces.freesurfer.utils}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:nipype-interfaces-freesurfer-utils}\label{interfaces/generated/nipype.interfaces.freesurfer.utils::doc}

\subsection{\texttt{ApplyMask}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:applymask}
Wraps command \textbf{mri\_mask}

Use Freesurfer's mri\_mask to apply a mask to an image.

The mask file need not be binarized; it can be thresholded above a given
value before application. It can also optionally be transformed into input
space with an LTA matrix.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input image (will be masked)
mask@_file : (an existing file name)
        image defining mask space

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_xfm : (a boolean)
        invert transformation
mask@_thresh : (a float)
        threshold mask before applying
out@_file : (a file name)
        final image to write
subjects@_dir : (an existing directory name)
        subjects directory
use@_abs : (a boolean)
        take absolute value of mask before applying
xfm@_file : (an existing file name)
        LTA-format transformation matrix to align mask with input
xfm@_source : (an existing file name)
        image defining transform source space
xfm@_target : (an existing file name)
        image defining transform target space
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        masked image
\end{Verbatim}


\subsection{\texttt{ImageInfo}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:imageinfo}
Wraps command \textbf{mri\_info}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file : (an existing file name)
        image to query
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
TE : (a string)
        echo time (msec)
TI : (a string)
        inversion time (msec)
TR : (a string)
        repetition time(msec)
data@_type : (a string)
        image data type
dimensions : (a tuple)
        image dimensions (voxels)
file@_format : (a string)
        file format
info    output of mri@_info
orientation : (a string)
        image orientation
out@_file : (an existing file name)
        text file with image information
ph@_enc@_dir : (a string)
        phase encode direction
vox@_sizes : (a tuple)
        voxel sizes (mm)
\end{Verbatim}


\subsection{\texttt{MRIsConvert}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:mrisconvert}
Wraps command \textbf{mris\_convert}

Uses Freesurfer's mris\_convert to convert surface files to various formats

Example:

import nipype.interfaces.freesurfer as fs
mris = fs.MRIs\_Convert()
mris.inputs.in\_file = `lh.pial'
mris.inputs.out\_datatype = `gii'
mris.run()

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        File to read/convert
out@_datatype : ('ico' or 'tri' or 'stl' or 'vtk' or 'gii' or 'mgh' or 'mgz')
        These file formats are supported:  ASCII:       .ascICO: .ico, .tri GEO: .geo STL: .stl VTK: .vtk GIFTI: .gii MGH surface-encoded 'volume': .mgh, .mgz

@PYGZlb[]Optional@PYGZrb[]
annot@_file : (an existing file name)
        input is annotation or gifti label data
args : (a string)
        Additional parameters to the command
dataarray@_num : (an integer)
        if input is gifti, 'num' specifies which data array to use
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
functional@_file : (an existing file name)
        input is functional time-series or other multi-frame data (must specify surface)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
label@_file : (an existing file name)
        infile is .label file, label is name of this label
labelstats@_outfile : (a file name)
        outfile is name of gifti file to which label stats will be written
normal : (a boolean)
        output is an ascii file where vertex data
origname : (a string)
        read orig positions
out@_file : (a file name)
        output filename or True to generate one
parcstats@_file : (an existing file name)
        infile is name of text file containing label/val pairs
patch : (a boolean)
        input is a patch, not a full surface
rescale : (a boolean)
        rescale vertex xyz so total area is same as group average
scalarcurv@_file : (an existing file name)
        input is scalar curv overlay file (must still specify surface)
scale : (a float)
        scale vertex xyz by scale
subjects@_dir : (an existing directory name)
        subjects directory
talairachxfm@_subjid : (a string)
        apply talairach xfm of subject to vertex xyz
vertex : (a boolean)
        Writes out neighbors of a vertex in each row
xyz@_ascii : (a boolean)
        Print only surface xyz to ascii file
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
converted : (an existing file name)
        converted output surface
\end{Verbatim}


\subsection{\texttt{SampleToSurface}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:sampletosurface}
Wraps command \textbf{mri\_vol2surf}

Sample a volume to the cortical surface using Freesurfer's mri\_vol2surf.

You must supply a sampling method, range, and units.  You can project
either a given distance (in mm) or a given fraction of the cortical
thickness at that vertex along the surface normal from the target surface,
and then set the value of that vertex to be either the value at that point
or the average or maximum value found along the projection vector.

By default, the surface will be saved as a vector with a length equal to the
number of vertices on the target surface.  This is not a problem for Freesurfer
programs, but if you intend to use the file with interfaces to another package,
you must set the \code{reshape} input to True, which will factor the surface vector
into a matrix with dimensions compatible with proper Nifti files.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{SampleToSurface}\PYG{p}{(}\PYG{n}{hemi}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{lh}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{cope1.nii.gz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{reg\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{register.dat}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sampling\PYGZus{}method} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{average}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sampling\PYGZus{}range} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sampler}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sampling\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{frac}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{sampler}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
hemi : ('lh' or 'rh')
        target hemisphere
projection@_stem : (a string)
        stem for precomputed linear estimates and volume fractions
        exclusive: sampling@_method
sampling@_method : ('point' or 'max' or 'average')
        how to sample -- at a point or at the max or average over a range
        exclusive: projection@_stem
        requires: sampling@_range,sampling@_units
source@_file : (an existing file name)
        volume to sample values from

@PYGZlb[]Optional@PYGZrb[]
apply@_rot : (a tuple of the form: (a float, a float, a float))
        rotation angles (in degrees) to apply to reg matrix
apply@_trans : (a tuple of the form: (a float, a float, a float))
        translation (in mm) to apply to reg matrix
args : (a string)
        Additional parameters to the command
cortex@_mask : (a boolean)
        mask the target surface with hemi.cortex.label
        exclusive: mask@_label
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fix@_tk@_reg : (a boolean)
        make reg matrix round-compatible
float2int@_method : ('round' or 'tkregister')
        method to convert reg matrix values (default is round)
frame : (an integer)
        save only one frame (0-based)
hits@_file : (a boolean or an existing file name)
        save image with number of hits at each voxel
hits@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz')
        hits file type
ico@_order : (an integer)
        icosahedron order when target@_subject is 'ico'
        requires: target@_subject
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
interp@_method : ('nearest' or 'trilinear')
        interpolation method
mask@_label : (an existing file name)
        label file to mask output with
        exclusive: cortex@_mask
mni152reg : (a boolean)
        source volume is in MNI152 space
        exclusive: reg@_file,reg@_header,mni152reg
no@_reshape : (a boolean)
        do not reshape surface vector (default)
        exclusive: reshape
out@_file : (a file name)
        surface file to write
out@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz')
        output file type
override@_reg@_subj : (a boolean)
        override the subject in the reg file header
        requires: subject@_id
reference@_file : (an existing file name)
        reference volume (default is orig.mgz)
reg@_file : (an existing file name)
        source-to-reference registration file
        exclusive: reg@_file,reg@_header,mni152reg
reg@_header : (a boolean)
        register based on header geometry
        exclusive: reg@_file,reg@_header,mni152reg
        requires: subject@_id
reshape : (a boolean)
        reshape surface vector to fit in non-mgh format
        exclusive: no@_reshape
reshape@_slices : (an integer)
        number of 'slices' for reshaping
sampling@_range : (a float or a tuple of the form: (a float, a float, a float))
        sampling range - a point or a tuple of (min, max, step)
sampling@_units : ('mm' or 'frac')
        sampling range type -- either 'mm' or 'frac'
scale@_input : (a float)
        multiple all intensities by scale factor
smooth@_surf : (a float)
        smooth output surface (mm fwhm)
smooth@_vol : (a float)
        smooth input volume (mm fwhm)
subject@_id : (a string)
        subject id
subjects@_dir : (an existing directory name)
        subjects directory
surf@_reg : (a boolean)
        use surface registration to target subject
        requires: target@_subject
surface : (a string)
        target surface (default is white)
target@_subject : (a string)
        sample to surface of different subject than source
vox@_file : (a boolean or a file name)
        text file with the number of voxels intersecting the surface
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
hits@_file : (an existing file name)
        image with number of hits at each voxel
out@_file : (an existing file name)
        surface file
vox@_file : (an existing file name)
        text file with the number of voxels intersecting the surface
\end{Verbatim}


\subsection{\texttt{SurfaceSmooth}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:surfacesmooth}
Wraps command \textbf{mri\_surf2surf}

Smooth a surface image with mri\_surf2surf.

The surface is smoothed by an interative process of averaging the
value at each vertex with those of its adjacent neighbors. You may supply
either the number of iterations to run or a desired effective FWHM of the
smoothing process.  If the latter, the underlying program will calculate
the correct number of iterations internally.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{SurfaceSmooth}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{lh.cope1.mgz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{subj\PYGZus{}1}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{lh}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smoother}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
hemi : ('lh' or 'rh')
        hemisphere to operate on
in@_file : (a file name)
        source surface file
subject@_id : (a string)
        subject id of surface file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
cortex : (a boolean)
        only smooth within @$hemi.cortex.label
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fwhm : (a float)
        effective FWHM of the smoothing process
        exclusive: smooth@_iters
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        surface file to write
reshape : (a boolean)
        reshape surface vector to fit in non-mgh format
smooth@_iters : (an integer)
        iterations of the smoothing process
        exclusive: fwhm
subjects@_dir : (an existing directory name)
        subjects directory
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        smoothed surface file
\end{Verbatim}


\subsection{\texttt{SurfaceSnapshots}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:surfacesnapshots}
Wraps command \textbf{tksurfer}

Use Tksurfer to save pictures of the cortical surface.

By default, this takes snapshots of the lateral, medial, ventral,
and dorsal surfaces.  See the \code{six\_images} option to add the
anterior and posterior surfaces.

You may also supply your own tcl script (see the Freesurfer wiki for
information on scripting tksurfer). The screenshot stem is set as the
environment variable ``\_SNAPSHOT\_STEM'', which you can use in your
own scripts.

Node that this interface will not run if you do not have graphics
enabled on your system.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{as} \PYG{n+nn}{fs}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shots} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{SurfaceSnapshots}\PYG{p}{(}\PYG{n}{subject\PYGZus{}id}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{fsaverage}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{hemi}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{lh}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{surface}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{pial}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shots}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{overlay} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{zstat1.nii.gz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shots}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{overlay\PYGZus{}range} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mf}{2.3}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{shots}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{overlay\PYGZus{}reg} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{register.dat}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{shots}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
hemi : ('lh' or 'rh')
        hemisphere to visualize
subject@_id : (a string)
        subject to visualize
surface : (a string)
        surface to visualize

@PYGZlb[]Optional@PYGZrb[]
annot@_file : (an existing file name)
        path to annotation file to display
        exclusive: annot@_name
annot@_name : (a string)
        name of annotation to display (must be in @$subject/label directory
        exclusive: annot@_file
args : (a string)
        Additional parameters to the command
colortable : (an existing file name)
        load colortable file
demean@_overlay : (a boolean)
        remove mean from overlay
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
identity@_reg : (a boolean)
        use the identity matrix to register the overlay to the surface
        exclusive: overlay@_reg,identity@_reg,mni152@_reg
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_overlay : (a boolean)
        invert the overlay display
label@_file : (an existing file name)
        path to label file to display
        exclusive: label@_name
label@_name : (a string)
        name of label to display (must be in @$subject/label directory
        exclusive: label@_file
label@_outline : (a boolean)
        draw label/annotation as outline
label@_under : (a boolean)
        draw label/annotation under overlay
mni152@_reg : (a boolean)
        use to display a volume in MNI152 space on the average subject
        exclusive: overlay@_reg,identity@_reg,mni152@_reg
orig@_suffix : (a string)
        set the orig surface suffix string
overlay : (an existing file name)
        load an overlay volume/surface
        requires: overlay@_range
overlay@_range : (a float or a tuple of the form: (a float, a float) or a tuple of the form: (a float, a float, a float))
        overlay range--either min, (min,max) or (min,mid,max)
overlay@_range@_offset : (a float)
        overlay range will be symettric around offset value
overlay@_reg : (a file name)
        registration matrix file to register overlay to surface
        exclusive: overlay@_reg,identity@_reg,mni152@_reg
patch@_file : (an existing file name)
        load a patch
reverse@_overlay : (a boolean)
        reverse the overlay display
screenshot@_stem : (a string)
        stem to use for screenshot file names
show@_color@_scale : (a boolean)
        display the color scale bar
show@_color@_text : (a boolean)
        display text in the color scale bar
show@_curv : (a boolean)
        show curvature
        exclusive: show@_gray@_curv
show@_gray@_curv : (a boolean)
        show curvature in gray
        exclusive: show@_curv
six@_images : (a boolean)
        also take anterior and posterior snapshots
sphere@_suffix : (a string)
        set the sphere.reg suffix string
stem@_template@_args : (a list of items which are a string)
        input names to use as arguments for a string-formated stem template
        requires: screenshot@_stem
subjects@_dir : (an existing directory name)
        subjects directory
tcl@_script : (an existing file name)
        override default screenshot script
truncate@_overlay : (a boolean)
        truncate the overlay display
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
snapshots : (an existing file name)
        tiff images of the surface from different perspectives
\end{Verbatim}


\subsection{\texttt{SurfaceTransform}}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:surfacetransform}
Wraps command \textbf{mri\_surf2surf}

Transform a surface file from one subject to another via a spherical registration.

Both the source and target subject must reside in your Subjects Directory,
and they must have been processed with recon-all, unless you are transforming
to one of the icosahedron meshes.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.freesurfer.utils:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.freesurfer} \PYG{k+kn}{import} \PYG{n}{SurfaceTransform}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm} \PYG{o}{=} \PYG{n}{SurfaceTransform}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{lh.cope1.nii.gz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source\PYGZus{}subject} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{my\PYGZus{}subject}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{target\PYGZus{}subject} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{fsaverage}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{lh}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sxfm}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
hemi : ('lh' or 'rh')
        hemisphere to transform
source@_file : (an existing file name)
        Unknown
source@_subject : (a string)
        Unknown
target@_subject : (a string)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        surface file to write
reshape : (a boolean)
        Unknown
reshape@_factor : (an integer)
        Unknown
subjects@_dir : (an existing directory name)
        subjects directory
target@_ico@_order : (1 or 2 or 3 or 4 or 5 or 6 or 7)
        Unknown
target@_type : ('cor' or 'mgh' or 'mgz' or 'minc' or 'analyze' or 'analyze4d' or 'spm' or 'afni' or 'brik' or 'bshort' or 'bfloat' or 'sdt' or 'outline' or 'otl' or 'gdf' or 'nifti1' or 'nii' or 'niigz')
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        transformed surface file
\end{Verbatim}


\section{nipype.interfaces.fsl.base}
\label{interfaces/generated/nipype.interfaces.fsl.base:nipype-interfaces-fsl-base}\label{interfaces/generated/nipype.interfaces.fsl.base::doc}

\subsection{\texttt{Info}}
\label{interfaces/generated/nipype.interfaces.fsl.base:info}
Handle fsl output type and version information.

version refers to the version of fsl on the system

output type refers to the type of file fsl defaults to writing
eg, NIFTI, NIFTI\_GZ


\section{nipype.interfaces.fsl.dti}
\label{interfaces/generated/nipype.interfaces.fsl.dti:nipype-interfaces-fsl-dti}\label{interfaces/generated/nipype.interfaces.fsl.dti::doc}

\subsection{\texttt{BEDPOSTX}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:bedpostx}
Wraps command \textbf{bedpostx}

Deprecated! Please use create\_bedpostx\_pipeline instead


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bedp} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BEDPOSTX}\PYG{p}{(}\PYG{n}{bpx\PYGZus{}directory}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{subjdir}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{bvecs}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{bvals}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{dwi}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{mask}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{fibres}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bedp}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'bedpostx subjdir -n 1'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bvals : (an existing file name)
        b values file
bvecs : (an existing file name)
        b vectors file
dwi : (an existing file name)
        diffusion weighted image data file
mask : (an existing file name)
        bet binary mask file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bpx@_directory : (a directory name)
        the name for this subjects bedpostx folder
burn@_period : (an integer)
        burnin period
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fibres : (an integer)
        number of fibres per voxel
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
jumps : (an integer)
        number of jumps
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
sampling : (an integer)
        sample every
weight : (a float)
        ARD weight, more weight means less secondary fibres per voxel
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
bpx@_out@_directory : (an existing directory name)
        path/name of directory with all bedpostx output files for this subject
dyads : (a list of items which are a file name)
        a list of path/name of mean of PDD distribution in vector form
mean@_fsamples : (a list of items which are a file name)
        a list of path/name of 3D volume with mean of distribution on f anisotropy
mean@_phsamples : (a list of items which are a file name)
        a list of path/name of 3D volume with mean of distribution on phi
mean@_thsamples : (a list of items which are a file name)
        a list of path/name of 3D volume with mean of distribution on theta
merged@_fsamples : (a list of items which are a file name)
        a list of path/name of 4D volume with samples from the distribution on anisotropic volume fraction
merged@_phsamples : (a list of items which are a file name)
        a list of path/name of file with samples from the distribution on phi
merged@_thsamples : (a list of items which are a file name)
        a list of path/name of 4D volume with samples from the distribution on theta
xfms@_directory : (an existing directory name)
        path/name of directory with the tranformation matrices
\end{Verbatim}


\subsection{\texttt{DTIFit}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:dtifit}
Wraps command \textbf{dtifit}

Use FSL  dtifit command for fitting a diffusion tensor model at each
voxel


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{DTIFit}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{dwi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bvecs} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bvals} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}name} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{TP}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dti}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'dtifit -k diffusion.nii -o TP -m mask.nii -r bvecs -b bvals'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bvals : (an existing file name)
        b values file
bvecs : (an existing file name)
        b vectors file
dwi : (an existing file name)
        diffusion weighted image data file
mask : (an existing file name)
        bet binary mask file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
base@_name : (a string)
        base@_name that all output files will start with
cni : (an existing file name)
        input counfound regressors
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
little@_bit : (a boolean)
        only process small area of brain
max@_x : (an integer)
        max x
max@_y : (an integer)
        max y
max@_z : (an integer)
        max z
min@_x : (an integer)
        min x
min@_y : (an integer)
        min y
min@_z : (an integer)
        min z
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
save@_tensor : (a boolean)
        save the elements of the tensor
sse : (a boolean)
        output sum of squared errors
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
FA : (an existing file name)
        path/name of file with the fractional anisotropy
L1 : (an existing file name)
        path/name of file with the 1st eigenvalue
L2 : (an existing file name)
        path/name of file with the 2nd eigenvalue
L3 : (an existing file name)
        path/name of file with the 3rd eigenvalue
MD : (an existing file name)
        path/name of file with the mean diffusivity
S0 : (an existing file name)
        path/name of file with the raw T2 signal with no diffusion weighting
V1 : (an existing file name)
        path/name of file with the 1st eigenvector
V2 : (an existing file name)
        path/name of file with the 2nd eigenvector
V3 : (an existing file name)
        path/name of file with the 3rd eigenvector
tensor : (an existing file name)
        path/name of file with the 4D tensor volume
\end{Verbatim}


\subsection{\texttt{DistanceMap}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:distancemap}
Wraps command \textbf{distancemap}

Use FSL's distancemap to generate a map of the distance to the nearest nonzero voxel.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.dti:examples}
import nipype.interfaces.fsl as fsl
mapper = fsl.DistanceMap()
mapper.inputs.in\_file = ``skeleton\_mask.nii.gz''
mapper.run() \# doctest: +SKIP

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to calculate distance values for

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
distance@_map : (a file name)
        distance map to write
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
invert@_input : (a boolean)
        invert input image
local@_max@_file : (a boolean or a file name)
        write an image of the local maxima
mask@_file : (an existing file name)
        binary mask to contrain calculations
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
distance@_map : (an existing file name)
        value is distance to nearest nonzero voxels
local@_max@_file : (a file name)
        image of local maxima
\end{Verbatim}


\subsection{\texttt{EddyCorrect}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:eddycorrect}
Wraps command \textbf{eddy\_correct}

Deprecated! Please use create\_eddy\_correct\_pipeline instead


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{eddyc} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{EddyCorrect}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{diffusion\PYGZus{}edc.nii}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{ref\PYGZus{}num}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{eddyc}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'eddy\PYGZus{}correct diffusion.nii diffusion\PYGZus{}edc.nii 0'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        4D input file
ref@_num : (an integer)
        reference number

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        4D output file
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
eddy@_corrected : (an existing file name)
        path/name of 4D eddy corrected output file
\end{Verbatim}


\subsection{\texttt{FindTheBiggest}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:findthebiggest}
Wraps command \textbf{find\_the\_biggest}

Use FSL find\_the\_biggest for performing hard segmentation on
the outputs of connectivity-based thresholding in probtrack.
For complete details, see the \href{http://www.fmrib.ox.ac.uk/fsl/fdt/fdt\_biggest.html}{FDT
Documentation.}


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ldir} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{seeds\PYGZus{}to\PYGZus{}M1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{seeds\PYGZus{}to\PYGZus{}M2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fBig} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FindTheBiggest}\PYG{p}{(}\PYG{n}{in\PYGZus{}files}\PYG{o}{=}\PYG{n}{ldir}\PYG{p}{,} \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{biggestSegmentation}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fBig}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'find\PYGZus{}the\PYGZus{}biggest seeds\PYGZus{}to\PYGZus{}M1.nii seeds\PYGZus{}to\PYGZus{}M2.nii biggestSegmentation'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of items which are a file name)
        a list of input volumes or a singleMatrixFile

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        file with the resulting segmentation
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        output file indexed in order of input files
\end{Verbatim}


\subsection{\texttt{MakeDyadicVectors}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:makedyadicvectors}
Wraps command \textbf{make\_dyadic\_vectors}

Create vector volume representing mean principal diffusion direction
and its uncertainty (dispersion)

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
phi@_vol : (an existing file name)
        Unknown
theta@_vol : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (an existing file name)
        Unknown
output : (a file name)
        Unknown
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
perc : (a float)
        the {perc}@% angle of the output cone of uncertainty (output will be in degrees)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dispersion : (an existing file name)
        Unknown
dyads : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{ProbTrackX}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:probtrackx}
Wraps command \textbf{probtrackx}

Use FSL  probtrackx for tractography on bedpostx results


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pbx} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ProbTrackX}\PYG{p}{(}\PYG{n}{samples\PYGZus{}base\PYGZus{}name}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merged}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mask}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{seed}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{MASK\PYGZus{}average\PYGZus{}thal\PYGZus{}right.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mode}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{seedmask}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{xfm}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{trans.mat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{n\PYGZus{}samples}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{n}{n\PYGZus{}steps}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{force\PYGZus{}dir}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{opd}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{os2t}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}     \PYG{n}{target\PYGZus{}masks} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{targets\PYGZus{}MASK1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{targets\PYGZus{}MASK2.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}     \PYG{n}{thsamples}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}thsamples.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{fsamples}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}fsamples.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{phsamples}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{merged\PYGZus{}phsamples.nii}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{out\PYGZus{}dir}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pbx}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'probtrackx --forcedir -m mask.nii --mode=seedmask --nsamples=3 --nsteps=10 --opd --os2t --dir=. --samples=merged --seed=MASK\PYGZus{}average\PYGZus{}thal\PYGZus{}right.nii --targetmasks=targets.txt --xfm=trans.mat'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
fsamples : (an existing file name)
        Unknown
mask : (an existing file name)
        bet binary mask file in diffusion space
phsamples : (an existing file name)
        Unknown
seed : (an existing file name or a list of items which are an existing file name or a list of items which are a list of from 3 to 3 items which are an integer)
        seed volume(s), or voxel(s)or freesurfer label file
thsamples : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
avoid@_mp : (an existing file name)
        reject pathways passing through locations given by this mask
c@_thresh : (a float)
        curvature threshold - default=0.2
correct@_path@_distribution : (a boolean)
        correct path distribution for the length of the pathways
dist@_thresh : (a float)
        discards samples shorter than this threshold (in mm - default=0)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fibst : (an integer)
        force a starting fibre for tracking - default=1, i.e. first fibre orientation. Only works if randfib==0
force@_dir : (a boolean)
        use the actual directory name given - i.e. do not add + to make a new directory
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
inv@_xfm : (a file name)
        transformation matrix taking DTI space to seed space (compulsory when using a warp@_field for seeds@_to@_dti)
loop@_check : (a boolean)
        perform loop@_checks on paths - slower, but allows lower curvature threshold
mask2 : (an existing file name)
        second bet binary mask (in diffusion space) in twomask@_symm mode
mesh : (an existing file name)
        Freesurfer-type surface descriptor (in ascii format)
mod@_euler : (a boolean)
        use modified euler streamlining
mode : ('simple' or 'two@_mask@_symm' or 'seedmask')
        options: simple (single seed voxel), seedmask (mask of seed voxels),twomask@_symm (two bet binary masks)
n@_samples : (an integer)
        number of samples - default=5000
n@_steps : (an integer)
        number of steps per sample - default=2000
network : (a boolean)
        activate network mode - only keep paths going through at least one seed mask (required if multiple seed masks)
opd : (a boolean)
        outputs path distributions
os2t : (a boolean)
        Outputs seeds to targets
out@_dir : (an existing directory name)
        directory to put the final volumes in
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
rand@_fib : (0 or 1 or 2 or 3)
        options: 0 - default, 1 - to randomly sample initial fibres (with f @textgreater[] fibthresh), 2 - to sample in proportion fibres (with f@textgreater[]fibthresh) to f, 3 - to sample ALL populations at random (even if f@textless[]fibthresh)
random@_seed : (a boolean)
        random seed
s2tastext : (a boolean)
        output seed-to-target counts as a text file (useful when seeding from a mesh)
sample@_random@_points : (a boolean)
        sample random points within seed voxels
samples@_base@_name : (a string)
        the rootname/base@_name for samples files
seed@_ref : (an existing file name)
        reference vol to define seed space in simple mode - diffusion space assumed if absent
step@_length : (a float)
        step@_length in mm - default=0.5
stop@_mask : (an existing file name)
        stop tracking at locations given by this mask file
target@_masks : (a file name)
        list of target masks - required for seeds@_to@_targets classification
use@_anisotropy : (a boolean)
        use anisotropy to constrain tracking
verbose : (0 or 1 or 2)
        Verbose level, @PYGZlb[]0-2@PYGZrb[]
waypoints : (an existing file name)
        waypoint mask or ascii list of waypoint masks - only keep paths going through ALL the masks
xfm : (an existing file name)
        transformation matrix taking seed space to DTI space (either FLIRT matrix or FNIRT warp@_field) - default is identity
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
fdt@_paths : (an existing file name)
        path/name of a 3D image file containing the output connectivity distribution to the seed mask
log : (an existing file name)
        path/name of a text record of the command that was run
particle@_files : (a list of items which are a file name)
        Unknown
targets : (a list of items which are a file name)
        a list with all generated seeds@_to@_target files
way@_total : (an existing file name)
        path/name of a text file containing a single number corresponding to the total number of generated tracts that have not been rejected by inclusion/exclusion mask criteria
\end{Verbatim}


\subsection{\texttt{ProjThresh}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:projthresh}
Wraps command \textbf{proj\_thresh}

Use FSL proj\_thresh for thresholding some outputs of probtrack
For complete details, see the FDT Documentation
\textless{}\href{http://www.fmrib.ox.ac.uk/fsl/fdt/fdt\_thresh.html}{http://www.fmrib.ox.ac.uk/fsl/fdt/fdt\_thresh.html}\textgreater{}


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ldir} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{seeds\PYGZus{}to\PYGZus{}M1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{seeds\PYGZus{}to\PYGZus{}M2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pThresh} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ProjThresh}\PYG{p}{(}\PYG{n}{in\PYGZus{}files}\PYG{o}{=}\PYG{n}{ldir}\PYG{p}{,}\PYG{n}{threshold}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pThresh}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'proj\PYGZus{}thresh seeds\PYGZus{}to\PYGZus{}M1.nii seeds\PYGZus{}to\PYGZus{}M2.nii 3'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of items which are a file name)
        a list of input volumes
threshold : (an integer)
        threshold indicating minimum number of seed voxels entering this mask region

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_files : (a list of items which are a file name)
        path/name of output volume after thresholding
\end{Verbatim}


\subsection{\texttt{Randomise}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:randomise}
Wraps command \textbf{randomise}

XXX UNSTABLE DO NOT USE

FSL Randomise: feeds the 4D projected FA data into GLM
modelling and thresholding
in order to find voxels which correlate with your model


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl.dti} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rand} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Randomise}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{allFA.nii}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{mask} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{tcon}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{design.con}\PYG{l+s}{'}\PYG{p}{,}     \PYG{n}{design\PYGZus{}mat}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{design.mat}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rand}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'randomise -i allFA.nii -o tbss\PYGZus{} -d design.mat -t design.con -m mask.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
design@_mat : (an existing file name)
        design matrix file
in@_file : (an existing file name)
        4D input file
tcon : (an existing file name)
        t contrasts file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
base@_name : (a string)
        the rootname that all generated files will have
c@_thresh : (a float)
        carry out cluster-based thresholding
cm@_thresh : (a float)
        carry out cluster-mass-based thresholding
demean : (a boolean)
        demean data temporally before model fitting
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
f@_c@_thresh : (a float)
        carry out f cluster thresholding
f@_cm@_thresh : (a float)
        carry out f cluster-mass thresholding
f@_only : (a boolean)
        calculate f-statistics only
fcon : (an existing file name)
        f contrasts file
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (an existing file name)
        mask image
num@_perm : (an integer)
        number of permutations (default 5000, set to 0 for exhaustive)
one@_sample@_group@_mean : (a boolean)
        perform 1-sample group-mean test instead of generic permutation test
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
p@_vec@_n@_dist@_files : (a boolean)
        output permutation vector and null distribution text files
raw@_stats@_imgs : (a boolean)
        output raw ( unpermuted ) statistic images
seed : (an integer)
        specific integer seed for random number generator
show@_info@_parallel@_mode : (a boolean)
        print out information required for parallel mode and exit
show@_total@_perms : (a boolean)
        print out how many unique permutations would be generated and exit
tfce : (a boolean)
        carry out Threshold-Free Cluster Enhancement
tfce2D : (a boolean)
        carry out Threshold-Free Cluster Enhancement with 2D optimisation
tfce@_C : (a float)
        TFCE connectivity (6 or 26; default=6)
tfce@_E : (a float)
        TFCE extent parameter (default=0.5)
tfce@_H : (a float)
        TFCE height parameter (default=2)
var@_smooth : (an integer)
        use variance smoothing (std is in mm)
vox@_p@_values : (a boolean)
        output voxelwise (corrected and uncorrected) p-value images
vxf : (a list of items which are an integer)
        list of 4D images containing voxelwise EVs(list order corresponds to numbers in vxl option)
vxl : (a list of items which are an integer)
        list of numbers indicating voxelwise EVsposition in the design matrix (list order corresponds to files in vxf option)
x@_block@_labels : (an existing file name)
        exchangeability block labels file
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tstat1@_file : (an existing file name)
        path/name of tstat image corresponding to the first t contrast
\end{Verbatim}


\subsection{\texttt{TBSS1Preproc}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:tbss1preproc}
Wraps command \textbf{tbss\_1\_preproc}

XXX UNSTABLE DO NOT USE

Use FSL TBSS1Preproc for preparing your FA data in your TBSS working
directory in the right format


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl.dti} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss1} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{TBSS1Preproc}\PYG{p}{(}\PYG{n}{img\PYGZus{}list}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{functional2.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{functional3.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss1}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'tbss\PYGZus{}1\PYGZus{}preproc functional.nii functional2.nii functional3.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
img@_list : (a list of items which are an existing file name)
        list with filenames of the FA images

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tbss@_dir : (an existing directory name)
        path/name of directory with FA images
\end{Verbatim}


\subsection{\texttt{TBSS2Reg}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:tbss2reg}
Wraps command \textbf{tbss\_2\_reg}

XXX UNSTABLE DO NOT USE

Use FSL TBSS2Reg for applying nonlinear registration of all FA images
into standard space


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id8}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl.dti} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss2} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{TBSS2Reg}\PYG{p}{(}\PYG{n}{tbss\PYGZus{}dir}\PYG{o}{=}\PYG{n}{os}\PYG{o}{.}\PYG{n}{getcwd}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,}\PYG{n}{FMRIB58FA}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss2}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'tbss\PYGZus{}2\PYGZus{}reg -T'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA and origdata folders generated by tbss@_1@_preproc

@PYGZlb[]Optional@PYGZrb[]
FMRIB58FA : (a boolean)
        use FMRIB58@_FA@_1mm as target for nonlinear registrations
        exclusive: FMRIB58FA,target@_img,find@_target
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
find@_target : (a boolean)
        find best target from all images in FA
        exclusive: FMRIB58FA,target@_img,find@_target
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
target@_img : (a string)
        use given image as target for nonlinear registrations
        exclusive: FMRIB58FA,target@_img,find@_target
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA and origdata folders generated by tbss@_1@_preproc
\end{Verbatim}


\subsection{\texttt{TBSS3Postreg}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:tbss3postreg}
Wraps command \textbf{tbss\_3\_postreg}

XXX UNSTABLE DO NOT USE

Use FSL TBSS3Postreg for creating the mean FA image and skeletonise it


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl.dti} \PYG{k+kn}{as}  \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss3} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{TBSS3Postreg}\PYG{p}{(}\PYG{n}{subject\PYGZus{}mean}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{tbss\PYGZus{}dir}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{tbss\PYGZus{}dir}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss3}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'tbss\PYGZus{}3\PYGZus{}postreg -S'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA and origdata folders generated by tbss@_1@_preproc

@PYGZlb[]Optional@PYGZrb[]
FMRIB58FA : (a boolean)
        use FMRIB58@_FA and its skeleton instead of study-derived mean and skeleton
        exclusive: subject@_mean,FMRIB58FA
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
subject@_mean : (a boolean)
        derive mean@_FA and mean@_FA@_skeleton from mean of all subjects in study
        exclusive: subject@_mean,FMRIB58FA
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
all@_FA : (an existing file name)
        path/name of 4D volume with all FA images
mean@_FA : (an existing file name)
        path/name of 3D volume with mean FA image
mean@_FA@_skeleton : (an existing file name)
        path/name of 3D volume with mean FA skeleton
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA, origdata, and stats folders generated by tbss@_1@_preproc and this command
\end{Verbatim}


\subsection{\texttt{TBSS4Prestats}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:tbss4prestats}
Wraps command \textbf{tbss\_4\_prestats}

XXX UNSTABLE DO NOT USE

Use FSL TBSS4Prestats thresholds the mean FA skeleton image at the
chosen threshold


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id10}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl.dti} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss4} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{TBSS4Prestats}\PYG{p}{(}\PYG{n}{threshold}\PYG{o}{=}\PYG{l+m+mf}{0.3}\PYG{p}{,} \PYG{n}{tbss\PYGZus{}dir}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{tbss\PYGZus{}dir}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{tbss4}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'tbss\PYGZus{}4\PYGZus{}prestats 0.300'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA, origdata, and stats folders generated by tbss@_1@_preproc and tbss@_3@_postreg
threshold : (a float)
        threshold value

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
all@_FA@_skeletonised : (an existing file name)
        path/name of 4D volume with all FA images skeletonized
mean@_FA@_skeleton@_mask : (an existing file name)
        path/name of mean FA skeleton mask
tbss@_dir : (an existing directory name)
        path/name of directory containing the FA, origdata, and stats folders generated by tbss@_1@_preproc and tbss@_3@_postreg
\end{Verbatim}


\subsection{\texttt{TractSkeleton}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:tractskeleton}
Wraps command \textbf{tbss\_skeleton}

Use FSL's tbss\_skeleton to skeletonise an FA image or project arbitrary values onto a skeleton.

There are two ways to use this interface.  To create a skeleton from an FA image, just
supply the \code{in\_file} and set \code{skeleton\_file} to True (or specify a skeleton filename.
To project values onto a skeleton, you must set \code{project\_data} to True, and then also
supply values for \code{threshold}, \code{distance\_map}, and \code{data\_file}. The \code{search\_mask\_file}
and \code{use\_cingulum\_mask} inputs are also used in data projection, but \code{use\_cingulum\_mask}
is set to True by default.  This mask controls where the projection algorithm searches
within a circular space around a tract, rather than in a single perpindicular direction.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id11}
import nipype.interfaces.fsl as fsl
skeletor = fsl.TractSkeleton()
skeletor.inputs.in\_file = ``all\_FA.nii.gz''
skeletor.inputs.skeleton\_file = True
skeletor.run() \# doctest: +SKIP

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input image (typcially mean FA volume)

@PYGZlb[]Optional@PYGZrb[]
alt@_data@_file : (an existing file name)
        4D non-FA data to project onto skeleton
alt@_skeleton : (an existing file name)
        alternate skeleton to use
args : (a string)
        Additional parameters to the command
data@_file : (an existing file name)
        4D data to project onto skeleton (usually FA)
distance@_map : (an existing file name)
        distance map image
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
project@_data : (a boolean)
        project data onto skeleton
        requires: threshold,distance@_map,data@_file
projected@_data : (a file name)
        input data projected onto skeleton
search@_mask@_file : (an existing file name)
        mask in which to use alternate search rule
        exclusive: use@_cingulum@_mask
skeleton@_file : (a boolean or a file name)
        write out skeleton image
threshold : (a float)
        skeleton threshold value
use@_cingulum@_mask : (a boolean)
        perform alternate search using built-in cingulum mask
        exclusive: search@_mask@_file
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
projected@_data : (a file name)
        input data projected onto skeleton
skeleton@_file : (a file name)
        tract skeleton image
\end{Verbatim}


\subsection{\texttt{VecReg}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:vecreg}
Wraps command \textbf{vecreg}

Use FSL vecreg for registering vector data
For complete details, see the FDT Documentation
\textless{}\href{http://www.fmrib.ox.ac.uk/fsl/fdt/fdt\_vecreg.html}{http://www.fmrib.ox.ac.uk/fsl/fdt/fdt\_vecreg.html}\textgreater{}


\subsubsection{Example}
\label{interfaces/generated/nipype.interfaces.fsl.dti:id12}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vreg} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{VecReg}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}\PYG{p}{,}                  \PYG{n}{affine\PYGZus{}mat}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{trans.mat}\PYG{l+s}{'}\PYG{p}{,}                  \PYG{n}{ref\PYGZus{}vol}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{,}                  \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{diffusion\PYGZus{}vreg.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{vreg}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'vecreg -t trans.mat -i diffusion.nii -o diffusion\PYGZus{}vreg.nii -r mni.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        filename for input vector or tensor field
ref@_vol : (an existing file name)
        filename for reference (target) volume

@PYGZlb[]Optional@PYGZrb[]
affine@_mat : (an existing file name)
        filename for affine transformation matrix
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
interpolation : ('nearestneighbour' or 'trilinear' or 'sinc' or 'spline')
        interpolation method : nearestneighbour, trilinear (default), sinc or spline
mask : (an existing file name)
        brain mask in input space
out@_file : (a file name)
        filename for output registered vector or tensor field
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
ref@_mask : (an existing file name)
        brain mask in output space (useful for speed up of nonlinear reg)
rotation@_mat : (an existing file name)
        filename for secondary affine matrixif set, this will be used for the rotation of the vector/tensor field
rotation@_warp : (an existing file name)
        filename for secondary warp fieldif set, this will be used for the rotation of the vector/tensor field
warp@_field : (an existing file name)
        filename for 4D warp field for nonlinear registration
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        path/name of filename for the registered vector or tensor field
\end{Verbatim}


\subsection{\texttt{XFibres}}
\label{interfaces/generated/nipype.interfaces.fsl.dti:xfibres}
Wraps command \textbf{xfibres}

Perform model parameters estimation for local (voxelwise) diffusion parameters

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bvals : (an existing file name)
        Unknown
bvecs : (an existing file name)
        Unknown
dwi : (an existing file name)
        Unknown
mask : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
all@_ard : (a boolean)
        Turn ARD on on all fibres
        exclusive: no@_ard,all@_ard
args : (a string)
        Additional parameters to the command
burn@_in : (an integer @textgreater[]= 0)
        Total num of jumps at start of MCMC to be discarded
burn@_in@_no@_ard : (an integer @textgreater[]= 0)
        num of burnin jumps before the ard is imposed
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
force@_dir : (a boolean)
        use the actual directory name given - i.e. do not add + to make a new directory
fudge : (an integer)
        ARD fudge factor
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
logdir : (a directory name)
        Unknown
model : (an integer)
        Which model to use. 1=mono-exponential (default and required for single shell). 2=continous exponential (for multi-shell experiments)
n@_fibres : (an integer @textgreater[]= 1)
        Maximum nukmber of fibres to fit in each voxel
n@_jumps : (an integer @textgreater[]= 1)
        Num of jumps to be made by MCMC
no@_ard : (a boolean)
        Turn ARD off on all fibres
        exclusive: no@_ard,all@_ard
no@_spat : (a boolean)
        Initialise with tensor, not spatially
        exclusive: no@_spat,non@_linear
non@_linear : (a boolean)
        Initialise with nonlinear fitting
        exclusive: no@_spat,non@_linear
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
sample@_every : (an integer @textgreater[]= 0)
        Num of jumps for each sample (MCMC)
seed : (an integer)
        seed for pseudo random number generator
update@_proposal@_every : (an integer @textgreater[]= 1)
        Num of jumps for each update to the proposal density std (MCMC)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dyads : (an existing file name)
        Mean of PDD distribution in vector form.
fsamples : (an existing file name)
        Samples from the distribution on anisotropic volume fraction
mean@_S0samples : (an existing file name)
        Samples from S0 distribution
mean@_dsamples : (an existing file name)
        Mean of distribution on diffusivity d
mean@_fsamples : (an existing file name)
        Mean of distribution on f anisotropy
phsamples : (an existing file name)
        Samples from the distribution on phi
thsamples : (an existing file name)
        Samples from the distribution on theta
\end{Verbatim}


\section{nipype.interfaces.fsl.maths}
\label{interfaces/generated/nipype.interfaces.fsl.maths::doc}\label{interfaces/generated/nipype.interfaces.fsl.maths:nipype-interfaces-fsl-maths}

\subsection{\texttt{ApplyMask}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:applymask}
Wraps command \textbf{fslmaths}

Use fslmaths to apply a binary mask to another image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
mask@_file : (an existing file name)
        binary image defining mask space

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{ApplyMaskInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:applymaskinput}

\subsection{\texttt{BinaryMaths}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:binarymaths}
Wraps command \textbf{fslmaths}

Use fslmaths to perform mathematical operations using a second image or a numeric value.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
operand@_file : (an existing file name)
        second image to perform operation with
        exclusive: operand@_value
operand@_value : (a float)
        value to perform operation with
        exclusive: operand@_file
operation : ('add' or 'sub' or 'mul' or 'div' or 'rem' or 'max' or 'min')
        operation to perform

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{BinaryMathsInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:binarymathsinput}

\subsection{\texttt{ChangeDataType}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:changedatatype}
Wraps command \textbf{fslmaths}

Use fslmaths to change the datatype of an image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        output data type

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{ChangeDataTypeInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:changedatatypeinput}

\subsection{\texttt{DilateImage}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:dilateimage}
Wraps command \textbf{fslmaths}

Use fslmaths to perform a spatial dilation of an image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
operation : ('mean' or 'modal' or 'max')
        filtering operation to perfoem in dilation

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
kernel@_file : (an existing file name)
        use external file for kernel
        exclusive: kernel@_size
kernel@_shape : ('3D' or '2D' or 'box' or 'boxv' or 'gauss' or 'sphere' or 'file')
        kernel shape to use
kernel@_size : (a float)
        kernel size - voxels for box/boxv, mm for sphere, mm sigma for gauss
        exclusive: kernel@_file
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{DilateInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:dilateinput}

\subsection{\texttt{ErodeImage}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:erodeimage}
Wraps command \textbf{fslmaths}

Use fslmaths to perform a spatial erosion of an image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
kernel@_file : (an existing file name)
        use external file for kernel
        exclusive: kernel@_size
kernel@_shape : ('3D' or '2D' or 'box' or 'boxv' or 'gauss' or 'sphere' or 'file')
        kernel shape to use
kernel@_size : (a float)
        kernel size - voxels for box/boxv, mm for sphere, mm sigma for gauss
        exclusive: kernel@_file
minimum@_filter : (a boolean)
        if true, minimum filter rather than erosion by zeroing-out
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{ErodeInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:erodeinput}

\subsection{\texttt{IsotropicSmooth}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:isotropicsmooth}
Wraps command \textbf{fslmaths}

Use fslmaths to spatially smooth an image with a gaussian kernel.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
fwhm : (a float)
        fwhm of smoothing kernel
        exclusive: sigma
in@_file : (an existing file name)
        image to operate on
sigma : (a float)
        sigma of smoothing kernel
        exclusive: fwhm

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{IsotropicSmoothInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:isotropicsmoothinput}

\subsection{\texttt{KernelInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:kernelinput}

\subsection{\texttt{MathsCommand}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:mathscommand}
Wraps command \textbf{fslmaths}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{MathsInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:mathsinput}

\subsection{\texttt{MathsOutput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:mathsoutput}

\subsection{\texttt{MeanImage}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:meanimage}
Wraps command \textbf{fslmaths}

Use fslmaths to generate a mean image across a given dimension.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dimension : ('T' or 'X' or 'Y' or 'Z')
        dimension to mean across
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{MeanImageInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:meanimageinput}

\subsection{\texttt{MultiImageMaths}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:multiimagemaths}
Wraps command \textbf{fslmaths}

Use fslmaths to perform a sequence of mathematical operations.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.maths:examples}
from nipype.interfaces.fsl import MultiImageMaths
maths = MultiImageMaths()
maths.inputs.in\_file = ``functional.nii''
maths.inputs.op\_string = ``-add \%s -mul -1 -div \%s''
maths.inputs.operand\_files = {[}''functional2.nii'', ``functional3.nii''{]}
maths.inputs.out\_file = functional4.nii
maths.cmdline
fslmaths functional1.nii -add functional2.nii -mul -1 -div functional3.nii functional4.nii

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
op@_string : (a string)
        python formatted string of operations to perform
operand@_files : (a list of items which are an existing file name)
        list of file names to plug into op string

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{MultiImageMathsInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:multiimagemathsinput}

\subsection{\texttt{SpatialFilter}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:spatialfilter}
Wraps command \textbf{fslmaths}

Use fslmaths to spatially filter an image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
operation : ('mean' or 'median' or 'meanu')
        operation to filter with

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
kernel@_file : (an existing file name)
        use external file for kernel
        exclusive: kernel@_size
kernel@_shape : ('3D' or '2D' or 'box' or 'boxv' or 'gauss' or 'sphere' or 'file')
        kernel shape to use
kernel@_size : (a float)
        kernel size - voxels for box/boxv, mm for sphere, mm sigma for gauss
        exclusive: kernel@_file
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{SpatialFilterInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:spatialfilterinput}

\subsection{\texttt{TemporalFilter}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:temporalfilter}
Wraps command \textbf{fslmaths}

Use fslmaths to apply a low, high, or bandpass temporal filter to a timeseries.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
highpass@_sigma : (a float)
        highpass filter sigma (in volumes)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
lowpass@_sigma : (a float)
        lowpass filter sigma (in volumes)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{TemporalFilterInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:temporalfilterinput}

\subsection{\texttt{Threshold}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:threshold}
Wraps command \textbf{fslmaths}

Use fslmaths to apply a threshold to an image in a variety of ways.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
thresh : (a float)
        threshold value

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
direction : ('below' or 'above')
        zero-out either below or above thresh value
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
use@_nonzero@_voxels : (a boolean)
        use nonzero voxels to caluclate robust range
        requires: use@_robust@_range
use@_robust@_range : (a boolean)
        inteperet thresh as percentage (0-100) of robust range
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{UnaryMaths}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:unarymaths}
Wraps command \textbf{fslmaths}

Use fslmaths to perorm a variety of mathematical operations on an image.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        image to operate on
operation : ('exp' or 'log' or 'sin' or 'cos' or 'sqr' or 'sqrt' or 'recip' or 'abs' or 'bin' or 'index')
        operation to perform

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
internal@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for calculations (default is float)
out@_file : (a file name)
        image to write
output@_datatype : ('float' or 'char' or 'int' or 'short' or 'double' or 'input')
        datatype to use for output (default uses input type)
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image written after calculations
\end{Verbatim}


\subsection{\texttt{UnaryMathsInput}}
\label{interfaces/generated/nipype.interfaces.fsl.maths:unarymathsinput}

\section{nipype.interfaces.fsl.model}
\label{interfaces/generated/nipype.interfaces.fsl.model:nipype-interfaces-fsl-model}\label{interfaces/generated/nipype.interfaces.fsl.model::doc}

\subsection{\texttt{Cluster}}
\label{interfaces/generated/nipype.interfaces.fsl.model:cluster}
Wraps command \textbf{cluster}

Uses FSL cluster to perform clustering on statistical output


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cl} \PYG{o}{=} \PYG{n}{Cluster}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{threshold} \PYG{o}{=} \PYG{l+m+mf}{2.3}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{zstat1.nii.gz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}localmax\PYGZus{}txt\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{stats.txt}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cl}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'cluster --in=zstat1.nii.gz --olmax=stats.txt --thresh=2.3000000000'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input volume
threshold : (a float)
        threshold for input volume

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
connectivity : (an integer)
        the connectivity of voxels (default 26)
cope@_file : (a file name)
        cope volume
dlh : (a float)
        smoothness estimate = sqrt(det(Lambda))
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
find@_min : (a boolean)
        find minima instead of maxima
fractional : (a boolean)
        interprets the threshold as a fraction of the robust range
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
minclustersize : (a boolean)
        prints out minimum significant cluster size
no@_table : (a boolean)
        suppresses printing of the table info
num@_maxima : (an integer)
        no of local maxima to report
out@_index@_file : (a boolean or a file name)
        output of cluster index (in size order)
out@_localmax@_txt@_file : (a boolean or a file name)
        local maxima text file
out@_localmax@_vol@_file : (a boolean or a file name)
        output of local maxima volume
out@_max@_file : (a boolean or a file name)
        filename for output of max image
out@_mean@_file : (a boolean or a file name)
        filename for output of mean image
out@_pval@_file : (a boolean or a file name)
        filename for image output of log pvals
out@_size@_file : (a boolean or a file name)
        filename for output of size image
out@_threshold@_file : (a boolean or a file name)
        thresholded image
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
peak@_distance : (a float)
        minimum distance between local maxima/minima, in mm (default 0)
pthreshold : (a float)
        p-threshold for clusters
        requires: dlh,volume
std@_space@_file : (a file name)
        filename for standard-space volume
use@_mm : (a boolean)
        use mm, not voxel, coordinates
volume : (an integer)
        number of voxels in the mask
warpfield@_file : (a file name)
        file contining warpfield
xfm@_file : (a file name)
        filename for Linear: input-@textgreater[]standard-space transform. Non-linear: input-@textgreater[]highres transform
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
index@_file : (a file name)
        output of cluster index (in size order)
localmax@_txt@_file : (a file name)
        local maxima text file
localmax@_vol@_file : (a file name)
        output of local maxima volume
max@_file : (a file name)
        filename for output of max image
mean@_file : (a file name)
        filename for output of mean image
pval@_file : (a file name)
        filename for image output of log pvals
size@_file : (a file name)
        filename for output of size image
threshold@_file : (a file name)
        thresholded image
\end{Verbatim}


\subsection{\texttt{ContrastMgr}}
\label{interfaces/generated/nipype.interfaces.fsl.model:contrastmgr}
Wraps command \textbf{contrast\_mgr}

Use FSL contrast\_mgr command to evaluate contrasts

In interface mode this file assumes that all the required inputs are in the
same location.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
corrections : (an existing file name)
        statistical corrections used within FILM modelling
dof@_file : (an existing file name)
        degrees of freedom
param@_estimates : (an existing file name)
        Parameter estimates for each column of the design matrix
sigmasquareds : (an existing file name)
        summary of residuals, See Woolrich, et. al., 2001
tcon@_file : (an existing file name)
        contrast file containing T-contrasts

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
contrast@_num : (an integer)
        contrast number to start labeling copes from
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fcon@_file : (an existing file name)
        contrast file containing F-contrasts
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
suffix : (a string)
        suffix to put on the end of the cope filename before the contrast number, default is nothing
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
copes : (an existing file name)
        Contrast estimates for each contrast
fstats : (an existing file name)
        f-stat file for each contrast
neffs : (an existing file name)
        neff file ?? for each contrast
tstats : (an existing file name)
        t-stat file for each contrast
varcopes : (an existing file name)
        Variance estimates for each contrast
zstats : (an existing file name)
        z-stat file for each contrast
\end{Verbatim}


\subsection{\texttt{FEAT}}
\label{interfaces/generated/nipype.interfaces.fsl.model:feat}
Wraps command \textbf{feat}

Uses FSL feat to calculate first level stats

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
fsf@_file : (a file name)
        File specifying the feat design spec file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
feat@_dir : (an existing directory name)
        Unknown
\end{Verbatim}


\subsection{\texttt{FEATModel}}
\label{interfaces/generated/nipype.interfaces.fsl.model:featmodel}
Wraps command \textbf{feat\_model}

Uses FSL feat\_model to generate design.mat files

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
ev@_files : (an existing file name)
        Event spec files generated by level1design
fsf@_file : (a file name)
        File specifying the feat design spec file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
con@_file : (an existing file name)
        Contrast file containing contrast vectors
design@_cov : (an existing file name)
        Graphical representation of design covariance
design@_file : (an existing file name)
        Mat file containing ascii matrix for design
design@_image : (an existing file name)
        Graphical representation of design matrix
fcon@_file : (a file name)
        Contrast file containing contrast vectors
\end{Verbatim}


\subsection{\texttt{FEATRegister}}
\label{interfaces/generated/nipype.interfaces.fsl.model:featregister}
Register feat directories to a specific standard

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
feat@_dirs : (a directory name)
        Lower level feat dirs
reg@_image : (a file name)
        image to register to (will be treated as standard)

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
reg@_dof : (an integer)
        registration degrees of freedom
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
fsf@_file : (an existing file name)
        FSL feat specification file
\end{Verbatim}


\subsection{\texttt{FILMGLS}}
\label{interfaces/generated/nipype.interfaces.fsl.model:filmgls}
Wraps command \textbf{film\_gls}

Use FSL film\_gls command to fit a design matrix to voxel timeseries


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id1}
Initialize with no options, assigning them when calling run:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FILMGLS}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fgls}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{in\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{design\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{thresh}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{rn}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{stats}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

Assign options through the \code{inputs} attribute:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FILMGLS}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{design\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{design.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{threshold} \PYG{o}{=} \PYG{l+m+mi}{10}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{results\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{stats}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fgls}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Specify options when creating an instance:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fgls} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FILMGLS}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{design\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{design.mat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{threshold}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{results\PYGZus{}dir}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{stats}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fgls}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input data file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
autocorr@_estimate@_only : (a boolean)
        perform autocorrelation estimatation only
        exclusive: autocorr@_estimate@_only,fit@_armodel,tukey@_window,multitaper@_product,use@_pava,autocorr@_noestimate
autocorr@_noestimate : (a boolean)
        do not estimate autocorrs
        exclusive: autocorr@_estimate@_only,fit@_armodel,tukey@_window,multitaper@_product,use@_pava,autocorr@_noestimate
brightness@_threshold : (an integer)
        susan brightness threshold, otherwise it is estimated
design@_file : (an existing file name)
        design matrix file
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fit@_armodel : (a boolean)
        fits autoregressive model - default is to use tukey with M=sqrt(numvols)
        exclusive: autocorr@_estimate@_only,fit@_armodel,tukey@_window,multitaper@_product,use@_pava,autocorr@_noestimate
full@_data : (a boolean)
        output full data
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask@_size : (an integer)
        susan mask size
multitaper@_product : (an integer)
        multitapering with slepian tapers and num is the time-bandwidth product
        exclusive: autocorr@_estimate@_only,fit@_armodel,tukey@_window,multitaper@_product,use@_pava,autocorr@_noestimate
output@_pwdata : (a boolean)
        output prewhitened data and average design matrix
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
results@_dir : (a directory name)
        directory to store results in
smooth@_autocorr : (a boolean)
        Smooth auto corr estimates
threshold : (a float)
        threshold
tukey@_window : (an integer)
        tukey window size to estimate autocorr
        exclusive: autocorr@_estimate@_only,fit@_armodel,tukey@_window,multitaper@_product,use@_pava,autocorr@_noestimate
use@_pava : (a boolean)
        estimates autocorr using PAVA
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
corrections : (an existing file name)
        statistical corrections used within FILM modelling
dof@_file : (an existing file name)
        degrees of freedom
logfile : (an existing file name)
        FILM run logfile
param@_estimates : (an existing file name)
        Parameter estimates for each column of the design matrix
residual4d : (an existing file name)
        Model fit residual mean-squared error for each time point
results@_dir : (an existing directory name)
        directory storing model estimation output
sigmasquareds : (an existing file name)
        summary of residuals, See Woolrich, et. al., 2001
\end{Verbatim}


\subsection{\texttt{FLAMEO}}
\label{interfaces/generated/nipype.interfaces.fsl.model:flameo}
Wraps command \textbf{flameo}

Use FSL flameo command to perform higher level model fits


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id2}
Initialize FLAMEO with no options, assigning them when calling run:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flameo} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLAMEO}\PYG{p}{(}\PYG{n}{cope\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{cope.nii.gz}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{var\PYGZus{}cope\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{varcope.nii.gz}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{cov\PYGZus{}split\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{cov\PYGZus{}split.mat}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{design\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{design.mat}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{t\PYGZus{}con\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{design.con}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{mask\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}\PYG{p}{,}                             \PYG{n}{run\PYGZus{}mode}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fe}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flameo}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'flameo --copefile=cope.nii.gz --covsplitfile=cov\PYGZus{}split.mat --designfile=design.mat --ld=stats --maskfile=mask.nii --runmode=fe --tcontrastsfile=design.con --varcopefile=varcope.nii.gz'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
cope@_file : (an existing file name)
        cope regressor data file
cov@_split@_file : (an existing file name)
        ascii matrix specifying the groups the covariance is split into
design@_file : (an existing file name)
        design matrix file
mask@_file : (an existing file name)
        mask file
run@_mode : ('fe' or 'ols' or 'flame1' or 'flame12')
        inference to perform
t@_con@_file : (an existing file name)
        ascii matrix specifying t-contrasts

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
burnin : (an integer)
        number of jumps at start of mcmc to be discarded
dof@_var@_cope@_file : (an existing file name)
        dof data file for varcope data
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
f@_con@_file : (an existing file name)
        ascii matrix specifying f-contrasts
fix@_mean : (a boolean)
        fix mean for tfit
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
infer@_outliers : (a boolean)
        infer outliers - not for fe
log@_dir : (a directory name)
        Unknown
n@_jumps : (an integer)
        number of jumps made by mcmc
no@_pe@_outputs : (a boolean)
        do not output pe files
outlier@_iter : (an integer)
        Number of max iterations to use when inferring outliers. Default is 12.
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
sample@_every : (an integer)
        number of jumps for each sample
sigma@_dofs : (an integer)
        sigma (in mm) to use for Gaussian smoothing the DOFs in FLAME 2. Default is 1mm, -1 indicates no smoothing
var@_cope@_file : (an existing file name)
        varcope weightings data file
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
copes   Contrast estimates for each contrast
mrefvars        mean random effect variances for each contrast
pes     Parameter estimates for each column of the design matrixfor each voxel
res4d   Model fit residual mean-squared error for each time point
stats@_dir : (an existing directory name)
        directory storing model estimation output
tdof    temporal dof file for each contrast
tstats  t-stat file for each contrast
var@_copes       Variance estimates for each contrast
weights weights file for each contrast
zstats  z-stat file for each contrast
\end{Verbatim}


\subsection{\texttt{L2Model}}
\label{interfaces/generated/nipype.interfaces.fsl.model:l2model}
Generate subject specific second level model


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{import} \PYG{n}{L2Model}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{model} \PYG{o}{=} \PYG{n}{L2Model}\PYG{p}{(}\PYG{n}{num\PYGZus{}copes}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)} \PYG{c}{\# 3 sessions}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
num@_copes : (an integer)
        number of copes to be combined

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
design@_con : (an existing file name)
        design contrast file
design@_grp : (an existing file name)
        design group file
design@_mat : (an existing file name)
        design matrix file
\end{Verbatim}


\subsection{\texttt{Level1Design}}
\label{interfaces/generated/nipype.interfaces.fsl.model:level1design}
Generate FEAT specific files


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{l+m+mf}{2.5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{dgamma}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{n+nb+bp}{False}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{session\PYGZus{}info} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info.npz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bases : (a dictionary with keys which are 'dgamma' and with values which are a dictionary with keys which are 'derivs' and with values which are a boolean or a dictionary with keys which are 'gamma' and with values which are a dictionary with keys which are 'derivs' and with values which are a boolean or a dictionary with keys which are 'none' and with values which are None)
        name of basis function and options e.g., {'dgamma': {'derivs': True}}
interscan@_interval : (a float)
        Interscan  interval (in secs)
model@_serial@_correlations : (a boolean)
        Option to model serial correlations using an autoregressive estimator (order 1). Setting this option is only useful in the context of the fsf file. If you set this to False, you need to repeat this option for FILMGLS by setting autocorr@_noestimate to True
session@_info    Session specific information generated by []`[]`modelgen.SpecifyModel[]`[]`

@PYGZlb[]Optional@PYGZrb[]
contrasts : (a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float) or a tuple of the form: (a string, 'F', a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float)))
        List of contrasts with each contrast being a list of the form - @PYGZlb[]('name', 'stat', @PYGZlb[]condition list@PYGZrb[], @PYGZlb[]weight list@PYGZrb[], @PYGZlb[]session list@PYGZrb[])@PYGZrb[]. if session list is None or not provided, all sessions are used. For F contrasts, the condition list should contain previously defined T-contrasts.
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
ev@_files : (an existing file name)
        condition information files
fsf@_files : (an existing file name)
        FSL feat specification files
\end{Verbatim}


\subsection{\texttt{MELODIC}}
\label{interfaces/generated/nipype.interfaces.fsl.model:melodic}
Wraps command \textbf{melodic}

Multivariate Exploratory Linear Optimised Decomposition into Independent Components


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup} \PYG{o}{=} \PYG{n}{MELODIC}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{approach} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{tica}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{functional2.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{functional3.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{no\PYGZus{}bet} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bg\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mi}{10}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{tr\PYGZus{}sec} \PYG{o}{=} \PYG{l+m+mf}{1.5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mm\PYGZus{}thresh} \PYG{o}{=} \PYG{l+m+mf}{0.5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}stats} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}des} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{timeDesign.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{t\PYGZus{}con} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{timeDesign.con}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{s\PYGZus{}des} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{subjectDesign.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{s\PYGZus{}con} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{subjectDesign.con}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{groupICA.out}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{melodic\PYGZus{}setup}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (an existing file name)
        input file names (either single file name or a list)

@PYGZlb[]Optional@PYGZrb[]
ICs : (an existing file name)
        filename of the IC components file for mixture modelling
approach : (a string)
        approach for decomposition, 2D: defl, symm (default), 3D: tica (default), concat
args : (a string)
        Additional parameters to the command
bg@_image : (an existing file name)
        specify background image for report (default: mean image)
bg@_threshold : (a float)
        brain/non-brain threshold used to mask non-brain voxels, as a percentage (only if --nobet selected)
cov@_weight : (a float)
        voxel-wise weights for the covariance matrix (e.g. segmentation information)
dim : (an integer)
        dimensionality reduction into @#num dimensions(default: automatic estimation)
dim@_est : (a string)
        use specific dim. estimation technique: lap, bic, mdl, aic, mean (default: lap)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
epsilon : (a float)
        minimum error change
epsilonS : (a float)
        minimum error change for rank-1 approximation in TICA
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
log@_power : (a boolean)
        calculate log of power for frequency spectrum
mask : (an existing file name)
        file name of mask for thresholding
max@_restart : (an integer)
        maximum number of restarts
maxit : (an integer)
        maximum number of iterations before restart
mix : (an existing file name)
        mixing matrix for mixture modelling / filtering
mm@_thresh : (a float)
        threshold for Mixture Model based inference
no@_bet : (a boolean)
        switch off BET
no@_mask : (a boolean)
        switch off masking
no@_mm : (a boolean)
        switch off mixture modelling on IC maps
non@_linearity : (a string)
        nonlinearity: gauss, tanh, pow3, pow4
num@_ICs : (an integer)
        number of IC's to extract (for deflation approach)
out@_all : (a boolean)
        output everything
out@_dir : (a directory name)
        output directory name
out@_mean : (a boolean)
        output mean volume
out@_orig : (a boolean)
        output the original ICs
out@_pca : (a boolean)
        output PCA results
out@_stats : (a boolean)
        output thresholded maps and probability maps
out@_unmix : (a boolean)
        output unmixing matrix
out@_white : (a boolean)
        output whitening/dewhitening matrices
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
pbsc : (a boolean)
        switch off conversion to percent BOLD signal change
rem@_cmp : (a list of items which are an integer)
        component numbers to remove
remove@_deriv : (a boolean)
        removes every second entry in paradigm file (EV derivatives)
report : (a boolean)
        generate Melodic web report
report@_maps : (a string)
        control string for spatial map images (see slicer)
s@_con : (an existing file name)
        t-contrast matrix across subject-domain
s@_des : (an existing file name)
        design matrix across subject-domain
sep@_vn : (a boolean)
        switch off joined variance normalization
sep@_whiten : (a boolean)
        switch on separate whitening
smode : (an existing file name)
        matrix of session modes for report generation
t@_con : (an existing file name)
        t-contrast matrix across time-domain
t@_des : (an existing file name)
        design matrix across time-domain
tr@_sec : (a float)
        TR in seconds
update@_mask : (a boolean)
        switch off mask updating
var@_norm : (a boolean)
        switch off variance normalization
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_dir : (an existing directory name)
        Unknown
\end{Verbatim}


\subsection{\texttt{MultipleRegressDesign}}
\label{interfaces/generated/nipype.interfaces.fsl.model:multipleregressdesign}
Generate multiple regression design

\begin{notice}{note}{Note:}
FSL does not demean columns for higher level analysis.
\end{notice}

Please see \href{http://www.fmrib.ox.ac.uk/fsl/feat5/detail.html\#higher}{FSL documentation}
for more details on model specification for higher level analysis.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{import} \PYG{n}{L2Model}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{model} \PYG{o}{=} \PYG{n}{MultipleRegressDesign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{model}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{group mean}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{reg1}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{model}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{regressors} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{reg1}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,}\PYG{n}{reg2}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{2.}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{model}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
contrasts : (a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'F', a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float)))
        List of contrasts with each contrast being a list of the form - @PYGZlb[]('name', 'stat', @PYGZlb[]condition list@PYGZrb[], @PYGZlb[]weight list@PYGZrb[])@PYGZrb[]. if session list is None or not provided, all sessions are used. For F contrasts, the condition list should contain previously defined T-contrasts without any weight list.
regressors : (a dictionary with keys which are a string and with values which are a list of items which are a float)
        dictionary containing named lists of regressors

@PYGZlb[]Optional@PYGZrb[]
groups : (a list of items which are an integer)
        list of group identifiers (defaults to single group)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
design@_con : (an existing file name)
        design t-contrast file
design@_fts : (an existing file name)
        design f-contrast file
design@_grp : (an existing file name)
        design group file
design@_mat : (an existing file name)
        design matrix file
\end{Verbatim}


\subsection{\texttt{SMM}}
\label{interfaces/generated/nipype.interfaces.fsl.model:smm}
Wraps command \textbf{mm --ld=logdir}

Spatial Mixture Modelling. For more detail on the spatial mixture modelling see
Mixture Models with Adaptive Spatial Regularisation for Segmentation with an Application to FMRI Data;
Woolrich, M., Behrens, T., Beckmann, C., and Smith, S.; IEEE Trans. Medical Imaging, 24(1):1-11, 2005.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
mask : (a file name)
        mask file
spatial@_data@_file : (an existing file name)
        statistics spatial map

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
no@_deactivation@_class : (a boolean)
        enforces no deactivation class
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
activation@_p@_map : (an existing file name)
        Unknown
deactivation@_p@_map : (an existing file name)
        Unknown
null@_p@_map : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{SmoothEstimate}}
\label{interfaces/generated/nipype.interfaces.fsl.model:smoothestimate}
Wraps command \textbf{smoothest}

Estimates the smoothness of an image


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.model:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est} \PYG{o}{=} \PYG{n}{SmoothEstimate}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{zstat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{zstat1.nii.gz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{mask\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'smoothest --mask=mask.nii --zstat=zstat1.nii.gz'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
dof : (an integer)
        number of degrees of freedom
        exclusive: zstat@_file
mask@_file : (an existing file name)
        brain mask volume

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
residual@_fit@_file : (an existing file name)
        residual-fit image file
        requires: dof
zstat@_file : (an existing file name)
        zstat image file
        exclusive: dof
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
dlh : (a float)
        smoothness estimate sqrt(det(Lambda))
resels : (a float)
        number of resels
volume : (an integer)
        number of voxels in mask
\end{Verbatim}


\section{nipype.interfaces.fsl.preprocess}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:nipype-interfaces-fsl-preprocess}\label{interfaces/generated/nipype.interfaces.fsl.preprocess::doc}

\subsection{\texttt{ApplyWarp}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:applywarp}
Wraps command \textbf{applywarp}

Use FSL's applywarp to apply the results of a FNIRT registration


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{aw} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ApplyWarp}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{aw}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{aw}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{ref\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{aw}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{my\PYGZus{}coefficients\PYGZus{}filed.nii}\PYG{l+s}{'} 
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{aw}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
field@_file : (an existing file name)
        file containing warp field
in@_file : (an existing file name)
        image to be warped
ref@_file : (an existing file name)
        reference image

@PYGZlb[]Optional@PYGZrb[]
abswarp : (a boolean)
        treat warp field as absolute: x' = w(x)
        exclusive: relwarp
args : (a string)
        Additional parameters to the command
datatype : ('char' or 'short' or 'int' or 'float' or 'double')
        Force output data type @PYGZlb[]char short int float double@PYGZrb[].
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
interp : ('nn' or 'trilinear' or 'sinc' or 'spline')
        interpolation method
mask@_file : (an existing file name)
        filename for mask image (in reference space)
out@_file : (a file name)
        output filename
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
postmat : (an existing file name)
        filename for post-transform (affine matrix)
premat : (an existing file name)
        filename for pre-transform (affine matrix)
relwarp : (a boolean)
        treat warp field as relative: x' = x + w(x)
        exclusive: abswarp
superlevel : ('a' or an integer)
        level of intermediary supersampling, a for 'automatic' or integer level. Default = 2
supersample : (a boolean)
        intermediary supersampling of output, default is off
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        Warped output file
\end{Verbatim}


\subsection{\texttt{ApplyXfm}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:applyxfm}
Wraps command \textbf{flirt}

Currently just a light wrapper around FLIRT,
with no modifications

ApplyXfm is used to apply an existing tranform to an image


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ApplyXfm}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}matrix\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{trans.mat}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{newfile.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{reference} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{apply\PYGZus{}xfm} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{result} \PYG{o}{=} \PYG{n}{applyxfm}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file
reference : (an existing file name)
        reference file

@PYGZlb[]Optional@PYGZrb[]
angle@_rep : ('quaternion' or 'euler')
        representation of rotation angles
apply@_xfm : (a boolean)
        apply transformation supplied by in@_matrix@_file
        requires: in@_matrix@_file
args : (a string)
        Additional parameters to the command
bins : (an integer)
        number of histogram bins
coarse@_search : (an integer)
        coarse search delta angle
cost : ('mutualinfo' or 'corratio' or 'normcorr' or 'normmi' or 'leastsq' or 'labeldiff')
        cost function
cost@_func : ('mutualinfo' or 'corratio' or 'normcorr' or 'normmi' or 'leastsq' or 'labeldiff')
        cost function
datatype : ('char' or 'short' or 'int' or 'float' or 'double')
        force output data type
display@_init : (a boolean)
        display initial matrix
dof : (an integer)
        number of transform degrees of freedom
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fine@_search : (an integer)
        fine search delta angle
force@_scaling : (a boolean)
        force rescaling even for low-res images
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_matrix@_file : (a file name)
        input 4x4 affine matrix
in@_weight : (an existing file name)
        File for input weighting volume
interp : ('trilinear' or 'nearestneighbour' or 'sinc')
        final interpolation method used in reslicing
min@_sampling : (a float)
        set minimum voxel dimension for sampling
no@_clamp : (a boolean)
        do not use intensity clamping
no@_resample : (a boolean)
        do not change input sampling
no@_resample@_blur : (a boolean)
        do not use blurring on downsampling
no@_search : (a boolean)
        set all angular searches to ranges 0 to 0
out@_file : (a file name)
        registered output file
out@_matrix@_file : (a file name)
        output affine matrix in 4x4 asciii format
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
padding@_size : (an integer)
        for applyxfm: interpolates outside image by size
ref@_weight : (an existing file name)
        File for reference weighting volume
rigid2D : (a boolean)
        use 2D rigid body mode - ignores dof
schedule : (an existing file name)
        replaces default schedule
searchr@_x : (a list of from 2 to 2 items which are an integer)
        search angles along x-axis, in degrees
searchr@_y : (a list of from 2 to 2 items which are an integer)
        search angles along y-axis, in degrees
searchr@_z : (a list of from 2 to 2 items which are an integer)
        search angles along z-axis, in degrees
sinc@_width : (an integer)
        full-width in voxels
sinc@_window : ('rectangular' or 'hanning' or 'blackman')
        sinc window
uses@_qform : (a boolean)
        initialize using sform or qform
verbose : (an integer)
        verbose mode, 0 is least
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        path/name of registered file (if generated)
out@_matrix@_file : (an existing file name)
        path/name of calculated affine transform (if generated)
\end{Verbatim}


\subsection{\texttt{BET}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:bet}
Wraps command \textbf{bet}

Use FSL BET command for skull stripping.

For complete details, see the \href{http://www.fmrib.ox.ac.uk/fsl/bet2/index.html}{BET Documentation.}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import}  \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{btr} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{btr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{btr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{frac} \PYG{o}{=} \PYG{l+m+mf}{0.7}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{btr}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file to skull strip

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
center : (a list of at most 3 items which are an integer)
        center of gravity in voxels
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
frac : (a float)
        fractional intensity threshold
functional : (a boolean)
        apply to 4D fMRI data
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (a boolean)
        create binary mask image
mesh : (a boolean)
        generate a vtk mesh brain surface
no@_output : (a boolean)
        Don't generate segmented output
out@_file : (a file name)
        name of output skull stripped image
outline : (a boolean)
        create surface outline image
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
padding : (a boolean)
        improve BET if FOV is very small in Z (by temporarily padding end slices)
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
radius : (an integer)
        head radius
reduce@_bias : (a boolean)
        bias field and neck cleanup
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
remove@_eyes : (a boolean)
        eye @& optic nerve cleanup (can be useful in SIENA)
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
robust : (a boolean)
        robust brain centre estimation (iterates BET several times)
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
skull : (a boolean)
        create skull image
surfaces : (a boolean)
        run bet2 and then betsurf to get additional skull and scalp surfaces (includes registrations)
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
t2@_guided : (a file name)
        as with creating surfaces, when also feeding in non-brain-extracted T2 (includes registrations)
        exclusive: functional,reduce@_bias,robust,padding,remove@_eyes,surfaces,t2@_guided
threshold : (a boolean)
        apply thresholding to segmented brain image and mask
vertical@_gradient : (a float)
        vertical gradient in fractional intensity threshold (-1, 1)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
mask@_file : (a file name)
        path/name of binary brain mask (if generated)
meshfile : (a file name)
        path/name of vtk mesh file (if generated)
out@_file : (a file name)
        path/name of skullstripped file
outline@_file : (a file name)
        path/name of outline file (if generated)
\end{Verbatim}


\subsection{\texttt{FAST}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:fast}
Wraps command \textbf{fast}

Use FSL FAST for segmenting and bias correction.

For complete details, see the \href{http://www.fmrib.ox.ac.uk/fsl/fast4/index.html}{FAST Documentation.}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\end{Verbatim}

Assign options through the \code{inputs} attribute:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fastr} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FAST}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fastr}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{fastr}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (an existing file name)
        image, or multi-channel set of images, to be segmented

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bias@_iters : (1 @textless[]= an integer @textless[]= 10)
        number of main-loop iterations during bias-field removal
bias@_lowpass : (4 @textless[]= an integer @textless[]= 40)
        bias field smoothing extent (FWHM) in mm
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
hyper : (0.0 @textless[]= a floating point number @textless[]= 1.0)
        segmentation spatial smoothness
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
img@_type : (1 or 2 or 3)
        int specifying type of image: (1 = T1, 2 = T2, 3 = PD)
init@_seg@_smooth : (0.0001 @textless[]= a floating point number @textless[]= 0.1)
        initial segmentation spatial smoothness (during bias field estimation)
init@_transform : (an existing file name)
        @textless[]standard2input.mat@textgreater[] initialise using priors
iters@_afterbias : (an integer @textgreater[]= 1)
        number of main-loop iterations after bias-field removal
manual@_seg : (an existing file name)
        Filename containing intensities
mixel@_smooth : (0.0 @textless[]= a floating point number @textless[]= 1.0)
        spatial smoothness for mixeltype
no@_bias : (a boolean)
        do not remove bias field
no@_pve : (a boolean)
        turn off PVE (partial volume estimation)
number@_classes : (1 @textless[]= an integer @textless[]= 10)
        number of tissue-type classes
other@_priors : (a list of from 3 to 3 items which are a file name)
        alternative prior images
out@_basename : (a file name)
        base name of output files
output@_biascorrected : (a boolean)
        output restored image (bias-corrected image)
output@_biasfield : (a boolean)
        output estimated bias field
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
probability@_maps : (a boolean)
        outputs individual probability maps
segment@_iters : (1 @textless[]= an integer @textless[]= 50)
        number of segmentation-initialisation iterations
segments : (a boolean)
        outputs a separate binary image for each tissue type
use@_priors : (a boolean)
        use priors throughout
verbose : (a boolean)
        switch on diagnostic messages
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
bias@_field : (a file name)
        Unknown
mixeltype : (a file name)
        path/name of mixeltype volume file @_mixeltype
partial@_volume@_files : (a file name)
        Unknown
partial@_volume@_map : (a file name)
        path/name of partial volume file @_pveseg
probability@_maps : (a file name)
        Unknown
restored@_image : (a file name)
        Unknown
tissue@_class@_files : (a file name)
        Unknown
tissue@_class@_map : (an existing file name)
        path/name of binary segmented volume file one val for each class  @_seg
\end{Verbatim}


\subsection{\texttt{FLIRT}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:flirt}
Wraps command \textbf{flirt}

Use FSL FLIRT for coregistration.

For complete details, see the \href{http://www.fmrib.ox.ac.uk/fsl/flirt/index.html}{FLIRT Documentation.}
\begin{description}
\item[{To print out the command line help, use:}] \leavevmode
fsl.FLIRT().inputs\_help()

\end{description}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flt} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FLIRT}\PYG{p}{(}\PYG{n}{bins}\PYG{o}{=}\PYG{l+m+mi}{640}\PYG{p}{,} \PYG{n}{cost\PYGZus{}func}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mutualinfo}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{reference} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{moved\PYGZus{}subject.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{flt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}matrix\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{subject\PYGZus{}to\PYGZus{}template.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{flt}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file
reference : (an existing file name)
        reference file

@PYGZlb[]Optional@PYGZrb[]
angle@_rep : ('quaternion' or 'euler')
        representation of rotation angles
apply@_xfm : (a boolean)
        apply transformation supplied by in@_matrix@_file
        requires: in@_matrix@_file
args : (a string)
        Additional parameters to the command
bins : (an integer)
        number of histogram bins
coarse@_search : (an integer)
        coarse search delta angle
cost : ('mutualinfo' or 'corratio' or 'normcorr' or 'normmi' or 'leastsq' or 'labeldiff')
        cost function
cost@_func : ('mutualinfo' or 'corratio' or 'normcorr' or 'normmi' or 'leastsq' or 'labeldiff')
        cost function
datatype : ('char' or 'short' or 'int' or 'float' or 'double')
        force output data type
display@_init : (a boolean)
        display initial matrix
dof : (an integer)
        number of transform degrees of freedom
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fine@_search : (an integer)
        fine search delta angle
force@_scaling : (a boolean)
        force rescaling even for low-res images
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_matrix@_file : (a file name)
        input 4x4 affine matrix
in@_weight : (an existing file name)
        File for input weighting volume
interp : ('trilinear' or 'nearestneighbour' or 'sinc')
        final interpolation method used in reslicing
min@_sampling : (a float)
        set minimum voxel dimension for sampling
no@_clamp : (a boolean)
        do not use intensity clamping
no@_resample : (a boolean)
        do not change input sampling
no@_resample@_blur : (a boolean)
        do not use blurring on downsampling
no@_search : (a boolean)
        set all angular searches to ranges 0 to 0
out@_file : (a file name)
        registered output file
out@_matrix@_file : (a file name)
        output affine matrix in 4x4 asciii format
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
padding@_size : (an integer)
        for applyxfm: interpolates outside image by size
ref@_weight : (an existing file name)
        File for reference weighting volume
rigid2D : (a boolean)
        use 2D rigid body mode - ignores dof
schedule : (an existing file name)
        replaces default schedule
searchr@_x : (a list of from 2 to 2 items which are an integer)
        search angles along x-axis, in degrees
searchr@_y : (a list of from 2 to 2 items which are an integer)
        search angles along y-axis, in degrees
searchr@_z : (a list of from 2 to 2 items which are an integer)
        search angles along z-axis, in degrees
sinc@_width : (an integer)
        full-width in voxels
sinc@_window : ('rectangular' or 'hanning' or 'blackman')
        sinc window
uses@_qform : (a boolean)
        initialize using sform or qform
verbose : (an integer)
        verbose mode, 0 is least
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        path/name of registered file (if generated)
out@_matrix@_file : (an existing file name)
        path/name of calculated affine transform (if generated)
\end{Verbatim}


\subsection{\texttt{FNIRT}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:fnirt}
Wraps command \textbf{fnirt}

Use FSL FNIRT for non-linear registration.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnt} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FNIRT}\PYG{p}{(}\PYG{n}{affine\PYGZus{}file}\PYG{o}{=}\PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{trans.mat}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fnt}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{ref\PYGZus{}file}\PYG{o}{=}\PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}
\end{Verbatim}

T1 -\textgreater{} Mni153

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnirt\PYGZus{}mprage} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{FNIRT}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnirt\PYGZus{}mprage}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}fwhm} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{8}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnirt\PYGZus{}mprage}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subsampling\PYGZus{}scheme} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{]}
\end{Verbatim}

Specify the resolution of the warps

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnirt\PYGZus{}mprage}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{warp\PYGZus{}resolution} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fnirt\PYGZus{}mprage}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{ref\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mni.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{warped\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{warped.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{fieldcoeff\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{fieldcoeff.nii}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

We can check the command line and confirm that it's what we expect.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fnirt\PYGZus{}mprage}\PYG{o}{.}\PYG{n}{cmdline}  
\PYG{g+go}{'fnirt --cout=fieldcoeff.nii --in=structural.nii --infwhm=8,4,2,2 --ref=mni.nii --subsamp=4,2,1,1 --warpres=6,6,6 --iout=warped.nii'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        name of input image
ref@_file : (an existing file name)
        name of reference image

@PYGZlb[]Optional@PYGZrb[]
affine@_file : (an existing file name)
        name of file containing affine transform
apply@_inmask : (a list of items which are 0 or 1)
        list of iterations to use input mask on (1 to use, 0 to skip)
        exclusive: skip@_inmask
apply@_intensity@_mapping : (a list of items which are 0 or 1)
        List of subsampling levels to apply intensity mapping for (0 to skip, 1 to apply)
        exclusive: skip@_intensity@_mapping
apply@_refmask : (a list of items which are 0 or 1)
        list of iterations to use reference mask on (1 to use, 0 to skip)
        exclusive: skip@_refmask
args : (a string)
        Additional parameters to the command
bias@_regularization@_lambda : (a float)
        Weight of regularisation for bias-field, default 10000
biasfield@_resolution : (a tuple of the form: (an integer, an integer, an integer))
        Resolution (in mm) of bias-field modelling local intensities, default 50,50,50
config@_file : (an existing file name)
        Name of config file specifying command line arguments
derive@_from@_ref : (a boolean)
        If true, ref image is used to calculate derivatives. Default false
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
field@_file : (a boolean or a file name)
        name of output file with field or true
fieldcoeff@_file : (a boolean or a file name)
        name of output file with field coefficients or true
hessian@_precision : ('double' or 'float')
        Precision for representing Hessian, double or float. Default double
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_fwhm : (a list of items which are an integer)
        FWHM (in mm) of gaussian smoothing kernel for input volume, default @PYGZlb[]6,4,2,2@PYGZrb[]
in@_intensitymap@_file : (an existing file name)
        name of file/files containing initial intensity mapingusually generated by previos fnirt run
inmask@_file : (an existing file name)
        name of file with mask in input image space
inmask@_val : (a float)
        Value to mask out in --in image. Default =0.0
intensity@_mapping@_model : ('none' or 'global@_linear' or 'global@_non@_linearlocal@_linear' or 'global@_non@_linear@_with@_bias' or 'local@_non@_linear')
        Model for intensity-mapping
intensity@_mapping@_order : (an integer)
        Order of poynomial for mapping intensities, default 5
inwarp@_file : (an existing file name)
        name of file containing initial non-linear warps
jacobian@_file : (a boolean or a file name)
        name of file for writing out the Jacobianof the field (for diagnostic or VBM purposes)
jacobian@_range : (a tuple of the form: (a float, a float))
        Allowed range of Jacobian determinants, default 0.01,100.0
log@_file : (a file name)
        Name of log-file
max@_nonlin@_iter : (a list of items which are an integer)
        Max @# of non-linear iterations list, default @PYGZlb[]5,5,5,5@PYGZrb[]
modulatedref@_file : (a boolean or a file name)
        name of file for writing out intensity modulated--ref (for diagnostic purposes)
out@_intensitymap@_file : (a boolean or a file name)
        name of files for writing information pertaining to intensity mapping
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
ref@_fwhm : (a list of items which are an integer)
        FWHM (in mm) of gaussian smoothing kernel for ref volume, default @PYGZlb[]4,2,0,0@PYGZrb[]
refmask@_file : (an existing file name)
        name of file with mask in reference space
refmask@_val : (a float)
        Value to mask out in --ref image. Default =0.0
regularization@_lambda : (a list of items which are a float)
        Weight of regularisation, default depending on --ssqlambda and --regmod switches. See user documetation.
regularization@_model : ('membrane@_energy' or 'bending@_energy')
        Model for regularisation of warp-field @PYGZlb[]membrane@_energy bending@_energy@PYGZrb[], default bending@_energy
skip@_implicit@_in@_masking : (a boolean)
        skip implicit masking  based on valuein --in image. Default = 0
skip@_implicit@_ref@_masking : (a boolean)
        skip implicit masking  based on valuein --ref image. Default = 0
skip@_inmask : (a boolean)
        skip specified inmask if set, default false
        exclusive: apply@_inmask
skip@_intensity@_mapping : (a boolean)
        Skip estimate intensity-mapping default false
        exclusive: apply@_intensity@_mapping
skip@_lambda@_ssq : (a boolean)
        If true, lambda is not weighted by current ssq, default false
skip@_refmask : (a boolean)
        Skip specified refmask if set, default false
        exclusive: apply@_refmask
spline@_order : (an integer)
        Order of spline, 2-@textgreater[]Qadratic spline, 3-@textgreater[]Cubic spline. Default=3
subsampling@_scheme : (a list of items which are an integer)
        sub-sampling scheme, list, default @PYGZlb[]4,2,1,1@PYGZrb[]
warp@_resolution : (a tuple of the form: (an integer, an integer, an integer))
        (approximate) resolution (in mm) of warp basis in x-, y- and z-direction, default 10,10,10
warped@_file : (a file name)
        name of output image
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
field@_file : (a file name)
        file with warp field
fieldcoeff@_file : (an existing file name)
        file with field coefficients
jacobian@_file : (a file name)
        file containing Jacobian of the field
log@_file : (a file name)
        Name of log-file
modulatedref@_file : (a file name)
        file containing intensity modulated --ref
out@_intensitymap@_file : (a file name)
        file containing info pertaining to intensity mapping
warped@_file : (an existing file name)
        warped image
\end{Verbatim}


\subsection{\texttt{FUGUE}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:fugue}
Wraps command \textbf{fugue}

Use FSL FUGUE to unwarp epi's with fieldmaps


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id6}
Please insert examples for use of this command

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
asym@_se@_time : (a float)
        set the fieldmap asymmetric spin echo time (sec)
despike@_2dfilter : (a boolean)
        apply a 2D de-spiking filter
despike@_theshold : (a float)
        specify the threshold for de-spiking (default=3.0)
dwell@_time : (a float)
        set the EPI dwell time per phase-encode line - same as echo spacing - (sec)
dwell@_to@_asym@_ratio : (a float)
        set the dwell to asym time ratio
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fmap@_in@_file : (an existing file name)
        filename for loading fieldmap (rad/s)
fmap@_out@_file : (a file name)
        filename for saving fieldmap (rad/s)
fourier@_order : (an integer)
        apply Fourier (sinusoidal) fitting of order N
icorr : (a boolean)
        apply intensity correction to unwarping (pixel shift method only)
        requires: shift@_in@_file
icorr@_only : (a boolean)
        apply intensity correction only
        requires: unwarped@_file
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file : (an existing file name)
        filename of input volume
mask@_file : (an existing file name)
        filename for loading valid mask
median@_2dfilter : (a boolean)
        apply 2D median filtering
no@_extend : (a boolean)
        do not apply rigid-body extrapolation to the fieldmap
no@_gap@_fill : (a boolean)
        do not apply gap-filling measure to the fieldmap
nokspace : (a boolean)
        do not use k-space forward warping
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
pava : (a boolean)
        apply monotonic enforcement via PAVA
phase@_conjugate : (a boolean)
        apply phase conjugate method of unwarping
phasemap@_file : (an existing file name)
        filename for input phase image
poly@_order : (an integer)
        apply polynomial fitting of order N
save@_unmasked@_fmap : (a boolean or a file name)
        saves the unmasked fieldmap when using --savefmap
        requires: fmap@_out@_file
save@_unmasked@_shift : (a boolean or a file name)
        saves the unmasked shiftmap when using --saveshift
        requires: shift@_out@_file
shift@_in@_file : (an existing file name)
        filename for reading pixel shift volume
shift@_out@_file : (a file name)
        filename for saving pixel shift volume
smooth2d : (a float)
        apply 2D Gaussian smoothing of sigma N (in mm)
smooth3d : (a float)
        apply 3D Gaussian smoothing of sigma N (in mm)
unwarp@_direction : ('x' or 'y' or 'z' or 'x-' or 'y-' or 'z-')
        specifies direction of warping (default y)
unwarped@_file : (a file name)
        apply unwarping and save as filename
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
unwarped@_file : (an existing file name)
        unwarped file
\end{Verbatim}


\subsection{\texttt{MCFLIRT}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:mcflirt}
Wraps command \textbf{mcflirt}

Use FSL MCFLIRT to do within-modality motion correction.

For complete details, see the \href{http://www.fmrib.ox.ac.uk/fsl/mcflirt/index.html}{MCFLIRT Documentation.}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mcflt} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{MCFLIRT}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{,} \PYG{n}{cost}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{mutualinfo}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mcflt}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        timeseries to motion-correct

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
bins : (an integer)
        number of histogram bins
cost : ('mutualinfo' or 'woods' or 'corratio' or 'normcorr' or 'normmi' or 'leastsquares')
        cost function to optimize
dof : (an integer)
        degrees of freedom for the transformation
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
init : (an existing file name)
        inital transformation matrix
interpolation : ('trilinear' or 'nn' or 'sinc')
        interpolation method for transformation
mean@_vol : (a boolean)
        register to mean volume
out@_file : (a file name)
        file to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
ref@_file : (an existing file name)
        target image for motion correction
ref@_vol : (an integer)
        volume to align frames to
rotation : (an integer)
        scaling factor for rotation tolerances
save@_mats : (a boolean)
        save transformation matrices
save@_plots : (a boolean)
        save transformation parameters
save@_rms : (a boolean)
        save rms displacement parameters
scaling : (a float)
        scaling factor to use
smooth : (a float)
        smoothing factor for the cost function
stages : (an integer)
        stages (if 4, perform final search with sinc interpolation
stats@_imgs : (a boolean)
        produce variance and std. dev. images
use@_contour : (a boolean)
        run search on contour images
use@_gradient : (a boolean)
        run search on gradient images
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
mat@_file : (an existing file name)
        transformation matrices
mean@_img : (an existing file name)
        mean timeseries image
out@_file : (an existing file name)
        motion-corrected timeseries
par@_file : (an existing file name)
        text-file with motion parameters
rms@_files : (an existing file name)
        absolute and relative displacement parameters
std@_img : (an existing file name)
        standard deviation image
variance@_img : (an existing file name)
        variance image
\end{Verbatim}


\subsection{\texttt{PRELUDE}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:prelude}
Wraps command \textbf{prelude}

Use FSL prelude to do phase unwrapping


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id8}
Please insert examples for use of this command

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
complex@_phase@_file : (an existing file name)
        complex phase input volume
        exclusive: magnitude@_file,phase@_file
magnitude@_file : (an existing file name)
        file containing magnitude image
        exclusive: complex@_phase@_file
phase@_file : (an existing file name)
        raw phase file
        exclusive: complex@_phase@_file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
end : (an integer)
        final image number to process (default Inf)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
label@_file : (a file name)
        saving the area labels output
labelprocess2d : (a boolean)
        does label processing in 2D (slice at a time)
mask@_file : (an existing file name)
        filename of mask input volume
num@_partitions : (an integer)
        number of phase partitions to use
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
process2d : (a boolean)
        does all processing in 2D (slice at a time)
        exclusive: labelprocess2d
process3d : (a boolean)
        forces all processing to be full 3D
        exclusive: labelprocess2d,process2d
rawphase@_file : (a file name)
        saving the raw phase output
removeramps : (a boolean)
        remove phase ramps during unwrapping
savemask@_file : (a file name)
        saving the mask volume
start : (an integer)
        first image number to process (default 0)
threshold : (a float)
        intensity threshold for masking
unwrapped@_phase@_file : (a file name)
        file containing unwrapepd phase
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
unwrapped@_phase@_file : (a file name)
        unwrapped phase file
\end{Verbatim}


\subsection{\texttt{SUSAN}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:susan}
Wraps command \textbf{susan}

use FSL SUSAN to perform smoothing


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{print} \PYG{n}{anatfile} 
\PYG{g+go}{anatomical.nii }
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sus} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{SUSAN}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sus}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sus}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{brightness\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mf}{2000.0}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sus}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mf}{8.0}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{result} \PYG{o}{=} \PYG{n}{sus}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
brightness@_threshold : (a float)
        brightness threshold and should be greater than noise level and less than contrast of edges to be preserved.
fwhm : (a float)
        fwhm of smoothing, in mm, gets converted using sqrt(8*log(2))
in@_file : (an existing file name)
        filename of input timeseries

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dimension : (3 or 2)
        within-plane (2) or fully 3D (3)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        output file name
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
usans : (a list of at most 2 items which are a tuple of the form: (an existing file name, a float))
        determines whether the smoothing area (USAN) is to be found from secondary images (0, 1 or 2). A negative value for any brightness threshold will auto-set the threshold at 10@% of the robust range
use@_median : (1 or 0)
        whether to use a local median filter in the cases where single-point noise is detected
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
smoothed@_file : (an existing file name)
        smoothed output file
\end{Verbatim}


\subsection{\texttt{SliceTimer}}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:slicetimer}
Wraps command \textbf{slicetimer}

use FSL slicetimer to perform slice timing correction.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.preprocess:id10}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{SliceTimer}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interleaved} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{result} \PYG{o}{=} \PYG{n}{st}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        filename of input timeseries

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
custom@_order : (an existing file name)
        filename of single-column custom interleave order file (first slice is referred to as 1 not 0)
custom@_timings : (an existing file name)
        slice timings, in fractions of TR, range 0:1 (default is 0.5 = no shift)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
global@_shift : (a float)
        shift in fraction of TR, range 0:1 (default is 0.5 = no shift)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
index@_dir : (a boolean)
        slice indexing from top to bottom
interleaved : (a boolean)
        use interleaved acquisition
out@_file : (a file name)
        filename of output timeseries
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
slice@_direction : (1 or 2 or 3)
        direction of slice acquisition (x=1,y=2,z=3) - default is z
time@_repetition : (a float)
        Specify TR of data - default is 3s
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
slice@_time@_corrected@_file : (an existing file name)
        slice time corrected file
\end{Verbatim}


\section{nipype.interfaces.fsl.utils}
\label{interfaces/generated/nipype.interfaces.fsl.utils::doc}\label{interfaces/generated/nipype.interfaces.fsl.utils:nipype-interfaces-fsl-utils}

\subsection{\texttt{ConvertXFM}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:convertxfm}
Wraps command \textbf{convert\_xfm}

Use the FSL utility convert\_xfm to modify FLIRT transformation matrices.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{invt} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ConvertXFM}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{invt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{flirt.mat}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{invt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{invert\PYGZus{}xfm} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{invt}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{flirt\PYGZus{}inv.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{invt}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'convert\PYGZus{}xfm -omat flirt\PYGZus{}inv.mat -inverse flirt.mat'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input transformation matrix

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
concat@_xfm : (a boolean)
        write joint transformation of two input matrices
        exclusive: invert@_xfm,concat@_xfm,fix@_scale@_skew
        requires: in@_file2
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
fix@_scale@_skew : (a boolean)
        use secondary matrix to fix scale and skew
        exclusive: invert@_xfm,concat@_xfm,fix@_scale@_skew
        requires: in@_file2
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file2 : (an existing file name)
        second input matrix (for use with fix@_scale@_skew or concat@_xfm
invert@_xfm : (a boolean)
        invert input transformation
        exclusive: invert@_xfm,concat@_xfm,fix@_scale@_skew
out@_file : (a file name)
        final transformation matrix
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        output transformation matrix
\end{Verbatim}


\subsection{\texttt{ExtractROI}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:extractroi}
Wraps command \textbf{fslroi}

Uses FSL Fslroi command to extract region of interest (ROI)
from an image.

You can a) take a 3D ROI from a 3D data set (or if it is 4D, the
same ROI is taken from each time point and a new 4D data set is
created), b) extract just some time points from a 4D data set, or
c) control time and space limits to the ROI.  Note that the
arguments are minimum index and size (not maximum index).  So to
extract voxels 10 to 12 inclusive you would specify 10 and 3 (not
10 and 12).


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{import} \PYG{n}{ExtractROI}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{anatfile}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fslroi} \PYG{o}{=} \PYG{n}{ExtractROI}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{anatfile}\PYG{p}{,} \PYG{n}{roi\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{t\PYGZus{}min}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{t\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fslroi}\PYG{o}{.}\PYG{n}{cmdline} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{fslroi }\PYG{l+s+si}{\%s}\PYG{l+s}{ bar.nii 0 1}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{anatfile}
\PYG{g+go}{True}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
roi@_file : (a file name)
        output file
t@_min : (an integer)
        Unknown
t@_size : (an integer)
        Unknown
x@_min : (an integer)
        Unknown
x@_size : (an integer)
        Unknown
y@_min : (an integer)
        Unknown
y@_size : (an integer)
        Unknown
z@_min : (an integer)
        Unknown
z@_size : (an integer)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
roi@_file : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{FilterRegressor}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:filterregressor}
Wraps command \textbf{fsl\_regfilt}

Data de-noising by regressing out part of a design matrix

Uses simple OLS regression on 4D images

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
design@_file : (an existing file name)
        design  file name of the matrix with time courses (e.g. GLM design or MELODIC mixing matrix)
filter@_out : (a list of items which are an integer)
        filter out part of the regression model, e.g. -f '1,2,3'
in@_file : (an existing file name)
        input file name (4D image)

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (an existing file name)
        mask image file name
out@_file : (a boolean)
        output data
out@_vnscales : (a boolean)
        output scaling factors for variance normalization
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
var@_norm : (a boolean)
        perform variance-normalization on data
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        output file name for the filtered data
\end{Verbatim}


\subsection{\texttt{ImageMaths}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:imagemaths}
Wraps command \textbf{fslmaths}

Use FSL fslmaths command to allow mathematical manipulation of images

\href{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/intro/index.htm\#fslutils}{FSL info}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{anatfile}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{maths} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{ImageMaths}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{anatfile}\PYG{p}{,} \PYG{n}{op\PYGZus{}string}\PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-add 5}\PYG{l+s}{'}\PYG{p}{,}                                \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo\PYGZus{}maths.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{maths}\PYG{o}{.}\PYG{n}{cmdline} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{fslmaths }\PYG{l+s+si}{\%s}\PYG{l+s}{ -add 5 foo\PYGZus{}maths.nii}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{anatfile}
\PYG{g+go}{True}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file2 : (an existing file name)
        Unknown
op@_string : (a string)
        string defining the operation, i. e. -add
out@_data@_type : ('char' or 'short' or 'int' or 'float' or 'double' or 'input')
        output datatype, one of (char, short, int, float, double, input)
out@_file : (a file name)
        Unknown
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
suffix : (a string)
        out@_file suffix
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{ImageMeants}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:imagemeants}
Wraps command \textbf{fslmeants}

Use fslmeants for printing the average timeseries (intensities) to
the screen (or saves to a file). The average is taken over all voxels in the
mask (or all voxels in the image if no mask is specified)

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file for computing the average timeseries

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
eig : (a boolean)
        calculate Eigenvariate(s) instead of mean (output will have 0 mean)
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (an existing file name)
        input 3D mask
nobin : (a boolean)
        do not binarise the mask for calculation of Eigenvariates
order : (an integer)
        select number of Eigenvariates
out@_file : (a file name)
        name of output text matrix
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
show@_all : (a boolean)
        show all voxel time series (within mask) instead of averaging
spatial@_coord : (a list of items which are an integer)
        @textless[]x y z@textgreater[] requested spatial coordinate (instead of mask)
transpose : (a boolean)
        output results in transpose format (one row per voxel/mean)
use@_mm : (a boolean)
        use mm instead of voxel coordinates (for -c option)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        path/name of output text matrix
\end{Verbatim}


\subsection{\texttt{ImageStats}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:imagestats}
Wraps command \textbf{fslstats}

Use FSL fslstats command to calculate stats from images

\href{http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/intro/index.htm\#fslutils}{FSL info}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{import} \PYG{n}{ImageStats}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{funcfile}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{stats} \PYG{o}{=} \PYG{n}{ImageStats}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n}{funcfile}\PYG{p}{,} \PYG{n}{op\PYGZus{}string}\PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-M}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{stats}\PYG{o}{.}\PYG{n}{cmdline} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{fslstats }\PYG{l+s+si}{\%s}\PYG{l+s}{ -M}\PYG{l+s}{'}\PYG{o}{\%}\PYG{n}{funcfile}
\PYG{g+go}{True}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input file to generate stats of
op@_string : (a string)
        string defining the operation, options are applied in order, e.g. -M -l 10 -M will report the non-zero mean, apply athreshold and then report the new nonzero mean

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask@_file : (an existing file name)
        mask file used for option -k @%s
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
split@_4d : (a boolean)
        give a separate output line for each 3D volume of a 4D timeseries
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_stat        stats output
\end{Verbatim}


\subsection{\texttt{Merge}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:merge}
Wraps command \textbf{fslmerge}

Use fslmerge to concatenate images

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
dimension : ('t' or 'x' or 'y' or 'z')
        dimension along which the file will be merged
in@_files : (a list of items which are an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
merged@_file : (a file name)
        Unknown
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
merged@_file : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{Overlay}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:overlay}
Wraps command \textbf{overlay}

Use FSL's overlay command to combine background and statistical images into one volume


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Overlay}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{background\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mean\PYGZus{}func.nii.gz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{auto\PYGZus{}thresh\PYGZus{}bg} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{stat\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{zstat1.nii.gz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{stat\PYGZus{}thresh} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mf}{3.5}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{combine}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{show\PYGZus{}negative\PYGZus{}stats} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{combine}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
auto@_thresh@_bg : (a boolean)
        automatically threhsold the background image
        exclusive: auto@_thresh@_bg,full@_bg@_range,bg@_thresh
background@_image : (an existing file name)
        image to use as background
bg@_thresh : (a tuple of the form: (a float, a float))
        min and max values for background intensity
        exclusive: auto@_thresh@_bg,full@_bg@_range,bg@_thresh
full@_bg@_range : (a boolean)
        use full range of background image
        exclusive: auto@_thresh@_bg,full@_bg@_range,bg@_thresh
stat@_image : (an existing file name)
        statistical image to overlay in color
stat@_thresh : (a tuple of the form: (a float, a float))
        min and max values for the statistical overlay

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        combined image volume
out@_type : ('float' or 'int')
        write output with float or int
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
show@_negative@_stats : (a boolean)
        display negative statistics in overlay
        exclusive: stat@_image2
stat@_image2 : (an existing file name)
        second statistical image to overlay in color
        exclusive: show@_negative@_stats
stat@_thresh2 : (a tuple of the form: (a float, a float))
        min and max values for second statistical overlay
transparency : (a boolean)
        make overlay colors semi-transparent
use@_checkerboard : (a boolean)
        use checkerboard mask for overlay
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        combined image volume
\end{Verbatim}


\subsection{\texttt{PlotMotionParams}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:plotmotionparams}
Wraps command \textbf{fsl\_tsplot}

Use fsl\_tsplot to plot the estimated motion parameters from a realignment program.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{PlotMotionParams}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.par}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}source} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{fsl}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{plot\PYGZus{}type} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{rotations}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{plotter}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\subsubsection{Notes}
\label{interfaces/generated/nipype.interfaces.fsl.utils:notes}
The `in\_source' attribute determines the order of columns that are expected in the
source file.  FSL prints motion parameters in the order rotations, translations,
while SPM prints them in the opposite order.  This interface should be able to
plot timecourses of motion parameters generated from other sources as long as
they fall under one of these two patterns.  For more flexibilty, see the
\code{fsl.PlotTimeSeries} interface.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name or a list of items which are an existing file name)
        file with motion parameters
in@_source : ('spm' or 'fsl')
        which program generated the motion parameter file - fsl, spm
plot@_type : ('rotations' or 'translations' or 'displacement')
        which motion type to plot - rotations, translations, displacement

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        image to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
plot@_size : (a tuple of the form: (an integer, an integer))
        plot image height and width
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image to write
\end{Verbatim}


\subsection{\texttt{PlotTimeSeries}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:plottimeseries}
Wraps command \textbf{fsl\_tsplot}

Use fsl\_tsplot to create images of time course plots.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.fsl} \PYG{k+kn}{as} \PYG{n+nn}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{PlotTimeSeries}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.par}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{title} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{Functional timeseries}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{labels} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{run1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{run2}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{plotter}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name or a list of items which are an existing file name)
        file or list of files with columns of timecourse information

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
labels : (a string or a list of items which are a string)
        label or list of labels
legend@_file : (an existing file name)
        legend file
out@_file : (a file name)
        image to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
plot@_finish : (an integer)
        final column from in-file to plot
        exclusive: plot@_range
plot@_range : (a tuple of the form: (an integer, an integer))
        first and last columns from the in-file to plot
        exclusive: plot@_start,plot@_finish
plot@_size : (a tuple of the form: (an integer, an integer))
        plot image height and width
plot@_start : (an integer)
        first column from in-file to plot
        exclusive: plot@_range
sci@_notation : (a boolean)
        switch on scientific notation
title : (a string)
        plot title
x@_precision : (an integer)
        precision of x-axis labels
x@_units : (an integer)
        scaling units for x-axis (between 1 and length of in file)
y@_max : (a float)
        maximum y value
        exclusive: y@_range
y@_min : (a float)
        minumum y value
        exclusive: y@_range
y@_range : (a tuple of the form: (a float, a float))
        min and max y axis values
        exclusive: y@_min,y@_max
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image to write
\end{Verbatim}


\subsection{\texttt{PowerSpectrum}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:powerspectrum}
Wraps command \textbf{fslpspec}

Use FSL PowerSpectrum command for power spectrum estimation.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id8}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pspec} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{PowerSpectrum}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pspec}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{pspec}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input 4D file to estimate the power spectrum

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        name of output 4D file for power spectrum
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        path/name of the output 4D power spectrum file
\end{Verbatim}


\subsection{\texttt{Slicer}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:slicer}
Wraps command \textbf{slicer}

Use FSL's slicer command to output a png image from a volume.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.fsl.utils:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.testing} \PYG{k+kn}{import} \PYG{n}{example\PYGZus{}data}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{slice} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Slicer}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{slice}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{example\PYGZus{}data}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{slice}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{all\PYGZus{}axial} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{slice}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{image\PYGZus{}width} \PYG{o}{=} \PYG{l+m+mi}{750}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n+nb}{slice}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input volume

@PYGZlb[]Optional@PYGZrb[]
all@_axial : (a boolean)
        output all axial slices into one picture
        exclusive: single@_slice,middle@_slices,all@_axial,sample@_axial
        requires: image@_width
args : (a string)
        Additional parameters to the command
colour@_map : (an existing file name)
        use different colour map from that stored in nifti header
dither@_edges : (a boolean)
        produce semi-transparaent (dithered) edges
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
image@_edges : (an existing file name)
        volume to display edge overlay for (useful for checking registration
image@_width : (an integer)
        max picture width
intensity@_range : (a tuple of the form: (a float, a float))
        min and max intensities to display
label@_slices : (a boolean)
        display slice number
middle@_slices : (a boolean)
        output picture of mid-sagital, axial, and coronal slices
        exclusive: single@_slice,middle@_slices,all@_axial,sample@_axial
nearest@_neighbour : (a boolean)
        use nearest neighbour interpolation for output
out@_file : (a file name)
        picture to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
sample@_axial : (an integer)
        output every n axial slices into one picture
        exclusive: single@_slice,middle@_slices,all@_axial,sample@_axial
        requires: image@_width
scaling : (a float)
        image scale
show@_orientation : (a boolean)
        label left-right orientation
single@_slice : ('x' or 'y' or 'z')
        output picture of single slice in the x, y, or z plane
        exclusive: single@_slice,middle@_slices,all@_axial,sample@_axial
        requires: slice@_number
slice@_number : (an integer)
        slice number to save in picture
threshold@_edges : (a float)
        use threshold for edges
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        picture to write
\end{Verbatim}


\subsection{\texttt{Smooth}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:smooth}
Wraps command \textbf{fslmaths}

Use fslmaths to smooth the image

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
fwhm : (a float)
        Unknown
in@_file : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
smoothed@_file : (a file name)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
smoothed@_file : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{Split}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:split}
Wraps command \textbf{fslsplit}

Uses FSL Fslsplit command to separate a volume into images in
time, x, y or z dimension.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
dimension : ('t' or 'x' or 'y' or 'z')
        dimension along which the file will be split
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_file : (an existing file name)
        input filename
out@_base@_name : (a string)
        outputs prefix
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_files : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{SwapDimensions}}
\label{interfaces/generated/nipype.interfaces.fsl.utils:swapdimensions}
Wraps command \textbf{fslswapdim}

Use fslswapdim to alter the orientation of an image.

This interface accepts a three-tuple corresponding to the new
orientation.  You may either provide dimension ids in the form of
(-)x, (-)y, or (-z), or nifti-syle dimension codes (RL, LR, AP, PA, IS, SI).

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_file : (an existing file name)
        input image
new@_dims : (a tuple of the form: ('x' or '-x' or 'y' or '-y' or 'z' or '-z' or 'RL' or 'LR' or 'AP' or 'PA' or 'IS' or 'SI', 'x' or '-x' or 'y' or '-y' or 'z' or '-z' or 'RL' or 'LR' or 'AP' or 'PA' or 'IS' or 'SI', 'x' or '-x' or 'y' or '-y' or 'z' or '-z' or 'RL' or 'LR' or 'AP' or 'PA' or 'IS' or 'SI'))
        3-tuple of new dimension order

@PYGZlb[]Optional@PYGZrb[]
args : (a string)
        Additional parameters to the command
environ : (a dictionary with keys which are a value of type 'str' and with values which are a value of type 'str')
        Environment variables
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
out@_file : (a file name)
        image to write
output@_type : ('NIFTI@_PAIR' or 'NIFTI@_PAIR@_GZ' or 'NIFTI@_GZ' or 'NIFTI')
        FSL output type
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (an existing file name)
        image with new dimensions
\end{Verbatim}


\section{nipype.interfaces.io}
\label{interfaces/generated/nipype.interfaces.io:nipype-interfaces-io}\label{interfaces/generated/nipype.interfaces.io::doc}

\subsection{\texttt{DataGrabber}}
\label{interfaces/generated/nipype.interfaces.io:datagrabber}
Generic datagrabber module that wraps around glob in an
intelligent way for neuroimaging tasks to grab files

\begin{notice}{note}{Note:}
Doesn't support directories currently
\end{notice}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.io:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{import} \PYG{n}{DataGrabber}
\end{Verbatim}

Pick all files from current directory

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{DataGrabber}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{*}\PYG{l+s}{'}
\end{Verbatim}

Pick file foo/foo.nii from current directory

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.dcm}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outfiles}\PYG{l+s}{'}\PYG{p}{]}\PYG{o}{=}\PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{dicomdir}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{123456-1-1.dcm}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\end{Verbatim}

Same thing but with dynamically created fields

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{arg1}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{arg2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{arg1} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{arg2} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo}\PYG{l+s}{'}
\end{Verbatim}

however this latter form can be used with iterables and iterfield in a
pipeline.

Dynamically created, user-defined input and output fields

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{DataGrabber}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{ref}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{.}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{f3}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{f5}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{,}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{ref}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{ref}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sid} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{s1}\PYG{l+s}{'}
\end{Verbatim}

Change the template only for output field struct. The rest use the
general template

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{field\PYGZus{}template} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{struct}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{/struct.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
template : (a string)
        Layout used to get files. relative to base directory if defined

@PYGZlb[]Optional@PYGZrb[]
base@_directory : (an existing directory name)
        Path to the base directory consisting of subject data.
field@_template : (a dictionary with keys which are 'outfiles' and with values which are any value)
        arguments that fit into template
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
raise@_on@_empty : (a boolean)
        Generate exception if list is empty for a given field
sort@_filelist : (a boolean)
        Sort the filelist that matches the template
template@_args : (a dictionary with keys which are a string and with values which are a list of items which are a list of items which are any value)
        Information to plug into template
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
outfiles        Unknown
\end{Verbatim}


\subsection{\texttt{DataSink}}
\label{interfaces/generated/nipype.interfaces.io:datasink}
Generic datasink module to store structured outputs

Primarily for use within a workflow. This interface allows arbitrary
creation of input attributes. The names of these attributes define the
directory structure to create for storage of the files or directories.

The attributes take the following form:

string{[}{[}.{[}@{]}{]}string{[}{[}.{[}@{]}{]}string{]}{]} ...

where parts between {[}{]} are optional.

An attribute such as contrasts.@con will create a `contrasts' directory to
store the results linked to the attribute. If the @ is left out, such as in
`contrasts.con', a subdirectory `con' will be created under `contrasts'.


\subsubsection{Notes}
\label{interfaces/generated/nipype.interfaces.io:notes}\begin{quote}

Unlike most nipype-nodes this is not a thread-safe node because it can
write to a common shared location. It will not complain when it
overwrites a file.
\end{quote}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.io:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ds} \PYG{o}{=} \PYG{n}{DataSink}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ds}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{base\PYGZus{}directory} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{results\PYGZus{}dir}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ds}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{container} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{subject}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ds}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{structural} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{setattr}\PYG{p}{(}\PYG{n}{ds}\PYG{o}{.}\PYG{n}{inputs}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{contrasts.@con}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{setattr}\PYG{p}{(}\PYG{n}{ds}\PYG{o}{.}\PYG{n}{inputs}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{contrasts.alt}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1a.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2a.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ds}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
@_outputs : (a dictionary with keys which are a string and with values which are any value)
        Unknown
base@_directory : (a directory name)
        Path to the base directory for storing data.
container : (a string)
        Folder within base directory in which to store output
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
parameterization : (a boolean)
        store output in parametrized structure
regexp@_substitutions : (a tuple of the form: (a string, a string))
        List of 2-tuples reflecting a pair of a Python regexp pattern and a replacement string. Invoked after string []`substitutions[]`
remove@_dest@_dir : (a boolean)
        remove dest directory when copying dirs
strip@_dir : (a directory name)
        path to strip out of filename
substitutions : (a tuple of the form: (a string, a string))
        List of 2-tuples reflecting string to substitute and string to replace it with
\end{Verbatim}


\subsection{\texttt{FreeSurferSource}}
\label{interfaces/generated/nipype.interfaces.io:freesurfersource}
Generates freesurfer subject info from their directories


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.io:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{import} \PYG{n}{FreeSurferSource}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fs} \PYG{o}{=} \PYG{n}{FreeSurferSource}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{c}{\#fs.inputs.subjects\PYGZus{}dir = '.'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fs}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{PWS04}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fs}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{hemi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{lh}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fs}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
subject@_id : (a string)
        Subject name for whom to retrieve data
subjects@_dir : (a directory name)
        Freesurfer subjects directory.

@PYGZlb[]Optional@PYGZrb[]
hemi : ('both' or 'lh' or 'rh')
        Selects hemisphere specific outputs
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
T1 : (an existing file name)
        Intensity normalized whole-head volume
annot : (an existing file name)
        Surface annotation files
aparc@_aseg : (an existing file name)
        Aparc parcellation projected into aseg volume
aseg : (an existing file name)
        Volumetric map of regions from automatic segmentation
brain : (an existing file name)
        Intensity normalized brain-only volume
brainmask : (an existing file name)
        Skull-stripped (brain-only) volume
curv : (an existing file name)
        Maps of surface curvature
filled : (an existing file name)
        Subcortical mass volume
inflated : (an existing file name)
        Inflated surface meshes
label : (an existing file name)
        Volume and surface label files
norm : (an existing file name)
        Normalized skull-stripped volume
nu : (an existing file name)
        Non-uniformity corrected whole-head volume
orig : (an existing file name)
        Base image conformed to Freesurfer space
pial : (an existing file name)
        Gray matter/pia mater surface meshes
rawavg : (an existing file name)
        Volume formed by averaging input images
ribbon : (an existing file name)
        Volumetric maps of cortical ribbons
smoothwm : (an existing file name)
        Smoothed original surface meshes
sphere : (an existing file name)
        Spherical surface meshes
sphere@_reg : (an existing file name)
        Spherical registration file
sulc : (an existing file name)
        Surface maps of sulcal depth
thickness : (an existing file name)
        Surface maps of cortical thickness
volume : (an existing file name)
        Surface maps of cortical volume
white : (an existing file name)
        White/gray matter surface meshes
wm : (an existing file name)
        Segmented white-matter volume
wmparc : (an existing file name)
        Aparc parcellation projected into subcortical white matter
\end{Verbatim}


\subsection{\texttt{IOBase}}
\label{interfaces/generated/nipype.interfaces.io:iobase}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}


\subsection{\texttt{XNATSink}}
\label{interfaces/generated/nipype.interfaces.io:xnatsink}
Generic datasink module that takes a directory containing a
list of nifti files and provides a set of structured output
fields.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
config : (a file name)
        Unknown
        exclusive: server
experiment@_id : (a string)
        Set to workflow name
project@_id : (a string)
        Project in which to store the outputs
server : (a string)
        Unknown
        exclusive: config
        requires: user,pwd
subject@_id : (a string)
        Set to subject id

@PYGZlb[]Optional@PYGZrb[]
@_outputs : (a dictionary with keys which are a string and with values which are any value)
        Unknown
assessor@_id : (a string)
        Option to customize ouputs representation in XNAT - assessor level will be used with specified id
        exclusive: reconstruction@_id
cache@_dir : (a directory name)

ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
pwd : (a string)
        Unknown
reconstruction@_id : (a string)
        Option to customize ouputs representation in XNAT - reconstruction level will be used with specified id
        exclusive: assessor@_id
share : (a boolean)
        Option to share the subjects from the original projectinstead of creating new ones when possible - the created experiments are then shared backk to the original project
user : (a string)
        Unknown
\end{Verbatim}


\subsection{\texttt{XNATSource}}
\label{interfaces/generated/nipype.interfaces.io:xnatsource}
Generic XNATSource module that wraps around the pyxnat module in
an intelligent way for neuroimaging tasks to grab files and data
from an XNAT server.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.io:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.io} \PYG{k+kn}{import} \PYG{n}{XNATSource}
\end{Verbatim}

Pick all files from current directory

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{XNATSource}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{*}\PYG{l+s}{'}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{XNATSource}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{project}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{subject}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{experiment}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{assessor}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{inout}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{query\PYGZus{}template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{/projects/}\PYG{l+s+si}{\%s}\PYG{l+s}{/subjects/}\PYG{l+s+si}{\%s}\PYG{l+s}{/experiments/}\PYG{l+s+si}{\%s}\PYG{l+s}{'}                    \PYG{l+s}{'}\PYG{l+s}{/assessors/}\PYG{l+s+si}{\%s}\PYG{l+s}{/}\PYG{l+s+si}{\%s}\PYG{l+s}{\PYGZus{}resources/files}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{project} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{IMAGEN}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{IMAGEN\PYGZus{}000000001274}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{experiment} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{*SessionA*}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{assessor} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{*ADNI\PYGZus{}MPRAGE\PYGZus{}nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inout} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg} \PYG{o}{=} \PYG{n}{XNATSource}\PYG{p}{(}\PYG{n}{infields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{n}{outfields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{query\PYGZus{}template} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{/projects/IMAGEN/subjects/}\PYG{l+s+si}{\%s}\PYG{l+s}{/experiments/*SessionA*}\PYG{l+s}{'}                    \PYG{l+s}{'}\PYG{l+s}{/assessors/*}\PYG{l+s+si}{\%s}\PYG{l+s}{\PYGZus{}nii/out\PYGZus{}resources/files}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{query\PYGZus{}template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{struct}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{ADNI\PYGZus{}MPRAGE}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{query\PYGZus{}template\PYGZus{}args}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{func}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{sid}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{EPI\PYGZus{}faces}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{dg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{sid} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{IMAGEN\PYGZus{}000000001274}\PYG{l+s}{'}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
config : (a file name)
        Unknown
        exclusive: server
query@_template : (a string)
        Layout used to get files. Relative to base directory if defined
server : (a string)
        Unknown
        exclusive: config
        requires: user,pwd

@PYGZlb[]Optional@PYGZrb[]
cache@_dir : (a directory name)
        Cache directory
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
pwd : (a string)
        Unknown
query@_template@_args : (a dictionary with keys which are a string and with values which are a list of items which are a list of items which are any value)
        Information to plug into template
user : (a string)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
outfiles        Unknown
\end{Verbatim}


\section{nipype.interfaces.nipy.model}
\label{interfaces/generated/nipype.interfaces.nipy.model::doc}\label{interfaces/generated/nipype.interfaces.nipy.model:nipype-interfaces-nipy-model}

\subsection{\texttt{EstimateContrast}}
\label{interfaces/generated/nipype.interfaces.nipy.model:estimatecontrast}
Estimate contrast of a fitted model.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
axis    Unknown
beta : (an existing file name)
        beta coefficients of the fitted model
constants       Unknown
contrasts : (a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float) or a tuple of the form: (a string, 'F', a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float)))
        List of contrasts with each contrast being a list of the form:
    @PYGZlb[]('name', 'stat', @PYGZlb[]condition list@PYGZrb[], @PYGZlb[]weight list@PYGZrb[], @PYGZlb[]session list@PYGZrb[])@PYGZrb[]. if
    session list is None or not provided, all sessions are used. For F
    contrasts, the condition list should contain previously defined
    T-contrasts.
dof     degrees of freedom
nvbeta  Unknown
reg@_names : (a list of items which are any value)
        Unknown
s2 : (an existing file name)
        squared variance of the residuals

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (a file name)
        Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
p@_maps : (an existing file name)
        Unknown
stat@_maps : (an existing file name)
        Unknown
z@_maps : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{FitGLM}}
\label{interfaces/generated/nipype.interfaces.nipy.model:fitglm}
Fit GLM model based on the specified design. Supports only single or concatenated runs.

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
TR : (a float)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
drift@_model : ('Cosine' or 'Polynomial' or 'Blank')
        string that specifies the desired drift model, to be chosen among 'Polynomial', 'Cosine', 'Blank'
hrf@_model : ('Canonical' or 'Canonical With Derivative' or 'FIR')
        that specifies the hemodynamic reponse function it can be 'Canonical', 'Canonical With Derivative' or 'FIR'
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask : (a file name)
        restrict the fitting only to the region defined by this mask
method : ('kalman' or 'ols')
        method to fit the model, ols or kalma; kalman is more time consuming but it supports autoregressive model
model : ('ar1' or 'spherical')
        autoregressive mode is available only for the kalman method
normalize@_design@_matrix : (a boolean)
        normalize (zscore) the regressors before fitting
plot@_design@_matrix : (a boolean)
        Unknown
save@_residuals : (a boolean)
        Unknown
session@_info : (a list of from 1 to 1 items which are any value)
        Session specific information generated by []`[]`modelgen.SpecifyModel[]`[]`, FitGLM    does not  support multiple runs uless they are concatenated (see SpecifyModel options)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
a : (an existing file name)
        Unknown
axis    Unknown
beta : (an existing file name)
        Unknown
constants       Unknown
dof     Unknown
nvbeta  Unknown
reg@_names : (a list of items which are any value)
        Unknown
residuals : (a file name)
        Unknown
s2 : (an existing file name)
        Unknown
\end{Verbatim}


\section{nipype.interfaces.nipy.preprocess}
\label{interfaces/generated/nipype.interfaces.nipy.preprocess::doc}\label{interfaces/generated/nipype.interfaces.nipy.preprocess:nipype-interfaces-nipy-preprocess}

\subsection{\texttt{ComputeMask}}
\label{interfaces/generated/nipype.interfaces.nipy.preprocess:computemask}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
mean@_volume : (an existing file name)
        mean EPI image, used to compute the threshold for the mask

@PYGZlb[]Optional@PYGZrb[]
M : (a float)
        upper fraction of the histogram to be discarded
cc : (a boolean)
        if True, only the largest connect component is kept
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
m : (a float)
        lower fraction of the histogram to be discarded
reference@_volume : (an existing file name)
        reference volume used to compute the mask. If none is give, the         mean volume is used.
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
brain@_mask : (an existing file name)
        Unknown
\end{Verbatim}


\section{nipype.interfaces.nitime.analysis}
\label{interfaces/generated/nipype.interfaces.nitime.analysis::doc}\label{interfaces/generated/nipype.interfaces.nitime.analysis:nipype-interfaces-nitime-analysis}

\subsection{\texttt{CoherenceAnalyzer}}
\label{interfaces/generated/nipype.interfaces.nitime.analysis:coherenceanalyzer}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
NFFT : (an integer @textgreater[]= 32)
        Unknown
TR : (a float)
        Unknown
figure@_type : ('matrix' or 'network')
        Unknown
frequency@_range : (a list of from 2 to 2 items which are any value)
        Unknown
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
in@_TS   a nitime TimeSeries object
in@_file : (an existing file name)
        Unknown
        requires: TR
n@_overlap : (an integer @textgreater[]= 0)
        Unknown
output@_csv@_file : (a file name)
        File to write outputs (coherence,time-delay) with file-names: file@_name@_ {coherence,timedelay}
output@_figure@_file : (a file name)
        File to write output figures (coherence,time-delay) with file-names: file@_name@_{coherence,timedelay}. Possible formats: .png,.svg,.pdf,.jpg,...
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
coherence@_array : (an array)
        Unknown
coherence@_csv : (a file name)
        Unknown
coherence@_fig : (a file name)
        Figure representing coherence values
timedelay@_array : (an array)
        Unknown
timedelay@_csv : (a file name)
        Unknown
timedelay@_fig : (a file name)
        Figure representing coherence values
\end{Verbatim}


\subsection{\texttt{GetTimeSeries}}
\label{interfaces/generated/nipype.interfaces.nitime.analysis:gettimeseries}

\section{nipype.interfaces.slicer}
\label{interfaces/generated/nipype.interfaces.slicer::doc}\label{interfaces/generated/nipype.interfaces.slicer:nipype-interfaces-slicer}

\subsection{\texttt{SlicerCommandLine}}
\label{interfaces/generated/nipype.interfaces.slicer:slicercommandline}

\section{nipype.interfaces.spm.base}
\label{interfaces/generated/nipype.interfaces.spm.base::doc}\label{interfaces/generated/nipype.interfaces.spm.base:nipype-interfaces-spm-base}

\subsection{\texttt{Info}}
\label{interfaces/generated/nipype.interfaces.spm.base:info}
Handles SPM version information


\subsection{\texttt{SPMCommand}}
\label{interfaces/generated/nipype.interfaces.spm.base:spmcommand}
Extends \emph{BaseInterface} class to implement SPM specific interfaces.

WARNING: Pseudo prototype class, meant to be subclassed

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}


\section{nipype.interfaces.spm.model}
\label{interfaces/generated/nipype.interfaces.spm.model::doc}\label{interfaces/generated/nipype.interfaces.spm.model:nipype-interfaces-spm-model}

\subsection{\texttt{EstimateContrast}}
\label{interfaces/generated/nipype.interfaces.spm.model:estimatecontrast}
use spm\_contrasts to estimate contrasts of interest


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{EstimateContrast}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{spm\PYGZus{}mat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cont1} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task\textgreater{}Baseline}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,}\PYG{l+m+mf}{0.5}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{cont2} \PYG{o}{=} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{Task-Odd\textgreater{}Task-Even}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{Task-Odd}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{Task-Even}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{n}{cont1}\PYG{p}{,}\PYG{n}{cont2}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{n}{contrasts}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
beta@_images : (an existing file name)
        Parameter estimates of the design matrix
contrasts : (a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float) or a tuple of the form: (a string, 'F', a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float)))
        List of contrasts with each contrast being a list of the form:
    @PYGZlb[]('name', 'stat', @PYGZlb[]condition list@PYGZrb[], @PYGZlb[]weight list@PYGZrb[], @PYGZlb[]session list@PYGZrb[])@PYGZrb[]. if
    session list is None or not provided, all sessions are used. For F
    contrasts, the condition list should contain previously defined
    T-contrasts.
residual@_image : (an existing file name)
        Mean-squared image of the residuals
spm@_mat@_file : (an existing file name)
        Absolute path to SPM.mat

@PYGZlb[]Optional@PYGZrb[]
group@_contrast : (a boolean)
        higher level contrast
        exclusive: use@_derivs
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_derivs : (a boolean)
        use derivatives for estimation
        exclusive: group@_contrast
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
con@_images : (an existing file name)
        contrast images from a t-contrast
ess@_images : (an existing file name)
        contrast images from an F-contrast
spmF@_images : (an existing file name)
        stat images from an F-contrast
spmT@_images : (an existing file name)
        stat images from a t-contrast
spm@_mat@_file : (a file name)
        Updated SPM mat file
\end{Verbatim}


\subsection{\texttt{EstimateModel}}
\label{interfaces/generated/nipype.interfaces.spm.model:estimatemodel}
Use spm\_spm to estimate the parameters of a model

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=71}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=71}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est} \PYG{o}{=} \PYG{n}{EstimateModel}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{spm\PYGZus{}mat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{est}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
estimation@_method : (a dictionary with keys which are 'Classical' or 'Bayesian2' or 'Bayesian' and with values which are any value)
        Classical, Bayesian2, Bayesian (dict)
spm@_mat@_file : (an existing file name)
        absolute path to SPM.mat

@PYGZlb[]Optional@PYGZrb[]
flags : (a string)
        optional arguments (opt)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
RPVimage : (an existing file name)
        Resels per voxel image
beta@_images : (an existing file name)
        design parameter estimates
mask@_image : (an existing file name)
        binary mask to constrain estimation
residual@_image : (an existing file name)
        Mean-squared image of the residuals
spm@_mat@_file : (a file name)
        Updated SPM mat file
\end{Verbatim}


\subsection{\texttt{FactorialDesign}}
\label{interfaces/generated/nipype.interfaces.spm.model:factorialdesign}
Base class for factorial designs

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=79}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=79}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
covariates : (a dictionary with keys which are 'vector' or 'name' or 'interaction' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, interaction, centering}
explicit@_mask@_file : (a file name)
        use an implicit mask file to threshold
global@_calc@_mean : (a boolean)
        use mean for global calculation
        exclusive: global@_calc@_omit,global@_calc@_values
global@_calc@_omit : (a boolean)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_values
global@_calc@_values : (a list of items which are a float)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_omit
global@_normalization : (1 or 2 or 3)
        global normalization None-1, Proportional-2, ANCOVA-3
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
no@_grand@_mean@_scaling : (a boolean)
        do not perform grand mean scaling
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
threshold@_mask@_absolute : (a float)
        threshold using a proportion of the global value
        exclusive: threshold@_mask@_absolute,threshold@_mask@_none
threshold@_mask@_none : (a boolean)
        do not use threshold masking
        exclusive: threshold@_mask@_absolute,threshold@_mask@_relative
use@_implicit@_threshold : (a boolean)
        use implicit mask NaNs or zeros to threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\subsection{\texttt{Level1Design}}
\label{interfaces/generated/nipype.interfaces.spm.model:level1design}
Generate an SPM design matrix

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=61}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=61}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design} \PYG{o}{=} \PYG{n}{Level1Design}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{timing\PYGZus{}units} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{secs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{interscan\PYGZus{}interval} \PYG{o}{=} \PYG{l+m+mf}{2.5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{bases} \PYG{o}{=} \PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{hrf}\PYG{l+s}{'}\PYG{p}{:}\PYG{p}{\PYGZob{}}\PYG{l+s}{'}\PYG{l+s}{derivs}\PYG{l+s}{'}\PYG{p}{:} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{session\PYGZus{}info} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{session\PYGZus{}info.npz}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{level1design}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
bases : (a dictionary with keys which are 'hrf' or 'fourier' or 'fourier@_han' or 'gamma' or 'fir' and with values which are any value)

    dict {'name':{'basesparam1':val,...}}
    name : string
        Name of basis function (hrf, fourier, fourier@_han,
        gamma, fir)

        hrf :
            derivs : 2-element list
                Model  HRF  Derivatives. No derivatives: @PYGZlb[]0,0@PYGZrb[],
                Time derivatives : @PYGZlb[]1,0@PYGZrb[], Time and Dispersion
                derivatives: @PYGZlb[]1,1@PYGZrb[]
        fourier, fourier@_han, gamma, fir:
            length : int
                Post-stimulus window length (in seconds)
            order : int
                Number of basis functions

interscan@_interval : (a float)
        Interscan interval in secs
session@_info    Session specific information generated by []`[]`modelgen.SpecifyModel[]`[]`
timing@_units : ('secs' or 'scans')
        units for specification of onsets

@PYGZlb[]Optional@PYGZrb[]
factor@_info : (a list of items which are a dictionary with keys which are 'name' or 'levels' and with values which are any value)
        Factor specific information file (opt)
global@_intensity@_normalization : ('none' or 'scaling')
        Global intensity normalization - scaling or none (opt)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask@_image : (an existing file name)
        Image  for  explicitly  masking the analysis (opt)
mask@_threshold : ('-Inf' or a float)
        Thresholding for the mask (opt, '-Inf')
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
microtime@_onset : (a float)
        The onset/time-bin in seconds for alignment (opt)
microtime@_resolution : (an integer)
        Number of time-bins per scan in secs (opt)
model@_serial@_correlations : ('AR(1)' or 'none')
        Model serial correlations AR(1) or none (opt)
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
use@_mcr : (a boolean)
        Run m-code using SPM MCR
volterra@_expansion@_order : (1 or 2)
        Model interactions - yes:1, no:2 (opt)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\subsection{\texttt{MultipleRegression}}
\label{interfaces/generated/nipype.interfaces.spm.model:multipleregression}
Perform a two-sample ttest using two groups of images


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{import} \PYG{n}{MultipleRegression}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{=} \PYG{n}{MultipleRegression}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{covariates} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{names}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{reg1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{reg2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{centering}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{covariates}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{vectors}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+m+mi}{12}\PYG{p}{,}\PYG{l+m+mi}{24}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+m+mf}{0.6} \PYG{o}{-}\PYG{l+m+mf}{0.9}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{covariates} \PYG{o}{=} \PYG{n}{covariates}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{images} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrasts} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{reg2 \textgreater{} reg1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{T}\PYG{l+s}{'}\PYG{p}{,} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{reg1}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{reg2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{p}{[}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
contrasts : (a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float) or a tuple of the form: (a string, 'F', a list of items which are a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float) or a tuple of the form: (a string, 'T', a list of items which are a string, a list of items which are a float, a list of items which are a float)))
        List of contrasts with each contrast being a list of the form:
    @PYGZlb[]('name', 'stat', @PYGZlb[]condition list@PYGZrb[], @PYGZlb[]weight list@PYGZrb[], @PYGZlb[]session list@PYGZrb[])@PYGZrb[]. if
    session list is None or not provided, all sessions are used. For F
    contrasts, the condition list should contain previously defined
    T-contrasts.
covariates : (a dictionary with keys which are 'vectors' or 'names' or 'centering' and with values which are any value)
        dict of covariates {vectors, names, centering}
images : (a list of items which are an existing file name)
        con images from group 1

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
include@_intercept : (a boolean)
        Include intercept in model
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
con@_images : (an existing file name)
        contrast images from a t-contrast
ess@_images : (an existing file name)
        contrast images from an F-contrast
spmF@_images : (an existing file name)
        stat images from an F-contrast
spmT@_images : (an existing file name)
        stat images from a t-contrast
\end{Verbatim}


\subsection{\texttt{MultipleRegressionDesign}}
\label{interfaces/generated/nipype.interfaces.spm.model:multipleregressiondesign}
Create SPM design for multiple regression


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg} \PYG{o}{=} \PYG{n}{MultipleRegressionDesign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mreg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of at least 2 items which are an existing file name)
        List of files

@PYGZlb[]Optional@PYGZrb[]
covariates : (a dictionary with keys which are 'vector' or 'name' or 'interaction' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, interaction, centering}
explicit@_mask@_file : (a file name)
        use an implicit mask file to threshold
global@_calc@_mean : (a boolean)
        use mean for global calculation
        exclusive: global@_calc@_omit,global@_calc@_values
global@_calc@_omit : (a boolean)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_values
global@_calc@_values : (a list of items which are a float)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_omit
global@_normalization : (1 or 2 or 3)
        global normalization None-1, Proportional-2, ANCOVA-3
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
include@_intercept : (a boolean)
        Include intercept in design
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
no@_grand@_mean@_scaling : (a boolean)
        do not perform grand mean scaling
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
threshold@_mask@_absolute : (a float)
        threshold using a proportion of the global value
        exclusive: threshold@_mask@_absolute,threshold@_mask@_none
threshold@_mask@_none : (a boolean)
        do not use threshold masking
        exclusive: threshold@_mask@_absolute,threshold@_mask@_relative
use@_implicit@_threshold : (a boolean)
        use implicit mask NaNs or zeros to threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
user@_covariates : (a dictionary with keys which are 'vector' or 'name' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, centering}
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\subsection{\texttt{OneSampleTTest}}
\label{interfaces/generated/nipype.interfaces.spm.model:onesamplettest}
use spm to perform a one-sample ttest on a set of images


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{OneSampleTTest}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{con\PYGZus{}images} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
con@_images : (a file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
con@_images : (a file name)
        Unknown
spmT@_images : (a file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{OneSampleTTestDesign}}
\label{interfaces/generated/nipype.interfaces.spm.model:onesamplettestdesign}
Create SPM design for one sample t-test


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest} \PYG{o}{=} \PYG{n}{OneSampleTTestDesign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of at least 2 items which are an existing file name)
        input files

@PYGZlb[]Optional@PYGZrb[]
covariates : (a dictionary with keys which are 'vector' or 'name' or 'interaction' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, interaction, centering}
explicit@_mask@_file : (a file name)
        use an implicit mask file to threshold
global@_calc@_mean : (a boolean)
        use mean for global calculation
        exclusive: global@_calc@_omit,global@_calc@_values
global@_calc@_omit : (a boolean)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_values
global@_calc@_values : (a list of items which are a float)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_omit
global@_normalization : (1 or 2 or 3)
        global normalization None-1, Proportional-2, ANCOVA-3
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
no@_grand@_mean@_scaling : (a boolean)
        do not perform grand mean scaling
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
threshold@_mask@_absolute : (a float)
        threshold using a proportion of the global value
        exclusive: threshold@_mask@_absolute,threshold@_mask@_none
threshold@_mask@_none : (a boolean)
        do not use threshold masking
        exclusive: threshold@_mask@_absolute,threshold@_mask@_relative
use@_implicit@_threshold : (a boolean)
        use implicit mask NaNs or zeros to threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\subsection{\texttt{PairedTTestDesign}}
\label{interfaces/generated/nipype.interfaces.spm.model:pairedttestdesign}
Create SPM design for paired t-test


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id7}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pttest} \PYG{o}{=} \PYG{n}{PairedTTestDesign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{paired\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cont1a.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{cont2a.nii}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{pttest}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
paired@_files : (a list of at least 2 items which are a list of from 2 to 2 items which are an existing file name)
        List of paired files

@PYGZlb[]Optional@PYGZrb[]
ancova : (a boolean)
        Specify ancova-by-factor regressors
covariates : (a dictionary with keys which are 'vector' or 'name' or 'interaction' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, interaction, centering}
explicit@_mask@_file : (a file name)
        use an implicit mask file to threshold
global@_calc@_mean : (a boolean)
        use mean for global calculation
        exclusive: global@_calc@_omit,global@_calc@_values
global@_calc@_omit : (a boolean)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_values
global@_calc@_values : (a list of items which are a float)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_omit
global@_normalization : (1 or 2 or 3)
        global normalization None-1, Proportional-2, ANCOVA-3
grand@_mean@_scaling : (a boolean)
        Perform grand mean scaling
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
no@_grand@_mean@_scaling : (a boolean)
        do not perform grand mean scaling
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
threshold@_mask@_absolute : (a float)
        threshold using a proportion of the global value
        exclusive: threshold@_mask@_absolute,threshold@_mask@_none
threshold@_mask@_none : (a boolean)
        do not use threshold masking
        exclusive: threshold@_mask@_absolute,threshold@_mask@_relative
use@_implicit@_threshold : (a boolean)
        use implicit mask NaNs or zeros to threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\subsection{\texttt{Threshold}}
\label{interfaces/generated/nipype.interfaces.spm.model:threshold}
Topological FDR thresholding based on cluster extent/size. Smoothness is
estimated from GLM residuals but is assumed to be the same for all of the
voxels.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id8}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh} \PYG{o}{=} \PYG{n}{Threshold}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{spm\PYGZus{}mat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{stat\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}0001.img}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrast\PYGZus{}index} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{extent\PYGZus{}fdr\PYGZus{}p\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mf}{0.05}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
contrast@_index : (an integer)
        which contrast in the SPM.mat to use
spm@_mat@_file : (an existing file name)
        absolute path to SPM.mat
stat@_image : (an existing file name)
        stat image

@PYGZlb[]Optional@PYGZrb[]
extent@_fdr@_p@_threshold : (a float)
        p threshold on FDR corrected cluster size probabilities
extent@_threshold : (an integer)
        Minimum cluster size in voxels
height@_threshold : (a float)
        p-value for initial thresholding (defining clusters)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_fwe@_correction : (a boolean)
        whether to use FWE (Bonferroni) correction for initial threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
use@_topo@_fdr : (a boolean)
        whether to use FDR over cluster extent probabilities
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
pre@_topo@_fdr@_map : (an existing file name)
        Unknown
thresholded@_map : (an existing file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{ThresholdStatistics}}
\label{interfaces/generated/nipype.interfaces.spm.model:thresholdstatistics}
Given height and cluster size threshold calculate theoretical probabilities
concerning false positives


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id9}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh} \PYG{o}{=} \PYG{n}{ThresholdStatistics}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{spm\PYGZus{}mat\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{SPM.mat}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{stat\PYGZus{}image} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{spmT\PYGZus{}0001.img}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{contrast\PYGZus{}index} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{height\PYGZus{}threshold} \PYG{o}{=} \PYG{l+m+mf}{4.56}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{thresh}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
contrast@_index : (an integer)
        which contrast in the SPM.mat to use
height@_threshold : (a float)
        stat value for initial thresholding (defining clusters)
spm@_mat@_file : (an existing file name)
        absolute path to SPM.mat
stat@_image : (an existing file name)
        stat image

@PYGZlb[]Optional@PYGZrb[]
extent@_threshold : (an integer)
        Minimum cluster size in voxels
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
clusterwise@_P@_FDR : (a float)
        Unknown
clusterwise@_P@_RF : (a float)
        Unknown
voxelwise@_P@_Bonf : (a float)
        Unknown
voxelwise@_P@_FDR : (a float)
        Unknown
voxelwise@_P@_RF : (a float)
        Unknown
voxelwise@_P@_uncor : (a float)
        Unknown
\end{Verbatim}


\subsection{\texttt{TwoSampleTTest}}
\label{interfaces/generated/nipype.interfaces.spm.model:twosamplettest}
Perform a two-sample ttest using two groups of images

4 contrasts are automatically created corresponding to:
\begin{itemize}
\item {} 
group 1

\item {} 
group 2

\item {} 
group 1 - group 2

\item {} 
group 2 - group 1

\end{itemize}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id10}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{TwoSampleTTest}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{images\PYGZus{}group1} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{images\PYGZus{}group2} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1a.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2a.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{dependent} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{unequal\PYGZus{}variance} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
images@_group1 : (a list of items which are an existing file name)
        con images from group 1
images@_group2 : (a list of items which are an existing file name)
        con images from group 2

@PYGZlb[]Optional@PYGZrb[]
dependent : (a boolean)
        Are the measurements independent between levels
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
unequal@_variance : (a boolean)
        Are the variances equal or unequal between groups
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
con@_images : (a list of items which are a file name)
        contrast images from a t-contrast
spmT@_images : (a list of items which are a file name)
        stat images from a t-contrast
\end{Verbatim}


\subsection{\texttt{TwoSampleTTestDesign}}
\label{interfaces/generated/nipype.interfaces.spm.model:twosamplettestdesign}
Create SPM design for two sample t-test


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.model:id11}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest} \PYG{o}{=} \PYG{n}{TwoSampleTTestDesign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{group1\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{group2\PYGZus{}files} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{cont1a.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{cont2a.nii}\PYG{l+s}{'}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ttest}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
group1@_files : (a list of at least 2 items which are an existing file name)
        Group 1 input files
group2@_files : (a list of at least 2 items which are an existing file name)
        Group 2 input files

@PYGZlb[]Optional@PYGZrb[]
covariates : (a dictionary with keys which are 'vector' or 'name' or 'interaction' or 'centering' and with values which are any value)
        covariate dictionary {vector, name, interaction, centering}
dependent : (a boolean)
        Are the measurements dependent between levels
explicit@_mask@_file : (a file name)
        use an implicit mask file to threshold
global@_calc@_mean : (a boolean)
        use mean for global calculation
        exclusive: global@_calc@_omit,global@_calc@_values
global@_calc@_omit : (a boolean)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_values
global@_calc@_values : (a list of items which are a float)
        omit global calculation
        exclusive: global@_calc@_mean,global@_calc@_omit
global@_normalization : (1 or 2 or 3)
        global normalization None-1, Proportional-2, ANCOVA-3
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
no@_grand@_mean@_scaling : (a boolean)
        do not perform grand mean scaling
paths : (a directory name)
        Paths to add to matlabpath
spm@_mat@_dir : (an existing directory name)
        directory to store SPM.mat file (opt)
threshold@_mask@_absolute : (a float)
        threshold using a proportion of the global value
        exclusive: threshold@_mask@_absolute,threshold@_mask@_none
threshold@_mask@_none : (a boolean)
        do not use threshold masking
        exclusive: threshold@_mask@_absolute,threshold@_mask@_relative
unequal@_variance : (a boolean)
        Are the variances equal or unequal between groups
use@_implicit@_threshold : (a boolean)
        use implicit mask NaNs or zeros to threshold
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
spm@_mat@_file : (an existing file name)
        SPM mat file
\end{Verbatim}


\section{nipype.interfaces.spm.preprocess}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:nipype-interfaces-spm-preprocess}\label{interfaces/generated/nipype.interfaces.spm.preprocess::doc}

\subsection{\texttt{Coregister}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:coregister}
Use spm\_coreg for estimating cross-modality rigid body alignment

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=39}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=39}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{coreg} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Coregister}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{coreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{target} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{coreg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{coreg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
source : (an existing file name)
        file to register to target
target : (an existing file name)
        reference file to register to

@PYGZlb[]Optional@PYGZrb[]
apply@_to@_files : (an existing file name)
        files to apply transformation to
cost@_function : ('mi' or 'nmi' or 'ecc' or 'ncc')
        cost function, one of: 'mi' - Mutual Information,
        'nmi' - Normalised Mutual Information,
        'ecc' - Entropy Correlation Coefficient,
        'ncc' - Normalised Cross Correlation
fwhm : (a float)
        gaussian smoothing kernel width (mm)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
jobtype : ('estwrite' or 'estimate' or 'write')
        one of: estimate, write, estwrite
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
separation : (a list of items which are a float)
        sampling separation in mm
tolerance : (a list of items which are a float)
        acceptable tolerance for each of 12 params
use@_mcr : (a boolean)
        Run m-code using SPM MCR
write@_interp : (an integer @textgreater[]= 0)
        degree of b-spline used for interpolation
write@_mask : (a boolean)
        True/False mask output image
write@_wrap : (a list of from 3 to 3 items which are a boolean)
        Check if interpolation should wrap in @PYGZlb[]x,y,z@PYGZrb[]
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
coregistered@_files : (an existing file name)
        Coregistered other files
coregistered@_source : (an existing file name)
        Coregistered source files
\end{Verbatim}


\subsection{\texttt{NewSegment}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:newsegment}
Use spm\_preproc8 (New Segment) to separate structural images into different
tissue classes. Supports multiple modalities.

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=185}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=185}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{NewSegment}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{channel\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
    @PYGZlb[]Mandatory@PYGZrb[]
    channel@_files : (an existing file name)
            A list of files to be segmented

    @PYGZlb[]Optional@PYGZrb[]
    affine@_regularization : ('mni' or 'eastern' or 'subj' or 'none')
            mni, eastern, subj, none
    channel@_info : (a list of items which are a tuple of the form: (a float, a float, a tuple of the form: (a boolean, a boolean)))
            A list of tuples (one per channel/modality)
with the following fields:
        - bias reguralisation (0-10)
        - FWHM of Gaussian smoothness of bias
        - which maps to save (Corrected, Field) - a tuple of two boolean values
    ignore@_exception : (a boolean)
            Print an error message instead of throwing an exception in case the interface fails to run
    matlab@_cmd : (a string)
            matlab command to use
    mfile : (a boolean)
            Run m-code using m-file
    paths : (a directory name)
            Paths to add to matlabpath
    sampling@_distance : (a float)
            Sampling distance on data for parameter estimation
    tissues : (a list of items which are a tuple of the form: (a list of items which are an existing file name, an integer, a tuple of the form: (a boolean, a boolean), a tuple of the form: (a boolean, a boolean)))
            A list of tuples (one per tissue) with the following fields:
        - tissue probability map
        - number of gaussians
        - which maps to save @PYGZlb[]Native, DARTEL@PYGZrb[] - a tuple of two boolean values
        - which maps to save @PYGZlb[]Modulated, Unmodualted@PYGZrb[] - a tuple of two boolean values
    use@_mcr : (a boolean)
            Run m-code using SPM MCR
    warping@_regularization : (a float)
            Aproximate distance between sampling points.
    write@_deformation@_fields : (a list of from 2 to 2 items which are a boolean)
            Which deformation fields to write:@PYGZlb[]Inverse, Forward@PYGZrb[]
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
native@_class@_images : (an existing file name)
        native space probability maps
transformation@_mat : (an existing file name)
        Normalization transformation
\end{Verbatim}


\subsection{\texttt{Normalize}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:normalize}
use spm\_normalise for warping an image to a template

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=51}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=51}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{norm} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Normalize}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{norm}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{source} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{norm}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
parameter@_file : (a file name)
        normalization parameter file*@_sn.mat
        exclusive: source,template
source : (an existing file name)
        file to normalize to template
        exclusive: parameter@_file
template : (an existing file name)
        template file to normalize to
        exclusive: parameter@_file

@PYGZlb[]Optional@PYGZrb[]
DCT@_period@_cutoff : (a float)
        Cutoff of for DCT bases (opt)
affine@_regularization@_type : ('mni' or 'size' or 'none')
        mni, size, none (opt)
apply@_to@_files : (an existing file name)
        files to apply transformation to (opt)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
jobtype : ('estwrite' or 'estimate' or 'write')
        one of: estimate, write, estwrite (opt, estwrite)
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
nonlinear@_iterations : (an integer)
        Number of iterations of nonlinear warping (opt)
nonlinear@_regularization : (a float)
        the amount of the regularization for the nonlinear part of the normalization (opt)
paths : (a directory name)
        Paths to add to matlabpath
source@_image@_smoothing : (a float)
        source smoothing (opt)
source@_weight : (a file name)
        name of weighting image for source (opt)
template@_image@_smoothing : (a float)
        template smoothing (opt)
template@_weight : (a file name)
        name of weighting image for template (opt)
use@_mcr : (a boolean)
        Run m-code using SPM MCR
write@_bounding@_box : (a list of from 6 to 6 items which are a float)
        6-element list (opt)
write@_interp : (an integer @textgreater[]= 0)
        degree of b-spline used for interpolation
write@_preserve : (a boolean)
        True/False warped images are modulated (opt,)
write@_voxel@_sizes : (a list of from 3 to 3 items which are a float)
        3-element list (opt)
write@_wrap : (a list of items which are a boolean)
        Check if interpolation should wrap in @PYGZlb[]x,y,z@PYGZrb[] - list of bools (opt)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
normalization@_parameters : (an existing file name)
        MAT files containing the normalization parameters
normalized@_files : (an existing file name)
        Normalized other files
normalized@_source : (an existing file name)
        Normalized source files
\end{Verbatim}


\subsection{\texttt{Realign}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:realign}
Use spm\_realign for estimating within modality rigid body alignment

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=25}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=25}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{realign} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{realign}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{register\PYGZus{}to\PYGZus{}mean} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{realign}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of items which are an existing file name or an existing file name)
        list of filenames to realign

@PYGZlb[]Optional@PYGZrb[]
fwhm : (a floating point number @textgreater[]= 0.0)
        gaussian smoothing kernel width
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
interp : (0 @textless[]= an integer @textless[]= 7)
        degree of b-spline used for interpolation
jobtype : ('estwrite' or 'estimate' or 'write')
        one of: estimate, write, estwrite
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
quality : (0.0 @textless[]= a floating point number @textless[]= 1.0)
        0.1 = fast, 1.0 = precise
register@_to@_mean : (a boolean)
        Indicate whether realignment is done to the mean image
separation : (a floating point number @textgreater[]= 0.0)
        sampling separation in mm
use@_mcr : (a boolean)
        Run m-code using SPM MCR
weight@_img : (an existing file name)
        filename of weighting image
wrap : (a tuple of the form: (an integer, an integer, an integer))
        Check if interpolation should wrap in @PYGZlb[]x,y,z@PYGZrb[]
write@_interp : (0 @textless[]= an integer @textless[]= 7)
        degree of b-spline used for interpolation
write@_mask : (a boolean)
        True/False mask output image
write@_which : (a tuple of the form: (an integer, an integer))
        determines which images to reslice
write@_wrap : (a tuple of the form: (an integer, an integer, an integer))
        Check if interpolation should wrap in @PYGZlb[]x,y,z@PYGZrb[]
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
mean@_image : (an existing file name)
        Mean image file from the realignment
realigned@_files : (a list of items which are an existing file name or an existing file name)
        Realigned files
realignment@_parameters : (an existing file name)
        Estimated translation and rotation parameters
\end{Verbatim}


\subsection{\texttt{Segment}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:segment}
use spm\_segment to separate structural images into different
tissue classes.

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=43}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=43}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Segment}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{data} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{structural.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{seg}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
data : (an existing file name)
        one scan per subject

@PYGZlb[]Optional@PYGZrb[]
affine@_regularization : ('mni' or 'eastern' or 'subj' or 'none' or '')
        Possible options: "mni", "eastern", "subj", "none" (no reguralisation), "" (no affine registration)
bias@_fwhm : (30 or 40 or 50 or 60 or 70 or 80 or 90 or 100 or 110 or 120 or 130 or 'Inf')
        FWHM of Gaussian smoothness of bias
bias@_regularization : (0 or 1e-05 or 0.0001 or 0.001 or 0.01 or 0.1 or 1 or 10)
        no(0) - extremely heavy (10)
clean@_masks : ('no' or 'light' or 'thorough')
        clean using estimated brain mask ('no','light','thorough')
csf@_output@_type : (a list of from 3 to 3 items which are a boolean)
        Options to produce CSF images: c3*.img, wc3*.img and mwc3*.img.
    None: @PYGZlb[]False,False,False@PYGZrb[],
    Native Space: @PYGZlb[]False,False,True@PYGZrb[],
    Unmodulated Normalised: @PYGZlb[]False,True,False@PYGZrb[],
    Modulated Normalised: @PYGZlb[]True,False,False@PYGZrb[],
    Native + Unmodulated Normalised: @PYGZlb[]False,True,True@PYGZrb[],
    Native + Modulated Normalised: @PYGZlb[]True,False,True@PYGZrb[],
    Native + Modulated + Unmodulated: @PYGZlb[]True,True,True@PYGZrb[],
    Modulated + Unmodulated Normalised: @PYGZlb[]True,True,False@PYGZrb[]
gaussians@_per@_class : (a list of items which are an integer)
        num Gaussians capture intensity distribution
gm@_output@_type : (a list of from 3 to 3 items which are a boolean)
        Options to produce grey matter images: c1*.img, wc1*.img and mwc1*.img.
    None: @PYGZlb[]False,False,False@PYGZrb[],
    Native Space: @PYGZlb[]False,False,True@PYGZrb[],
    Unmodulated Normalised: @PYGZlb[]False,True,False@PYGZrb[],
    Modulated Normalised: @PYGZlb[]True,False,False@PYGZrb[],
    Native + Unmodulated Normalised: @PYGZlb[]False,True,True@PYGZrb[],
    Native + Modulated Normalised: @PYGZlb[]True,False,True@PYGZrb[],
    Native + Modulated + Unmodulated: @PYGZlb[]True,True,True@PYGZrb[],
    Modulated + Unmodulated Normalised: @PYGZlb[]True,True,False@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
mask@_image : (an existing file name)
        Binary image to restrict parameter estimation
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
sampling@_distance : (a float)
        Sampling distance on data for parameter estimation
save@_bias@_corrected : (a boolean)
        True/False produce a bias corrected image
tissue@_prob@_maps : (a list of items which are an existing file name)
        list of gray, white @& csf prob. (opt,)
use@_mcr : (a boolean)
        Run m-code using SPM MCR
warp@_frequency@_cutoff : (a float)
        Cutoff of DCT bases
warping@_regularization : (a float)
        Controls balance between parameters and data
wm@_output@_type : (a list of from 3 to 3 items which are a boolean)
        Options to produce white matter images: c2*.img, wc2*.img and mwc2*.img.
    None: @PYGZlb[]False,False,False@PYGZrb[],
    Native Space: @PYGZlb[]False,False,True@PYGZrb[],
    Unmodulated Normalised: @PYGZlb[]False,True,False@PYGZrb[],
    Modulated Normalised: @PYGZlb[]True,False,False@PYGZrb[],
    Native + Unmodulated Normalised: @PYGZlb[]False,True,True@PYGZrb[],
    Native + Modulated Normalised: @PYGZlb[]True,False,True@PYGZrb[],
    Native + Modulated + Unmodulated: @PYGZlb[]True,True,True@PYGZrb[],
    Modulated + Unmodulated Normalised: @PYGZlb[]True,True,False@PYGZrb[]
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
inverse@_transformation@_mat : (an existing file name)
        Inverse normalization info
modulated@_csf@_image : (an existing file name)
        modulated, normalized csf probability map
modulated@_gm@_image : (an existing file name)
        modulated, normalized grey probability map
modulated@_input@_image : (an existing file name)
        modulated version of input image
modulated@_wm@_image : (an existing file name)
        modulated, normalized white probability map
native@_csf@_image : (an existing file name)
        native space csf probability map
native@_gm@_image : (an existing file name)
        native space grey probability map
native@_wm@_image : (an existing file name)
        native space white probability map
normalized@_csf@_image : (an existing file name)
        normalized csf probability map
normalized@_gm@_image : (an existing file name)
        normalized grey probability map
normalized@_wm@_image : (an existing file name)
        normalized white probability map
transformation@_mat : (an existing file name)
        Normalization transformation
\end{Verbatim}


\subsection{\texttt{SliceTiming}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:slicetiming}
Use spm to perform slice timing correction.

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=19}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=19}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{import} \PYG{n}{SliceTiming}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st} \PYG{o}{=} \PYG{n}{SliceTiming}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{num\PYGZus{}slices} \PYG{o}{=} \PYG{l+m+mi}{32}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}repetition} \PYG{o}{=} \PYG{l+m+mf}{6.0}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{time\PYGZus{}acquisition} \PYG{o}{=} \PYG{l+m+mf}{6.} \PYG{o}{-} \PYG{l+m+mf}{6.}\PYG{o}{/}\PYG{l+m+mf}{32.}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{slice\PYGZus{}order} \PYG{o}{=} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{32}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{o}{-}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{ref\PYGZus{}slice} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{st}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (a list of items which are an existing file name or an existing file name)
        list of filenames to apply slice timing
num@_slices : (an integer)
        number of slices in a volume
ref@_slice : (an integer)
        1-based Number of the reference slice
slice@_order : (a list of items which are an integer)
        1-based order in which slices are acquired
time@_acquisition : (a float)
        time of volume acquisition. usually calculated as TR-(TR/num@_slices)
time@_repetition : (a float)
        time between volume acquisitions (start to start time)

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
timecorrected@_files : (a file name)
        Unknown
\end{Verbatim}


\subsection{\texttt{Smooth}}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:smooth}
Use spm\_smooth for 3D Gaussian smoothing of image volumes.

\href{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=57}{http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf\#page=57}


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.spm.preprocess:id6}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.interfaces.spm} \PYG{k+kn}{as} \PYG{n+nn}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Smooth}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{functional.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
in@_files : (an existing file name)
        list of files to smooth

@PYGZlb[]Optional@PYGZrb[]
data@_type : (an integer)
        Data type of the output images (opt)
fwhm : (a list of from 3 to 3 items which are a float or a float)
        3-list of fwhm for each dimension (opt)
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
smoothed@_files : (an existing file name)
        smoothed files
\end{Verbatim}


\section{nipype.interfaces.spm.utils}
\label{interfaces/generated/nipype.interfaces.spm.utils::doc}\label{interfaces/generated/nipype.interfaces.spm.utils:nipype-interfaces-spm-utils}

\subsection{\texttt{Analyze2nii}}
\label{interfaces/generated/nipype.interfaces.spm.utils:analyze2nii}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
analyze@_file : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
matlab@_cmd : (a string)
        matlab command to use
mfile : (a boolean)
        Run m-code using m-file
nifti@_file : (an existing file name)
        Unknown
paths : (a directory name)
        Paths to add to matlabpath
use@_mcr : (a boolean)
        Run m-code using SPM MCR
\end{Verbatim}


\section{nipype.interfaces.utility}
\label{interfaces/generated/nipype.interfaces.utility::doc}\label{interfaces/generated/nipype.interfaces.utility:nipype-interfaces-utility}

\subsection{\texttt{AssertEqual}}
\label{interfaces/generated/nipype.interfaces.utility:assertequal}
Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
volume1 : (an existing file name)
        Unknown
volume2 : (an existing file name)
        Unknown

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}


\subsection{\texttt{Function}}
\label{interfaces/generated/nipype.interfaces.utility:function}
Runs arbitrary function as an interface


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{func} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{def func(arg1, arg2=5): return arg1 + arg2}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fi} \PYG{o}{=} \PYG{n}{Function}\PYG{p}{(}\PYG{n}{input\PYGZus{}names}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{arg1}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{arg2}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{output\PYGZus{}names}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{out}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{function\PYGZus{}str} \PYG{o}{=} \PYG{n}{func}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{fi}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{arg1}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out}
\PYG{g+go}{\textasciitilde{}}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
function@_str : (a string)
        code for function

@PYGZlb[]Optional@PYGZrb[]
arg1    Unknown
arg2    Unknown
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out     Unknown
\end{Verbatim}


\subsection{\texttt{IdentityInterface}}
\label{interfaces/generated/nipype.interfaces.utility:identityinterface}
Basic interface class generates identity mappings


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{import} \PYG{n}{IdentityInterface}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ii} \PYG{o}{=} \PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{a}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{b}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{mandatory\PYGZus{}inputs}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ii}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{a}
\PYG{g+go}{\textless{}undefined\textgreater{}}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ii}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{a} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{ii}\PYG{o}{.}\PYG{n}{\PYGZus{}outputs}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{a}
\PYG{g+go}{\textless{}undefined\textgreater{}}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{ii}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{a}
\PYG{g+go}{'foo'}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ii2} \PYG{o}{=} \PYG{n}{IdentityInterface}\PYG{p}{(}\PYG{n}{fields}\PYG{o}{=}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{a}\PYG{l+s}{'}\PYG{p}{,}\PYG{l+s}{'}\PYG{l+s}{b}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{,} \PYG{n}{mandatory\PYGZus{}inputs}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{ii2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{a} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{ii2}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)} 
\PYG{g+go}{ValueError: IdentityInterface requires a value for input 'b' because it was listed in 'fields' Interface IdentityInterface failed to run.}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
a       Unknown
b       Unknown
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
a       Unknown
b       Unknown
\end{Verbatim}


\subsection{\texttt{Merge}}
\label{interfaces/generated/nipype.interfaces.utility:merge}
Basic interface class to merge inputs into a single list


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:id2}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{import} \PYG{n}{Merge}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mi} \PYG{o}{=} \PYG{n}{Merge}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in1} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in2} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{mi}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in3} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{mi}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out}
\PYG{g+go}{[1, 2, 5, 3]}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Optional@PYGZrb[]
axis : ('vstack' or 'hstack')
        direction in which to merge, hstack requires same number of elements in each input
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out : (a list of items which are any value)
        Merged output
\end{Verbatim}


\subsection{\texttt{Rename}}
\label{interfaces/generated/nipype.interfaces.utility:rename}
Change the name of a file based on a mapped format string.

To use additional inputs that will be defined at run-time, the class
constructor must be called with the format template, and the fields
identified will become inputs to the interface.

Additionally, you may set the parse\_string input, which will be run
over the input filename with a regular expressions search, and will
fill in additional input fields from matched groups. Fields set with
inputs have precedence over fields filled in with the regexp match.


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:id3}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{import} \PYG{n}{Rename}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename1} \PYG{o}{=} \PYG{n}{Rename}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename1}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{zstat1.nii.gz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename1}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{format\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{Faces-Scenes.nii.gz}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{rename1}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}          
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{print} \PYG{n}{res}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file}   
\PYG{g+go}{'Faces-Scenes.nii.gz"            }
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename2} \PYG{o}{=} \PYG{n}{Rename}\PYG{p}{(}\PYG{n}{format\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%(subject\PYGZus{}id)s}\PYG{l+s}{\PYGZus{}func\PYGZus{}run}\PYG{l+s+si}{\%(run)02d}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{functional.nii}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{keep\PYGZus{}ext} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{subj\PYGZus{}201}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename2}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{run} \PYG{o}{=} \PYG{l+m+mi}{2}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{rename2}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}          
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{print} \PYG{n}{res}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file}   
\PYG{g+go}{'subj\PYGZus{}201\PYGZus{}func\PYGZus{}run02.nii'        }
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename3} \PYG{o}{=} \PYG{n}{Rename}\PYG{p}{(}\PYG{n}{format\PYGZus{}string}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%(subject\PYGZus{}id)s}\PYG{l+s}{\PYGZus{}}\PYG{l+s+si}{\%(seq)s}\PYG{l+s}{\PYGZus{}run}\PYG{l+s+si}{\%(run)02d}\PYG{l+s}{.nii}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{func\PYGZus{}epi\PYGZus{}1\PYGZus{}1.nii}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{parse\PYGZus{}string} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{func\PYGZus{}(?P\textless{}seq\textgreater{}}\PYG{l+s}{\PYGZbs{}}\PYG{l+s}{w*)\PYGZus{}.*}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{subject\PYGZus{}id} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{subj\PYGZus{}201}\PYG{l+s}{"}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rename3}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{run} \PYG{o}{=} \PYG{l+m+mi}{2}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{rename3}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}          
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{print} \PYG{n}{res}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file}   
\PYG{g+go}{'subj\PYGZus{}201\PYGZus{}epi\PYGZus{}run02.nii'         }
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
format@_string : (a string)
        Python formatting string for output template
in@_file : (an existing file name)
        file to rename

@PYGZlb[]Optional@PYGZrb[]
keep@_ext : (a boolean)
        Keep in@_file extension, replace non-extension component of name
parse@_string : (a string)
        Python regexp parse string to define replacement inputs
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out@_file : (a file name)
        softlink to original file with new name
\end{Verbatim}


\subsection{\texttt{Select}}
\label{interfaces/generated/nipype.interfaces.utility:select}
Basic interface class to select specific elements from a list


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:id4}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{import} \PYG{n}{Select}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sl} \PYG{o}{=} \PYG{n}{Select}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{\PYGZus{}} \PYG{o}{=} \PYG{n}{sl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{set}\PYG{p}{(}\PYG{n}{inlist}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]}\PYG{p}{,}\PYG{n}{index}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{sl}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out}
\PYG{g+go}{\textasciitilde{}}
\end{Verbatim}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{\PYGZus{}} \PYG{o}{=} \PYG{n}{sl}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{set}\PYG{p}{(}\PYG{n}{inlist}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]}\PYG{p}{,}\PYG{n}{index}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{sl}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out}
\PYG{g+go}{[4, 5]}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
index : (an integer)
        0-based indices of values to choose
inlist  list of values to choose from

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
out     list of selected values
\end{Verbatim}


\subsection{\texttt{Split}}
\label{interfaces/generated/nipype.interfaces.utility:split}
Basic interface class to split lists into multiple outputs


\subsubsection{Examples}
\label{interfaces/generated/nipype.interfaces.utility:id5}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.utility} \PYG{k+kn}{import} \PYG{n}{Split}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{sp} \PYG{o}{=} \PYG{n}{Split}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{\PYGZus{}} \PYG{o}{=} \PYG{n}{sp}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{set}\PYG{p}{(}\PYG{n}{inlist}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{]}\PYG{p}{,}\PYG{n}{splits}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out} \PYG{o}{=} \PYG{n}{sp}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{out}\PYG{o}{.}\PYG{n}{outputs}\PYG{o}{.}\PYG{n}{out1}
\PYG{g+go}{[1, 2]}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]Mandatory@PYGZrb[]
inlist : (a list of items which are any value)
        list of values to split
splits : (a list of items which are an integer)
        Number of outputs in each split - should add to number of inputs

@PYGZlb[]Optional@PYGZrb[]
ignore@_exception : (a boolean)
        Print an error message instead of throwing an exception in case the interface fails to run
\end{Verbatim}


\section{nipype.workflows.camino.camino\_dti\_processing}
\label{interfaces/generated/nipype.workflows.camino.camino_dti_processing:nipype-workflows-camino-camino-dti-processing}\label{interfaces/generated/nipype.workflows.camino.camino_dti_processing::doc}

\subsection{\texttt{create\_camino\_dti\_pipeline()}}
\label{interfaces/generated/nipype.workflows.camino.camino_dti_processing:create-camino-dti-pipeline}
Creates a pipeline that does the same diffusion processing as in the
camino\_dti\_tutorial example script. Given a diffusion-weighted image,
b-values, and b-vectors, the workflow will return the tractography
computed from diffusion tensors and from PICo probabilistic tractography.


\subsubsection{Example}
\label{interfaces/generated/nipype.workflows.camino.camino_dti_processing:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{nipype.workflows.camino} \PYG{k+kn}{as} \PYG{n+nn}{cmonwk}                     
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}camino\PYGZus{}dti} \PYG{o}{=} \PYG{n}{cmonwk}\PYG{o}{.}\PYG{n}{camino\PYGZus{}dti\PYGZus{}processing}\PYG{o}{.}\PYG{n}{create\PYGZus{}camino\PYGZus{}dti\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{nipype\PYGZus{}camino\PYGZus{}dti}\PYG{l+s}{"}\PYG{p}{)}                     
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}camino\PYGZus{}dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{dwi} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{dwi.nii}\PYG{l+s}{'}\PYG{p}{)}                   
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}camino\PYGZus{}dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvecs} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}\PYG{p}{)}                   
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}camino\PYGZus{}dti}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvals} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}\PYG{p}{)}                  
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}camino\PYGZus{}dti}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{dwi}
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvecs}
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvals}
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{fa}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{trace}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{tracts\PYGZus{}pico}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{tracts\PYGZus{}dt}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{tensors}
\end{Verbatim}


\subsubsection{Graph}
\label{interfaces/generated/nipype.workflows.camino.camino_dti_processing:graph}\includegraphics{graphviz-2f6ec5745c0e7d961f2a07ac46eca4325c87d41e.pdf}

\section{nipype.workflows.fsl.dti}
\label{interfaces/generated/nipype.workflows.fsl.dti:nipype-workflows-fsl-dti}\label{interfaces/generated/nipype.workflows.fsl.dti::doc}

\subsection{\texttt{create\_bedpostx\_pipeline()}}
\label{interfaces/generated/nipype.workflows.fsl.dti:create-bedpostx-pipeline}
Creates a pipeline that does the same as bedpostx script from FSL -
calculates diffusion model parameters (distributions not MLE) voxelwise for
the whole volume (by splitting it slicewise).


\subsubsection{Example}
\label{interfaces/generated/nipype.workflows.fsl.dti:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx} \PYG{o}{=} \PYG{n}{create\PYGZus{}bedpostx\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{nipype\PYGZus{}bedpostx}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{dwi} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{mask} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvecs} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvecs}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{bvals} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{bvals}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{xfibres}\PYG{o}{.}\PYG{n}{n\PYGZus{}fibres} \PYG{o}{=} \PYG{l+m+mi}{2}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{xfibres}\PYG{o}{.}\PYG{n}{fudge} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{xfibres}\PYG{o}{.}\PYG{n}{burn\PYGZus{}in} \PYG{o}{=} \PYG{l+m+mi}{1000}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{xfibres}\PYG{o}{.}\PYG{n}{n\PYGZus{}jumps} \PYG{o}{=} \PYG{l+m+mi}{1250}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{xfibres}\PYG{o}{.}\PYG{n}{sample\PYGZus{}every} \PYG{o}{=} \PYG{l+m+mi}{25}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}bedpostx}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{dwi}
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{mask}
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{thsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{phsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{fsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{mean\PYGZus{}thsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{mean\PYGZus{}phsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{mean\PYGZus{}fsamples}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{dyads}
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{dyads\PYGZus{}dispersion}
\end{Verbatim}


\subsubsection{Graph}
\label{interfaces/generated/nipype.workflows.fsl.dti:graph}\includegraphics{graphviz-b4cf2088871c3a5d3786402cfe310f5fb9ec10fc.pdf}

\subsection{\texttt{create\_eddy\_correct\_pipeline()}}
\label{interfaces/generated/nipype.workflows.fsl.dti:create-eddy-correct-pipeline}
Creates a pipeline that replaces eddy\_correct script in FSL. It takes a
series of diffusion weighted images and linearly corregisters them to one
reference image.


\subsubsection{Example}
\label{interfaces/generated/nipype.workflows.fsl.dti:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}eddycorrect} \PYG{o}{=} \PYG{n}{create\PYGZus{}eddy\PYGZus{}correct\PYGZus{}pipeline}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{nipype\PYGZus{}eddycorrect}\PYG{l+s}{"}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}eddycorrect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{diffusion.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}eddycorrect}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{ref\PYGZus{}num} \PYG{o}{=} \PYG{l+m+mi}{0}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{nipype\PYGZus{}eddycorrect}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}

Inputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{in\PYGZus{}file}
\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{ref\PYGZus{}num}
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{outputnode}\PYG{o}{.}\PYG{n}{eddy\PYGZus{}corrected}
\end{Verbatim}


\subsubsection{Graph}
\label{interfaces/generated/nipype.workflows.fsl.dti:id2}\includegraphics{graphviz-3f560aabba6f0593d392dc53c1315f7fe0325650.pdf}

\section{nipype.workflows.fsl.preprocess}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:nipype-workflows-fsl-preprocess}\label{interfaces/generated/nipype.workflows.fsl.preprocess::doc}

\subsection{\texttt{create\_featpreproc()}}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:create-featpreproc}
Create a FEAT preprocessing workflow

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
inputspec.func : functional runs (filename or list of filenames)
inputspec.fwhm : fwhm for smoothing with SUSAN
inputspec.highpass : HWHM in TRs
inputspec.outdir : where preprocessed data should be stored
inputspec.subjectid : subjectid (used for storing output under subject's name
inputspec.subs : paths substitutions for datasink
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
outputspec.reference : volume to which runs are realigned
outputspec.motion@_parameters : motion correction parameters
outputspec.realigned@_files : motion corrected files
outputspec.motion@_plots : plots of motion correction parameters
outputspec.mask : mask file used to mask the brain
outputspec.smoothed@_files : smoothed functional data
outputspec.highpassed@_files : highpassed functional data
outputspec.mean : mean file
\end{Verbatim}


\subsubsection{Example}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:example}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.workflows.fsl} \PYG{k+kn}{import} \PYG{n}{create\PYGZus{}featpreproc}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc} \PYG{o}{=} \PYG{n}{create\PYGZus{}featpreproc}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{func} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{f3.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputspec}\PYG{o}{.}\PYG{n}{highpass} \PYG{o}{=} \PYG{l+m+mf}{128.}\PYG{o}{/}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{o}{*}\PYG{l+m+mf}{2.5}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{base\PYGZus{}dir} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{/tmp}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{preproc}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\subsubsection{Graph}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:graph}\includegraphics{graphviz-9064a95afca04adf83e2f3aebcbdc8187c505395.pdf}

\subsection{\texttt{create\_susan\_smooth()}}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:create-susan-smooth}
Create a SUSAN smoothing workflow

Inputs:

\begin{Verbatim}[commandchars=@\[\]]
inputnode.in@_files : functional runs (filename or list of filenames)
inputnode.fwhm : fwhm for smoothing with SUSAN
inputnode.mask@_file : mask used for estimating SUSAN thresholds (but not for smoothing)
\end{Verbatim}

Outputs:

\begin{Verbatim}[commandchars=@\[\]]
outputnode.smoothed@_files : functional runs (filename or list of filenames)
\end{Verbatim}


\subsubsection{Example}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:id1}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.workflows.fsl} \PYG{k+kn}{import} \PYG{n}{create\PYGZus{}susan\PYGZus{}smooth}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth} \PYG{o}{=} \PYG{n}{create\PYGZus{}susan\PYGZus{}smooth}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{in\PYGZus{}files} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{f3.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mi}{5}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{inputnode}\PYG{o}{.}\PYG{n}{mask\PYGZus{}file} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{mask.nii}\PYG{l+s}{'}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{smooth}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\subsubsection{Graph}
\label{interfaces/generated/nipype.workflows.fsl.preprocess:id2}\includegraphics{graphviz-634a79ab8b35d49f293edfa6c357b37687c4046b.pdf}

\chapter{Developer Guide}
\label{devel/index::doc}\label{devel/index:developer-guide}\label{devel/index:developers-guide-index}\begin{quote}\begin{description}
\item[{Release}] \leavevmode
0.4.dev

\item[{Date}] \leavevmode
April 14, 2011, 19:11 PDT

\end{description}\end{quote}

Since nipype is part of the \href{http://nipy.org}{NIPY} project, we follow the same
conventions documented in the \href{http://nipy.org/devel}{NIPY Developers Guide}. For bleeding-edge version help see \href{http://www.mit.edu/~satra/nipype-nightly/}{Nightly documentation}
\phantomsection\label{devel/writing_custom_interfaces:writing-custom-interfaces}

\section{Interface Specifications}
\label{devel/interface_specs:interface-specifications}\label{devel/interface_specs::doc}

\subsection{Before you start}
\label{devel/interface_specs:before-you-start}
NiPyPe is a young project maintained by an enthusiastic group of developers. Even though the documentation might be sparse or cryptic at times we strongly encourage you to contact us on the official nipype developers mailing list in case of any troubles: \href{mailto:nipy-devel@neuroimaging.scipy.org}{nipy-devel@neuroimaging.scipy.org} (we are sharing a mailing list with the nipy community therefore please add \code{{[}nipype{]}} to the messsage title).


\subsection{Overview}
\label{devel/interface_specs:overview}
We're using the \href{http://code.enthought.com/projects/traits/}{Enthought Traits} package for all of our
inputs and outputs.  Traits allows us to validate user inputs and
provides a mechanism to handle all the \emph{special cases} in a simple and
concise way though metadata.  With the metadata, each input/output can
have an optional set of metadata attributes (described in more detail
below).  The machinery for handling the metadata is located in the
base classes, so all subclasses use the same code to handle these
cases.  This is in contrast to our previous code where every class
defined it's own \_parse\_inputs, run and aggregate\_outputs methods to
handle these cases.  Which of course leads to a dozen different ways
to solve the same problem.

Traits is a big package with a lot to learn in order to take full
advantage of.  But don't be intimidated!  To write a Nipype Trait
Specification, you only need to learn a few of the basics of Traits.
Here are a few starting points in the documentation:
\begin{itemize}
\item {} 
What are Traits?  The \href{http://code.enthought.com/projects/traits/docs/html/traits\_user\_manual/intro.html}{Introduction in the User Manual}
gives a brief description of the functionality traits provides.

\item {} 
Traits and metadata.  The \href{http://code.enthought.com/projects/traits/docs/html/traits\_user\_manual/defining.html}{second section of the User Manual}
gives more details on traits and how to use them.  Plus there a
section describing metadata, including the metadata all traits have.

\item {} 
If your interested in more of a \emph{big picture} overview, \href{http://code.enthought.com/projects/traits/docs/html/tutorials/traits\_ui\_scientific\_app.html}{Gael wrote
a good tutorial}
that shows how to write a scientific application using traits for
the benefit of the generated UI components.  (For now, Nipype is not
taking advantage of the generated UI feature of traits.)

\end{itemize}


\subsubsection{Traits version}
\label{devel/interface_specs:traits-version}
We're using Traits version 3.x which can be install as part of \href{http://enthought.com/products/epd.php}{EPD} or from \href{http://pypi.python.org/pypi/Traits/3.3.0}{pypi}


\subsubsection{More documentation}
\label{devel/interface_specs:more-documentation}
Not everything is documented in the User Manual, in those cases the
\href{https://mail.enthought.com/mailman/listinfo/enthought-dev}{enthought-dev mailing list} or the
\href{http://code.enthought.com/projects/files/ETS32\_API/enthought.traits.html}{API docs}
is your next place to look.


\subsection{Nipype Interface Specifications}
\label{devel/interface_specs:nipype-interface-specifications}
Each interface class defines two specifications: 1) an InputSpec and
2) an OutputSpec.  Each of these are prefixed with the class name of
the interfaces.  For example, Bet has these specs:
\begin{itemize}
\item {} 
BETInputSpec

\item {} 
BETOutputSpec

\end{itemize}

Each of these Specs are classes, derived from a base TraitedSpec class
(more on these below).  The InputSpec consists of attributes which
correspond to different parameters for the tool they wrap/interface.
In the case of a command-line tool like Bet, the InputSpec attributes
correspond to the different command-line parameters that can be passed
to Bet.  If you are familiar with the Nipype 0.2 code-base, these
attributes are the same as the keys in the opt\_map dictionaries.  When
an interfaces class is instantiated, the InputSpec is bound to the
\code{inputs} attribute of that object.  Below is an example of how the
\code{inputs} appear to a user for Bet:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n+nb}{type}\PYG{p}{(}\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{p}{)}
\PYG{g+go}{\textless{}class 'nipype.interfaces.fsl.preprocess.BETInputSpec'\textgreater{}}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{o}{\textless{}}\PYG{n}{TAB}\PYG{o}{\textgreater{}}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}class\PYGZus{}\PYGZus{}           bet.inputs.center}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}delattr\PYGZus{}\PYGZus{}         bet.inputs.environ}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}doc\PYGZus{}\PYGZus{}             bet.inputs.frac}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}getattribute\PYGZus{}\PYGZus{}    bet.inputs.functional}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}hash\PYGZus{}\PYGZus{}            bet.inputs.hashval}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}init\PYGZus{}\PYGZus{}            bet.inputs.infile}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}new\PYGZus{}\PYGZus{}             bet.inputs.items}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}reduce\PYGZus{}\PYGZus{}          bet.inputs.mask}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}reduce\PYGZus{}ex\PYGZus{}\PYGZus{}       bet.inputs.mesh}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}repr\PYGZus{}\PYGZus{}            bet.inputs.nooutput}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}setattr\PYGZus{}\PYGZus{}         bet.inputs.outfile}
\PYG{g+go}{bet.inputs.\PYGZus{}\PYGZus{}str\PYGZus{}\PYGZus{}             bet.inputs.outline}
\PYG{g+go}{bet.inputs.\PYGZus{}generate\PYGZus{}handlers  bet.inputs.outputtype}
\PYG{g+go}{bet.inputs.\PYGZus{}get\PYGZus{}hashval        bet.inputs.radius}
\PYG{g+go}{bet.inputs.\PYGZus{}hash\PYGZus{}infile        bet.inputs.reduce\PYGZus{}bias}
\PYG{g+go}{bet.inputs.\PYGZus{}xor\PYGZus{}inputs         bet.inputs.skull}
\PYG{g+go}{bet.inputs.\PYGZus{}xor\PYGZus{}warn           bet.inputs.threshold}
\PYG{g+go}{bet.inputs.args                bet.inputs.vertical\PYGZus{}gradient}
\end{Verbatim}

Each Spec inherits from a parent Spec.  The parent Specs provide
attribute(s) that are common to all child classes.  For example, FSL
InputSpecs inherit from interfaces.fsl.base.FSLTraitedSpec.
FSLTraitedSpec defines an \code{outputtype} attribute, which stores the
file type (NIFTI, NIFTI\_PAIR, etc...) for all generated output files.


\subsubsection{InputSpec class hierarchy}
\label{devel/interface_specs:inputspec-class-hierarchy}
Below is the current class hierarchy for InputSpec classes (from
base class down to subclasses).:
\begin{quote}

\code{TraitedSpec}: Nipype's primary base class for all Specs.
Provides initialization, some nipype-specific methods and any trait
handlers we define. Inherits from traits.HasTraits.
\begin{quote}

\code{BaseInterfaceInputSpec}: Defines inputs common to all
Interfaces (\code{ignore\_exception}). If in doubt inherit from this.
\begin{quote}

\code{CommandLineInputSpec}: Defines inputs common to all
command-line classes (\code{args} and \code{environ})
\begin{quote}

\code{FSLTraitedSpec}: Defines inputs common to all FSL classes
(\code{outputtype})

\code{SPMCommandInputSpec}: Defines inputs common to all SPM classes (\code{matlab\_cmd}, \code{path}, and \code{mfile})

\code{FSTraitedSpec}: Defines inputs common to all FreeSurfer classes
(\code{sbjects\_dir})

\code{MatlabInputSpec}: Defines inputs common to all Matlab classes (\code{script}, \code{nodesktop}, \code{nosplash}, \code{logfile}, \code{single\_comp\_thread}, \code{mfile}, \code{script\_file}, and \code{paths})

\code{SlicerCommandLineInputSpec}: Defines inputs common to all Slicer classes (\code{module})
\end{quote}
\end{quote}
\end{quote}
\end{quote}

Most developers will only need to code at the the interface-level (i.e. implementing custom class inheriting from one of the above classes).


\subsubsection{Output Specs}
\label{devel/interface_specs:output-specs}
The OutputSpec defines the outputs that are generated, or possibly
generated depending on inputs, by the tool.  OutputSpecs inherit from
\code{interfaces.base.TraitedSpec} directly.


\subsection{Traited Attributes}
\label{devel/interface_specs:traited-attributes}
Each specification attribute is an instance of a Trait class.  These
classes encapsulate many standard Python types like Float and Int, but
with additional behavior like type checking.  (\emph{See the documentation
on traits for more information on these trait types.}) To handle
unique behaviors of our attributes we us traits metadata.  These are
keyword arguments supplied in the initialization of the attributes.
The base classes \code{BaseInterface} and \code{CommandLine}
(defined in \code{nipype.interfaces.base}) check for the existence/or
value of these metadata and handle the inputs/outputs accordingly.
For example, all mandatory parameters will have the \code{mandatory =
True} metadata:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{BetInputSpec}\PYG{p}{(}\PYG{n}{FSLTraitedSpec}\PYG{p}{)}\PYG{p}{:}
  \PYG{n}{infile} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,}
                \PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{input file to skull strip}\PYG{l+s}{'}\PYG{p}{,}
                \PYG{n}{argstr}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s+si}{\%s}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{position}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{mandatory}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\end{Verbatim}


\subsubsection{Common}
\label{devel/interface_specs:common}\begin{description}
\item[{\code{exists}}] \leavevmode
For files, use \code{nipype.interfaces.base.File} as the trait type.  If
the file must exist for the tool to execute, specify \code{exists = True}
in the initialization of File (as shown in BetInputSpec above). This
will trigger the underlying traits code to confirm the file assigned
to that \emph{input} actually exists.  If it does not exist, the user will
be presented with an error message:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{does\PYGZus{}not\PYGZus{}exist.nii}\PYG{l+s}{'}
\PYG{g+go}{------------------------------------------------------------}
\PYG{g+gt}{Traceback (most recent call last):}
  File \PYG{n+nb}{"\textless{}ipython console\textgreater{}"}, line \PYG{l+m}{1}, in \PYG{n+nIdentifier}{\textless{}module\textgreater{}}
  File \PYG{n+nb}{"/Users/cburns/local/lib/python2.5/site-packages/nipype/interfaces/base.py"}, line \PYG{l+m}{76}, in \PYG{n+nIdentifier}{validate}
    \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{error}\PYG{p}{(} \PYG{n+nb}{object}\PYG{p}{,} \PYG{n}{name}\PYG{p}{,} \PYG{n}{value} \PYG{p}{)}
  File \PYG{n+nb}{"/Users/cburns/local/lib/python2.5/site-packages/enthought/traits/trait\PYGZus{}handlers.py"}, line \PYG{l+m}{175}, in \PYG{n+nIdentifier}{error}
    \PYG{n}{value} \PYG{p}{)}
\PYG{n+nc}{TraitError}: \PYG{n+nIdentifier}{The 'infile' trait of a BetInputSpec instance must be a file}
\PYG{g+go}{name, but a value of 'does\PYGZus{}not\PYGZus{}exist.nii' \textless{}type 'str'\textgreater{} was specified.}
\end{Verbatim}

\item[{\code{desc}}] \leavevmode
All trait objects have a set of default metadata attributes.  \code{desc}
is one of those and is used as a simple, one-line docstring.  The
\code{desc} is printed when users use the \code{help()} methods.
\begin{description}
\item[{\textbf{Required:} This metadata is required by all nipype interface}] \leavevmode
classes.

\end{description}

\item[{\code{usedefault}}] \leavevmode
Set this metadata to True when the \emph{default value} for the trait type
of this attribute is an acceptable value.  All trait objects have a
default value, \code{traits.Int} has a default of \code{0}, \code{traits.Float}
has a default of \code{0.0}, etc...  You can also define a default value
when you define the class.  For example, in the code below all objects
of \code{Foo} will have a default value of 12 for \code{x}:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{import} \PYG{n+nn}{enthought.traits.api} \PYG{k+kn}{as} \PYG{n+nn}{traits}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k}{class} \PYG{n+nc}{Foo}\PYG{p}{(}\PYG{n}{traits}\PYG{o}{.}\PYG{n}{HasTraits}\PYG{p}{)}\PYG{p}{:}
\PYG{g+gp}{... }    \PYG{n}{x} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Int}\PYG{p}{(}\PYG{l+m+mi}{12}\PYG{p}{)}
\PYG{g+gp}{... }    \PYG{n}{y} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Int}
\PYG{g+gp}{...}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{foo} \PYG{o}{=} \PYG{n}{Foo}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{foo}\PYG{o}{.}\PYG{n}{x}
\PYG{g+go}{12}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{foo}\PYG{o}{.}\PYG{n}{y}
\PYG{g+go}{0}
\end{Verbatim}

Nipype only passes \code{inputs} on to the underlying package if they
have been defined (more on this later).  So if you specify
\code{usedefault = True}, you are telling the parser to pass the default
value on to the underlying package.  Let's look at the InputSpec for
SPM Realign:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{RealignInputSpec}\PYG{p}{(}\PYG{n}{BaseInterfaceInputSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{jobtype} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Enum}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{estwrite}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{estimate}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{write}\PYG{l+s}{'}\PYG{p}{,}
                          \PYG{n}{desc}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{one of: estimate, write, estwrite}\PYG{l+s}{'}\PYG{p}{,}
                          \PYG{n}{usedefault}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\end{Verbatim}

Here we've defined \code{jobtype} to be an enumerated trait type,
\code{Enum}, which can be set to one of the following: \code{estwrite},
\code{estimate}, or \code{write}.  In a container, the default is always the
first element.  So in this case, the default will be \code{estwrite}:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{spm}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rlgn} \PYG{o}{=} \PYG{n}{spm}\PYG{o}{.}\PYG{n}{Realign}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rlgn}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}
\PYG{g+go}{\textless{}undefined\textgreater{}}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{rlgn}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{jobtype}
\PYG{g+go}{'estwrite'}
\end{Verbatim}

\item[{\code{xor} and \code{requires}}] \leavevmode
Both of these accept a list of trait names. The \code{xor} metadata reflects
mutually exclusive traits, while the requires metadata reflects traits
that have to be set together. When a xor-ed trait is set, all other
traits belonging to the list are set to Undefined. The function
check\_mandatory\_inputs ensures that all requirements (both mandatory and
via the requires metadata are satisfied). These are also reflected in
the help function.

\end{description}


\subsubsection{CommandLine}
\label{devel/interface_specs:commandline}\begin{description}
\item[{\code{argstr}}] \leavevmode
The metadata keyword for specifying the format strings
for the parameters. This was the \emph{value} string in the opt\_map
dictionaries of Nipype 0.2 code.  If we look at the
\code{FlirtInputSpec}, the \code{argstr} for the reference file corresponds
to the argument string I would need to provide with the command-line
version of \code{flirt}:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{FlirtInputSpec}\PYG{p}{(}\PYG{n}{FSLTraitedSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{reference} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{argstr} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{-ref }\PYG{l+s+si}{\%s}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mandatory} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,}
                     \PYG{n}{position} \PYG{o}{=} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{reference file}\PYG{l+s}{'}\PYG{p}{)}
\end{Verbatim}

\textbf{Required:} This metadata is required by all command-line interface classes.

\item[{\code{position}}] \leavevmode
This metadata is used to specify the position of arguments.  Both
positive and negative values are accepted.  \code{position = 0} will
position this argument as the first parameter after the command
name. \code{position = -1} will position this argument as the last
parameter, after all other parameters.

\item[{\code{genfile}}] \leavevmode
If True, the \code{genfile} metadata specifies that a filename should be
generated for this parameter \emph{if-and-only-if} the user did not provide
one.  The nipype convention is to automatically generate output
filenames when not specified by the user both as a convenience for the
user and so the pipeline can easily gather the outputs. Requires
\code{\_gen\_filename()} method to be implemented. This way should be used if the
desired file name is dependent on some runtime variables (such as file name
of one of the inputs, or current working directory). In case when it should
be fixed it's recommended to just use \code{usedefault}.

\item[{\code{sep}}] \leavevmode
For List traits the string with witch elements of the list will be joined.

\end{description}


\subsubsection{SPM}
\label{devel/interface_specs:spm}\begin{description}
\item[{\code{field}}] \leavevmode
name of the structure refered by the SPM job manager
\begin{description}
\item[{\textbf{Required:} This metadata is required by all SPM-mediated}] \leavevmode
interface classes.

\end{description}

\end{description}


\subsection{Defining an interface class}
\label{devel/interface_specs:defining-an-interface-class}

\subsubsection{Common}
\label{devel/interface_specs:id1}
When you define an interface class, you will define these attributes
and methods:
\begin{itemize}
\item {} 
\code{input\_spec}: the InputSpec

\item {} 
\code{output\_spec}: the OutputSpec

\item {} 
\code{\_list\_outputs()}: Returns a dictionary containing names of generated files that are expected after package completes execution.  This is used by \code{BaseInterface.aggregate\_outputs} to gather all output files for the pipeline.

\end{itemize}


\subsubsection{CommandLine}
\label{devel/interface_specs:id2}
For command-line interfaces:
\begin{itemize}
\item {} 
\code{\_cmd}: the command-line command

\end{itemize}

If you used genfile:
\begin{itemize}
\item {} 
\code{\_gen\_filename(name)}:  Generate filename, used for filenames that nipype generates as a convenience for users.  This is for parameters that are required by the wrapped package, but we're generating from some other parameter. For example, \code{BET.inputs.outfile} is required by BET but we can generate the name from \code{BET.inputs.infile}.  Override this method in subclass to handle.

\end{itemize}

And optionally:
\begin{itemize}
\item {} 
\code{\_format\_arg(name, spec, value)}: For extra formatting of the input values before passing them to generic \code{\_parse\_inputs()} method.

\end{itemize}

For example this is the class definition for Flirt, minus the docstring:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Flirt}\PYG{p}{(}\PYG{n}{NEW\PYGZus{}FSLCommand}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{\PYGZus{}cmd} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{flirt}\PYG{l+s}{'}
    \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{FlirtInputSpec}
    \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{FlirtOutputSpec}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outputs} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{output\PYGZus{}spec}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get}\PYG{p}{(}\PYG{p}{)}
        \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outfile}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}
        \PYG{c}{\# Generate an outfile if one is not provided}
        \PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{isdefined}\PYG{p}{(}\PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outfile}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)} \PYG{o+ow}{and} \PYG{n}{isdefined}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}\PYG{p}{)}\PYG{p}{:}
            \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outfile}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}gen\PYGZus{}fname}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}\PYG{p}{,}
                                                 \PYG{n}{suffix} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}flirt}\PYG{l+s}{'}\PYG{p}{)}
        \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outmatrix}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outmatrix}
        \PYG{c}{\# Generate an outmatrix file if one is not provided}
        \PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{isdefined}\PYG{p}{(}\PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outmatrix}\PYG{l+s}{'}\PYG{p}{]}\PYG{p}{)} \PYG{o+ow}{and} \PYGZbs{}
                \PYG{n}{isdefined}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}\PYG{p}{)}\PYG{p}{:}
            \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{outmatrix}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}gen\PYGZus{}fname}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}\PYG{p}{,}
                                                   \PYG{n}{suffix} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}flirt.mat}\PYG{l+s}{'}\PYG{p}{,}
                                                   \PYG{n}{change\PYGZus{}ext} \PYG{o}{=} \PYG{n+nb+bp}{False}\PYG{p}{)}
        \PYG{k}{return} \PYG{n}{outputs}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}gen\PYGZus{}filename}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{name}\PYG{p}{)}\PYG{p}{:}
        \PYG{k}{if} \PYG{n}{name} \PYG{o+ow}{in} \PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{outfile}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{outmatrix}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{:}
            \PYG{k}{return} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{n}{name}\PYG{p}{]}
        \PYG{k}{else}\PYG{p}{:}
            \PYG{k}{return} \PYG{n+nb+bp}{None}
\end{Verbatim}

There are two possible output files \code{outfile} and \code{outmatrix},
both of which can be generated if not specified by the user.

Also notice the use of \code{self.\_gen\_fname()} - a FSLCommand helper method for generating filenames (with extensions conforming with FSLOUTPUTTYPE).

See also {\hyperref[devel/cmd_interface_devel::doc]{\emph{How to wrap a command line tool}}}.


\subsubsection{SPM}
\label{devel/interface_specs:id3}
For SPM-mediated interfaces:
\begin{itemize}
\item {} 
\code{\_jobtype} and \code{\_jobname}: special names used used by the SPM job manager. You can find them by saving your batch job as an .m file and looking up the code.

\end{itemize}

And optionally:
\begin{itemize}
\item {} 
\code{\_format\_arg(name, spec, value)}: For extra formatting of the input values before passing them to generic \code{\_parse\_inputs()} method.

\end{itemize}


\subsubsection{Matlab}
\label{devel/interface_specs:matlab}
See {\hyperref[devel/matlab_interface_devel::doc]{\emph{How to wrap a MATLAB script}}}.


\subsubsection{Python}
\label{devel/interface_specs:python}
See {\hyperref[devel/python_interface_devel::doc]{\emph{How to wrap a Python script}}}.


\subsection{Undefined inputs}
\label{devel/interface_specs:undefined-inputs}
All the inputs and outputs that were not explicitly set (And do not have a usedefault flag - see above) will have Undefined value. To check if something is defined you have to explicitly call \code{isdefiend} function (comparing to None will not work).


\subsection{Example of inputs}
\label{devel/interface_specs:example-of-inputs}
Below we have an example of using Bet.  We can see from the help which
inputs are mandatory and which are optional, along with the one-line
description provided by the \code{desc} metadata:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{o}{.}\PYG{n}{help}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{Inputs}
\PYG{g+go}{------}

\PYG{g+go}{Mandatory:}
\PYG{g+go}{ infile: input file to skull strip}

\PYG{g+go}{Optional:}
\PYG{g+go}{ args: Additional parameters to the command}
\PYG{g+go}{ center: center of gravity in voxels}
\PYG{g+go}{ environ: Environment variables (default=\PYGZob{}\PYGZcb{})}
\PYG{g+go}{ frac: fractional intensity threshold}
\PYG{g+go}{ functional: apply to 4D fMRI data}
\PYG{g+go}{ mask: create binary mask image}
\PYG{g+go}{ mesh: generate a vtk mesh brain surface}
\PYG{g+go}{ nooutput: Don't generate segmented output}
\PYG{g+go}{ outfile: name of output skull stripped image}
\PYG{g+go}{ outline: create surface outline image}
\PYG{g+go}{ outputtype: None}
\PYG{g+go}{ radius: head radius}
\PYG{g+go}{ reduce\PYGZus{}bias: bias field and neck cleanup}
\PYG{g+go}{ skull: create skull image}
\PYG{g+go}{ threshold: apply thresholding to segmented brain image and mask}
\PYG{g+go}{ vertical\PYGZus{}gradient: vertical gradient in fractional intensity threshold (-1, 1)}

\PYG{g+go}{Outputs}
\PYG{g+go}{-------}
\PYG{g+go}{maskfile: path/name of binary brain mask (if generated)}
\PYG{g+go}{meshfile: path/name of vtk mesh file (if generated)}
\PYG{g+go}{outfile: path/name of skullstripped file}
\PYG{g+go}{outlinefile: path/name of outline file (if generated)}
\end{Verbatim}

Here we create a bet object and specify the required input. We then
check our inputs to see which are defined and which are not:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{BET}\PYG{p}{(}\PYG{n}{infile} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{f3.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet}\PYG{o}{.}\PYG{n}{inputs}
\PYG{g+go}{args = \textless{}undefined\textgreater{}}
\PYG{g+go}{center = \textless{}undefined\textgreater{}}
\PYG{g+go}{environ = \PYGZob{}'FSLOUTPUTTYPE': 'NIFTI\PYGZus{}GZ'\PYGZcb{}}
\PYG{g+go}{frac = \textless{}undefined\textgreater{}}
\PYG{g+go}{functional = \textless{}undefined\textgreater{}}
\PYG{g+go}{infile = f3.nii}
\PYG{g+go}{mask = \textless{}undefined\textgreater{}}
\PYG{g+go}{mesh = \textless{}undefined\textgreater{}}
\PYG{g+go}{nooutput = \textless{}undefined\textgreater{}}
\PYG{g+go}{outfile = \textless{}undefined\textgreater{}}
\PYG{g+go}{outline = \textless{}undefined\textgreater{}}
\PYG{g+go}{outputtype = NIFTI\PYGZus{}GZ}
\PYG{g+go}{radius = \textless{}undefined\textgreater{}}
\PYG{g+go}{reduce\PYGZus{}bias = \textless{}undefined\textgreater{}}
\PYG{g+go}{skull = \textless{}undefined\textgreater{}}
\PYG{g+go}{threshold = \textless{}undefined\textgreater{}}
\PYG{g+go}{vertical\PYGZus{}gradient = \textless{}undefined\textgreater{}}
\PYG{g+gp}{\textgreater{}\textgreater{}\textgreater{} }\PYG{n}{bet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{'bet f3.nii /Users/cburns/data/nipype/s1/f3\PYGZus{}brain.nii.gz'}
\end{Verbatim}

We also checked the command-line that will be generated when we run
the command and can see the generated output filename
\code{f3\_brain.nii.gz}.


\section{How to wrap a command line tool}
\label{devel/cmd_interface_devel::doc}\label{devel/cmd_interface_devel:how-to-wrap-a-command-line-tool}\label{devel/cmd_interface_devel:interface-devel}
The aim of this section is to describe how external programs and scripts can be
wrapped for use in Nipype either as interactive interfaces or within the
workflow/pipeline environment. Currently, there is support for command line
executables/scripts and matlab scripts. One can also create pure Python
interfaces. The key to defining interfaces is to provide a formal specification
of inputs and outputs and determining what outputs are generated given a set of
inputs.


\subsection{Defining inputs and outputs}
\label{devel/cmd_interface_devel:defining-inputs-and-outputs}
In NiPyPe we have decided to use Enthought Traits to define inputs and outputs of the interfaces.
This allows to introduce easy type checking. Inputs and outputs are grouped into separate classes
(usually suffixed with InputSpec and OutputSpec). For example:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{ExampleInputSpec}\PYG{p}{(}\PYG{n}{TraitedSpec}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{input\PYGZus{}volume} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{Input volume}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{mandatory} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}
        \PYG{n}{parameter} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Int}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{some parameter}\PYG{l+s}{"}\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{ExampleOutputSpec}\PYG{p}{(}\PYG{n}{TraitedSpec}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{output\PYGZus{}volume} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{Output volume}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}
\end{Verbatim}

For the Traits (and NiPyPe) to work correctly output and input spec has to be inherited from TraitedSpec
(however, this does not have to be direct inheritance).

Traits (File, Int etc.) have different parameters (called metadata). In the above example we have used the desc metadata
which holds human readable description of the input. mandatory flag forces NiPyPe to throw an exception if the input was not set.
exists is a special flag that works only for File traits and checks if the provided file exists.

The input and output specifications have to be connected to the our example interface class:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Example}\PYG{p}{(}\PYG{n}{Interface}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ExampleInputSpec}
        \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ExampleOutputSpec}
\end{Verbatim}

Where the names of the classes grouping inputs and outputs were arbitrary the names of the fields within
the interface they are assigned are not (it always has to be input\_spec and output\_spec). Of course this interface does not do much
because we have not specified how to process the inputs and create the outputs. This can be done in many ways.


\subsection{Command line executable}
\label{devel/cmd_interface_devel:command-line-executable}
As with all interfaces command line wrappers need to have inputs defined. Command line input spec has to inherit from
CommandLineInputSpec which adds two extra inputs: environ (a dictionary of environmental variables), and args (a string defining extra flags).
In addition input spec can define the relation between the inputs and the generated command line. To achieve this we have added two metadata: argstr
(string defining how the argument should be formated) and position (number defining the order of the arguments). For example

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{ExampleInputSpec}\PYG{p}{(}\PYG{n}{CommandLineSpec}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{input\PYGZus{}volume} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{Input volume}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{mandatory} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{position} \PYG{o}{=} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{argstr}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{"}\PYG{p}{)}
        \PYG{n}{parameter} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Int}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{some parameter}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{argstr} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{--param }\PYG{l+s+si}{\%d}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

As you probably noticed the argstr is a printf type string with formatting symbols. For an input defined in InputSpec to be included into the executed commandline argstr has to be included. Additionally inside the main
interface class you need to specify the name of the executable by assigning it to the \_cmd field. Also the main interface
class needs to inherit from CommandLine:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Example}\PYG{p}{(}\PYG{n}{CommandLine}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{\PYGZus{}cmd} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{my\PYGZus{}command}\PYG{l+s}{'}
        \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ExampleInputSpec}
        \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ExampleOutputSpec}
\end{Verbatim}

There is one more thing we need to take care of. When the executable finishes processing it will presumably create some
output files. We need to know which files to look for, check if they exist and expose them to whatever node would like to use them.
This is done by implementing \_list\_outputs() method in the main interface class. Basically what it does is assigning the expected output files to the fields of our
output spec:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outputs} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{output\PYGZus{}spec}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get}\PYG{p}{(}\PYG{p}{)}
        \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{output\PYGZus{}volume}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{name\PYGZus{}of\PYGZus{}the\PYGZus{}file\PYGZus{}this\PYGZus{}cmd\PYGZus{}made.nii}\PYG{l+s}{'}\PYG{p}{)}
        \PYG{k}{return} \PYG{n}{outputs}
\end{Verbatim}

Sometimes the inputs need extra parsing before turning into command line parameters. For example imagine a parameter selecting between three methods:
``old'', ``standard'' and ``new''. Imagine also that the command line accept this as a parameter ``--method='' accepting 0, 1 or 2. Since we
are aiming to make nipype scripts as informative as possible it's better to define the inputs as following:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{ExampleInputSpec}\PYG{p}{(}\PYG{n}{CommandLineSpec}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{method} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Enum}\PYG{p}{(}\PYG{l+s}{"}\PYG{l+s}{old}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{standard}\PYG{l+s}{"}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{new}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{method}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{argstr}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{--method=}\PYG{l+s+si}{\%d}\PYG{l+s}{"}\PYG{p}{)}
\end{Verbatim}

Here we've used the Enum trait which restricts input a few fixed options. If we would leave it as it is it would not work since the argstr is expecting
numbers. We need to do additional parsing by overloading the following method in the main interface class:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{\PYGZus{}format\PYGZus{}arg}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{name}\PYG{p}{,} \PYG{n}{spec}\PYG{p}{,} \PYG{n}{value}\PYG{p}{)}\PYG{p}{:}
        \PYG{k}{if} \PYG{n}{name} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{method}\PYG{l+s}{'}\PYG{p}{:}
            \PYG{k}{return} \PYG{n}{spec}\PYG{o}{.}\PYG{n}{argstr}\PYG{o}{\%}\PYG{p}{\PYGZob{}}\PYG{l+s}{"}\PYG{l+s}{old}\PYG{l+s}{"}\PYG{p}{:}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{standard}\PYG{l+s}{"}\PYG{p}{:}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+s}{"}\PYG{l+s}{new}\PYG{l+s}{"}\PYG{p}{:}\PYG{l+m+mi}{2}\PYG{p}{\PYGZcb{}}\PYG{p}{[}\PYG{n}{value}\PYG{p}{]}
        \PYG{k}{return} \PYG{n+nb}{super}\PYG{p}{(}\PYG{n}{Example}\PYG{p}{,} \PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{o}{.}\PYG{n}{\PYGZus{}format\PYGZus{}arg}\PYG{p}{(}\PYG{n}{name}\PYG{p}{,} \PYG{n}{spec}\PYG{p}{,} \PYG{n}{value}\PYG{p}{)}
\end{Verbatim}

Here is a minimalistic interface for the gzip command:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{p}{(}
    \PYG{n}{TraitedSpec}\PYG{p}{,}
    \PYG{n}{CommandLineInputSpec}\PYG{p}{,}
    \PYG{n}{CommandLine}\PYG{p}{,}
    \PYG{n}{File}
\PYG{p}{)}
\PYG{k+kn}{import} \PYG{n+nn}{os}

\PYG{k}{class} \PYG{n+nc}{GZipInputSpec}\PYG{p}{(}\PYG{n}{CommandLineInputSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{input\PYGZus{}file} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{File}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{mandatory} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{argstr}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s+si}{\%s}\PYG{l+s}{"}\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{GZipOutputSpec}\PYG{p}{(}\PYG{n}{TraitedSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{output\PYGZus{}file} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{desc} \PYG{o}{=} \PYG{l+s}{"}\PYG{l+s}{Zip file}\PYG{l+s}{"}\PYG{p}{,} \PYG{n}{exists} \PYG{o}{=} \PYG{n+nb+bp}{True}\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{GZipTask}\PYG{p}{(}\PYG{n}{CommandLine}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{GZipInputSpec}
    \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{GZipOutputSpec}
    \PYG{n}{cmd} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{gzip}\PYG{l+s}{'}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
            \PYG{n}{outputs} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{output\PYGZus{}spec}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get}\PYG{p}{(}\PYG{p}{)}
            \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{output\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{input\PYGZus{}file} \PYG{o}{+} \PYG{l+s}{"}\PYG{l+s}{.gz}\PYG{l+s}{"}\PYG{p}{)}
            \PYG{k}{return} \PYG{n}{outputs}

\PYG{k}{if} \PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{==} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}}\PYG{l+s}{'}\PYG{p}{:}

    \PYG{n}{zipper} \PYG{o}{=} \PYG{n}{GZipTask}\PYG{p}{(}\PYG{n}{input\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{an\PYGZus{}existing\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{)}
    \PYG{k}{print} \PYG{n}{zipper}\PYG{o}{.}\PYG{n}{cmdline}
    \PYG{n}{zipper}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}


\section{How to wrap a MATLAB script}
\label{devel/matlab_interface_devel::doc}\label{devel/matlab_interface_devel:how-to-wrap-a-matlab-script}
This is minimal script for wrapping MATLAB code. You should replace the MATLAB
code template, and define approriate inputs and outputs.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.matlab} \PYG{k+kn}{import} \PYG{n}{MatlabCommand}
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.traits} \PYG{k+kn}{import} \PYG{n}{File}
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{TraitedSpec}\PYG{p}{,} \PYG{n}{BaseInterface}\PYG{p}{,} \PYG{n}{BaseInterfaceInputSpec}
\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{k+kn}{from} \PYG{n+nn}{string} \PYG{k+kn}{import} \PYG{n}{Template}

\PYG{k}{class} \PYG{n+nc}{ConmapTxt2MatInputSpec}\PYG{p}{(}\PYG{n}{BaseInterfaceInputSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{in\PYGZus{}file} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{mandatory}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
    \PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{cmatrix.mat}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{usedefault}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{ConmapTxt2MatOutputSpec}\PYG{p}{(}\PYG{n}{TraitedSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{out\PYGZus{}file} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{ConmapTxt2Mat}\PYG{p}{(}\PYG{n}{BaseInterface}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ConmapTxt2MatInputSpec}
    \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{ConmapTxt2MatOutputSpec}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}run\PYGZus{}interface}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{runtime}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{d} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{in\PYGZus{}file}\PYG{o}{=}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{in\PYGZus{}file}\PYG{p}{,}
        \PYG{n}{out\PYGZus{}file}\PYG{o}{=}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file}\PYG{p}{)}
        \PYG{c}{\#this is your MATLAB code template}
        \PYG{n}{script} \PYG{o}{=} \PYG{n}{Template}\PYG{p}{(}\PYG{l+s}{"""}\PYG{l+s}{in\PYGZus{}file = ‘\$in\PYGZus{}file}\PYG{l+s}{'}\PYG{l+s}{;}
\PYG{l+s}{out\PYGZus{}file = ‘\$out\PYGZus{}file}\PYG{l+s}{'}\PYG{l+s}{;}
\PYG{l+s}{ConmapTxt2Mat(in\PYGZus{}file, out\PYGZus{}file);}
\PYG{l+s}{exit;}
\PYG{l+s}{"""}\PYG{p}{)}\PYG{o}{.}\PYG{n}{substitute}\PYG{p}{(}\PYG{n}{d}\PYG{p}{)}

        \PYG{c}{\# mfile = True  will create an .m file with your script and executed. Alternatively}
        \PYG{c}{\# mfile can be set to False which will cause the matlab code to be passed}
        \PYG{c}{\# as a commandline argument to the matlab executable (without creating any files).}
        \PYG{c}{\# This, however, is less reliable and harder to debug (code will be reduced to}
        \PYG{c}{\# a single line and stripped of any comments).}
        \PYG{n}{result} \PYG{o}{=} \PYG{n}{MatlabCommand}\PYG{p}{(}\PYG{n}{script}\PYG{o}{=}\PYG{n}{script}\PYG{p}{,} \PYG{n}{mfile}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
        \PYG{k}{return} \PYG{n}{result}\PYG{o}{.}\PYG{n}{runtime}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outputs} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}outputs}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get}\PYG{p}{(}\PYG{p}{)}
        \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{'}\PYG{l+s}{out\PYGZus{}file}\PYG{l+s}{'}\PYG{p}{]} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{out\PYGZus{}file}\PYG{p}{)}
        \PYG{k}{return} \PYG{n}{outputs}
\end{Verbatim}


\section{How to wrap a Python script}
\label{devel/python_interface_devel::doc}\label{devel/python_interface_devel:how-to-wrap-a-python-script}
This is a minimal pure python interface. As you can see all you need to do is to
do is to define inputs, outputs, \_run\_interface() (not run()), and \_list\_outputs.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces.base} \PYG{k+kn}{import} \PYG{n}{BaseInterface}\PYG{p}{,} \PYGZbs{}
    \PYG{n}{BaseInterfaceInputSpec}\PYG{p}{,} \PYG{n}{traits}\PYG{p}{,} \PYG{n}{File}
\PYG{k+kn}{from} \PYG{n+nn}{nipype.utils.filemanip} \PYG{k+kn}{import} \PYG{n}{split\PYGZus{}filename}

\PYG{k+kn}{import} \PYG{n+nn}{nibabel} \PYG{k+kn}{as} \PYG{n+nn}{nb}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{os}

\PYG{k}{class} \PYG{n+nc}{SimpleThresholdInputSpec}\PYG{p}{(}\PYG{n}{BaseInterfaceInputSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{volume} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{desc}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{volume to be thresholded}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{mandatory}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
    \PYG{n}{threshold} \PYG{o}{=} \PYG{n}{traits}\PYG{o}{.}\PYG{n}{Float}\PYG{p}{(}\PYG{n}{desc}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{everything below this value will be set to zero}\PYG{l+s}{'}\PYG{p}{,}
                             \PYG{n}{mandatory}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}


\PYG{k}{class} \PYG{n+nc}{SimpleThresholdOutputSpec}\PYG{p}{(}\PYG{n}{TraitedSpec}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{thresholded\PYGZus{}volume} \PYG{o}{=} \PYG{n}{File}\PYG{p}{(}\PYG{n}{exists}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{desc}\PYG{o}{=}\PYG{l+s}{"}\PYG{l+s}{thresholded volume}\PYG{l+s}{"}\PYG{p}{)}


\PYG{k}{class} \PYG{n+nc}{SimpleThreshold}\PYG{p}{(}\PYG{n}{BaseInterface}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{input\PYGZus{}spec} \PYG{o}{=} \PYG{n}{SimpleThresholdInputSpec}
    \PYG{n}{output\PYGZus{}spec} \PYG{o}{=} \PYG{n}{SimpleThresholdOutputSpec}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}run\PYGZus{}interface}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{runtime}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{fname} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{volume}
        \PYG{n}{img} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{load}\PYG{p}{(}\PYG{n}{fname}\PYG{p}{)}
        \PYG{n}{data} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{img}\PYG{o}{.}\PYG{n}{get\PYGZus{}data}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}

        \PYG{n}{active\PYGZus{}map} \PYG{o}{=} \PYG{n}{data} \PYG{o}{\textgreater{}} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{threshold}

        \PYG{n}{thresholded\PYGZus{}map} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{zeros}\PYG{p}{(}\PYG{n}{data}\PYG{o}{.}\PYG{n}{shape}\PYG{p}{)}
        \PYG{n}{thresholded\PYGZus{}map}\PYG{p}{[}\PYG{n}{active\PYGZus{}map}\PYG{p}{]} \PYG{o}{=} \PYG{n}{data}\PYG{p}{[}\PYG{n}{active\PYGZus{}map}\PYG{p}{]}

        \PYG{n}{new\PYGZus{}img} \PYG{o}{=} \PYG{n}{nb}\PYG{o}{.}\PYG{n}{Nifti1Image}\PYG{p}{(}\PYG{n}{thresholded\PYGZus{}map}\PYG{p}{,} \PYG{n}{img}\PYG{o}{.}\PYG{n}{get\PYGZus{}affine}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{img}\PYG{o}{.}\PYG{n}{get\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
        \PYG{n}{\PYGZus{}}\PYG{p}{,} \PYG{n}{base}\PYG{p}{,} \PYG{n}{\PYGZus{}} \PYG{o}{=} \PYG{n}{split\PYGZus{}filename}\PYG{p}{(}\PYG{n}{fname}\PYG{p}{)}
        \PYG{n}{nb}\PYG{o}{.}\PYG{n}{save}\PYG{p}{(}\PYG{n}{new\PYGZus{}img}\PYG{p}{,} \PYG{n}{base} \PYG{o}{+} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}thresholded.nii}\PYG{l+s}{'}\PYG{p}{)}

        \PYG{k}{return} \PYG{n}{runtime}

    \PYG{k}{def} \PYG{n+nf}{\PYGZus{}list\PYGZus{}outputs}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
        \PYG{n}{outputs} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}outputs}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{get}\PYG{p}{(}\PYG{p}{)}
        \PYG{n}{fname} \PYG{o}{=} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{volume}
        \PYG{n}{\PYGZus{}}\PYG{p}{,} \PYG{n}{base}\PYG{p}{,} \PYG{n}{\PYGZus{}} \PYG{o}{=} \PYG{n}{split\PYGZus{}filename}\PYG{p}{(}\PYG{n}{fname}\PYG{p}{)}
        \PYG{n}{outputs}\PYG{p}{[}\PYG{l+s}{"}\PYG{l+s}{thresholded\PYGZus{}volume}\PYG{l+s}{"}\PYG{p}{]} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{abspath}\PYG{p}{(}\PYG{n}{base} \PYG{o}{+} \PYG{l+s}{'}\PYG{l+s}{\PYGZus{}thresholded.nii}\PYG{l+s}{'}\PYG{p}{)}
        \PYG{k}{return} \PYG{n}{outputs}
\end{Verbatim}


\section{Working with \emph{nipype} source code}
\label{devel/gitwash/index:using-git}\label{devel/gitwash/index:working-with-nipype-source-code}\label{devel/gitwash/index::doc}
Contents:


\subsection{Introduction}
\label{devel/gitwash/git_intro:introduction}\label{devel/gitwash/git_intro::doc}
These pages describe a \href{http://git-scm.com/}{git} and \href{http://github.com}{github} workflow for the \href{http://nipy.org/nipype}{nipype}
project.

There are several different workflows here, for different ways of
working with \emph{nipype}.

This is not a comprehensive \href{http://git-scm.com/}{git} reference, it's just a workflow for our
own project.  It's tailored to the \href{http://github.com}{github} hosting service. You may well
find better or quicker ways of getting stuff done with \href{http://git-scm.com/}{git}, but these
should get you started.

For general resources for learning \href{http://git-scm.com/}{git} see {\hyperref[devel/gitwash/git_resources:git-resources]{\emph{git resources}}}.


\subsection{Install git}
\label{devel/gitwash/git_install::doc}\label{devel/gitwash/git_install:install-git}\label{devel/gitwash/git_install:id1}

\subsubsection{Overview}
\label{devel/gitwash/git_install:overview}
\begin{tabulary}{\linewidth}{|L|L|}
\hline

Debian / Ubuntu
 & 
\code{sudo apt-get install git-core}
\\

Fedora
 & 
\code{sudo yum install git-core}
\\

Windows
 & 
Download and install \href{http://code.google.com/p/msysgit/downloads/list}{msysGit}
\\

OS X
 & 
Use the \href{http://code.google.com/p/git-osx-installer/downloads/list}{git-osx-installer}
\\
\hline
\end{tabulary}



\subsubsection{In detail}
\label{devel/gitwash/git_install:in-detail}
See the \href{http://git-scm.com/}{git} page for the most recent information.

Have a look at the \href{http://github.com}{github} install help pages available from \href{http://help.github.com}{github help}

There are good instructions here: \href{http://book.git-scm.com/2\_installing\_git.html}{http://book.git-scm.com/2\_installing\_git.html}


\subsection{Following the latest source}
\label{devel/gitwash/following_latest:following-the-latest-source}\label{devel/gitwash/following_latest:following-latest}\label{devel/gitwash/following_latest::doc}
These are the instructions if you just want to follow the latest
\emph{nipype} source, but you don't need to do any development for now.

The steps are:
\begin{itemize}
\item {} 
{\hyperref[devel/gitwash/git_install:install-git]{\emph{Install git}}}

\item {} 
get local copy of the git repository from \href{http://github.com}{github}

\item {} 
update local copy from time to time

\end{itemize}


\subsubsection{Get the local copy of the code}
\label{devel/gitwash/following_latest:get-the-local-copy-of-the-code}
From the command line:

\begin{Verbatim}[commandchars=@\[\]]
git clone git://github.com/nipy/nipype.git
\end{Verbatim}

You now have a copy of the code tree in the new \code{nipype} directory.


\subsubsection{Updating the code}
\label{devel/gitwash/following_latest:updating-the-code}
From time to time you may want to pull down the latest code.  Do this with:

\begin{Verbatim}[commandchars=@\[\]]
cd nipype
git pull
\end{Verbatim}

The tree in \code{nipype} will now have the latest changes from the initial
repository.


\subsection{Making a patch}
\label{devel/gitwash/patching::doc}\label{devel/gitwash/patching:making-a-patch}
You've discovered a bug or something else you want to change
in \href{http://nipy.org/nipype}{nipype} .. — excellent!

You've worked out a way to fix it — even better!

You want to tell us about it — best of all!

The easiest way is to make a \emph{patch} or set of patches.  Here
we explain how.  Making a patch is the simplest and quickest,
but if you're going to be doing anything more than simple
quick things, please consider following the
{\hyperref[devel/gitwash/git_development:git-development]{\emph{Git for development}}} model instead.


\subsubsection{Making patches}
\label{devel/gitwash/patching:making-patches}\label{devel/gitwash/patching:id1}

\paragraph{Overview}
\label{devel/gitwash/patching:overview}
\begin{Verbatim}[commandchars=@\[\]]
@# tell git who you are
git config --global user.email you@PYGZat[]yourdomain.example.com
git config --global user.name "Your Name Comes Here"
@# get the repository if you don't have it
git clone git://github.com/nipy/nipype.git
@# make a branch for your patching
cd nipype
git branch the-fix-im-thinking-of
git checkout the-fix-im-thinking-of
@# hack, hack, hack
@# Tell git about any new files you've made
git add somewhere/tests/test@_my@_bug.py
@# commit work in progress as you go
git commit -am 'BF - added tests for Funny bug'
@# hack hack, hack
git commit -am 'BF - added fix for Funny bug'
@# make the patch files
git format-patch -M -C master
\end{Verbatim}

Then, send the generated patch files to the \href{http://mail.scipy.org/mailman/listinfo/nipy-devel}{nipype
mailing list} — where we will thank you warmly.


\paragraph{In detail}
\label{devel/gitwash/patching:in-detail}\begin{enumerate}
\item {} 
Tell \href{http://git-scm.com/}{git} who you are so it can label the commits you've
made:

\begin{Verbatim}[commandchars=@\[\]]
git config --global user.email you@PYGZat[]yourdomain.example.com
git config --global user.name "Your Name Comes Here"
\end{Verbatim}

\item {} 
If you don't already have one, clone a copy of the
\href{http://nipy.org/nipype}{nipype} repository:

\begin{Verbatim}[commandchars=@\[\]]
git clone git://github.com/nipy/nipype.git
cd nipype
\end{Verbatim}

\item {} 
Make a `feature branch'.  This will be where you work on
your bug fix.  It's nice and safe and leaves you with
access to an unmodified copy of the code in the main
branch:

\begin{Verbatim}[commandchars=@\[\]]
git branch the-fix-im-thinking-of
git checkout the-fix-im-thinking-of
\end{Verbatim}

\item {} 
Do some edits, and commit them as you go:

\begin{Verbatim}[commandchars=@\[\]]
@# hack, hack, hack
@# Tell git about any new files you've made
git add somewhere/tests/test@_my@_bug.py
@# commit work in progress as you go
git commit -am 'BF - added tests for Funny bug'
@# hack hack, hack
git commit -am 'BF - added fix for Funny bug'
\end{Verbatim}

Note the \code{-am} options to \code{commit}. The \code{m} flag just
signals that you're going to type a message on the command
line.  The \code{a} flag — you can just take on faith —
or see \href{http://www.gitready.com/beginner/2009/01/18/the-staging-area.html}{why the -a flag?}.

\item {} 
When you have finished, check you have committed all your
changes:

\begin{Verbatim}[commandchars=@\[\]]
git status
\end{Verbatim}

\item {} 
Finally, make your commits into patches.  You want all the
commits since you branched from the \code{master} branch:

\begin{Verbatim}[commandchars=@\[\]]
git format-patch -M -C master
\end{Verbatim}

You will now have several files named for the commits:

\begin{Verbatim}[commandchars=@\[\]]
0001-BF-added-tests-for-Funny-bug.patch
0002-BF-added-fix-for-Funny-bug.patch
\end{Verbatim}

Send these files to the \href{http://mail.scipy.org/mailman/listinfo/nipy-devel}{nipype mailing list}.

\end{enumerate}

When you are done, to switch back to the main copy of the
code, just return to the \code{master} branch:

\begin{Verbatim}[commandchars=@\[\]]
git checkout master
\end{Verbatim}


\subsubsection{Moving from patching to development}
\label{devel/gitwash/patching:moving-from-patching-to-development}
If you find you have done some patches, and you have one or
more feature branches, you will probably want to switch to
development mode.  You can do this with the repository you
have.

Fork the \href{http://nipy.org/nipype}{nipype} repository on \href{http://github.com}{github} — {\hyperref[devel/gitwash/forking_hell:forking]{\emph{Making your own copy (fork) of nipype}}}.
Then:

\begin{Verbatim}[commandchars=@\[\]]
@# checkout and refresh master branch from main repo
git checkout master
git pull origin master
@# rename pointer to main repository to 'upstream'
git remote rename origin upstream
@# point your repo to default read / write to your fork on github
git remote add origin git@PYGZat[]github.com:your-user-name/nipype.git
@# push up any branches you've made and want to keep
git push origin the-fix-im-thinking-of
\end{Verbatim}

Then you can, if you want, follow the
{\hyperref[devel/gitwash/development_workflow:development-workflow]{\emph{Development workflow}}}.


\subsection{Git for development}
\label{devel/gitwash/git_development:git-development}\label{devel/gitwash/git_development::doc}\label{devel/gitwash/git_development:git-for-development}
Contents:


\subsubsection{Making your own copy (fork) of nipype}
\label{devel/gitwash/forking_hell:forking}\label{devel/gitwash/forking_hell::doc}\label{devel/gitwash/forking_hell:making-your-own-copy-fork-of-nipype}
You need to do this only once.  The instructions here are very similar
to the instructions at \href{http://help.github.com/forking/}{http://help.github.com/forking/} — please see
that page for more detail.  We're repeating some of it here just to give the
specifics for the \href{http://nipy.org/nipype}{nipype} project, and to suggest some default names.


\paragraph{Set up and configure a github account}
\label{devel/gitwash/forking_hell:set-up-and-configure-a-github-account}
If you don't have a \href{http://github.com}{github} account, go to the \href{http://github.com}{github} page, and make one.

You then need to configure your account to allow write access — see
the \code{Generating SSH keys} help on \href{http://help.github.com}{github help}.


\paragraph{Create your own forked copy of nipype}
\label{devel/gitwash/forking_hell:create-your-own-forked-copy-of-nipype}\begin{enumerate}
\item {} 
Log into your \href{http://github.com}{github} account.

\item {} 
Go to the \href{http://nipy.org/nipype}{nipype} github home at \href{http://github.com/nipy/nipype}{nipype github}.

\item {} 
Click on the \emph{fork} button:

\includegraphics{forking_button.png}

Now, after a short pause and some `Hardcore forking action', you
should find yourself at the home page for your own forked copy of \href{http://nipy.org/nipype}{nipype}.

\end{enumerate}


\subsubsection{Set up your fork}
\label{devel/gitwash/set_up_fork:set-up-fork}\label{devel/gitwash/set_up_fork:set-up-your-fork}\label{devel/gitwash/set_up_fork::doc}
First you follow the instructions for {\hyperref[devel/gitwash/forking_hell:forking]{\emph{Making your own copy (fork) of nipype}}}.


\paragraph{Overview}
\label{devel/gitwash/set_up_fork:overview}
\begin{Verbatim}[commandchars=@\[\]]
git clone git@PYGZat[]github.com:your-user-name/nipype.git
cd nipype
git remote add upstream git://github.com/nipy/nipype.git
\end{Verbatim}


\paragraph{In detail}
\label{devel/gitwash/set_up_fork:in-detail}

\subparagraph{Clone your fork}
\label{devel/gitwash/set_up_fork:clone-your-fork}\begin{enumerate}
\item {} 
Clone your fork to the local computer with \code{git clone
git@github.com:your-user-name/nipype.git}

\item {} 
Investigate.  Change directory to your new repo: \code{cd nipype}. Then
\code{git branch -a} to show you all branches.  You'll get something
like:

\begin{Verbatim}[commandchars=@\[\]]
* master
remotes/origin/master
\end{Verbatim}

This tells you that you are currently on the \code{master} branch, and
that you also have a \code{remote} connection to \code{origin/master}.
What remote repository is \code{remote/origin}? Try \code{git remote -v} to
see the URLs for the remote.  They will point to your \href{http://github.com}{github} fork.

Now you want to connect to the upstream \href{http://github.com/nipy/nipype}{nipype github} repository, so
you can merge in changes from trunk.

\end{enumerate}


\subparagraph{Linking your repository to the upstream repo}
\label{devel/gitwash/set_up_fork:linking-to-upstream}\label{devel/gitwash/set_up_fork:linking-your-repository-to-the-upstream-repo}
\begin{Verbatim}[commandchars=@\[\]]
cd nipype
git remote add upstream git://github.com/nipy/nipype.git
\end{Verbatim}

\code{upstream} here is just the arbitrary name we're using to refer to the
main \href{http://nipy.org/nipype}{nipype} repository at \href{http://github.com/nipy/nipype}{nipype github}.

Note that we've used \code{git://} for the URL rather than \code{git@}.  The
\code{git://} URL is read only.  This means we that we can't accidentally
(or deliberately) write to the upstream repo, and we are only going to
use it to merge into our own code.

Just for your own satisfaction, show yourself that you now have a new
`remote', with \code{git remote -v show}, giving you something like:

\begin{Verbatim}[commandchars=@\[\]]
upstream     git://github.com/nipy/nipype.git (fetch)
upstream     git://github.com/nipy/nipype.git (push)
origin       git@PYGZat[]github.com:your-user-name/nipype.git (fetch)
origin       git@PYGZat[]github.com:your-user-name/nipype.git (push)
\end{Verbatim}


\subsubsection{Configure git}
\label{devel/gitwash/configure_git::doc}\label{devel/gitwash/configure_git:configure-git}\label{devel/gitwash/configure_git:id1}

\paragraph{Overview}
\label{devel/gitwash/configure_git:overview}\label{devel/gitwash/configure_git:git-config-basic}
Your personal \href{http://git-scm.com/}{git} configurations are saved in the \code{.gitconfig} file in
your home directory.
Here is an example \code{.gitconfig} file:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]user@PYGZrb[]
        name = Your Name
        email = you@PYGZat[]yourdomain.example.com

@PYGZlb[]alias@PYGZrb[]
        ci = commit -a
        co = checkout
        st = status -a
        stat = status -a
        br = branch
        wdiff = diff --color-words

@PYGZlb[]core@PYGZrb[]
        editor = vim

@PYGZlb[]merge@PYGZrb[]
        summary = true
\end{Verbatim}

You can edit this file directly or you can use the \code{git config -{-}global}
command:

\begin{Verbatim}[commandchars=@\[\]]
git config --global user.name "Your Name"
git config --global user.email you@PYGZat[]yourdomain.example.com
git config --global alias.ci "commit -a"
git config --global alias.co checkout
git config --global alias.st "status -a"
git config --global alias.stat "status -a"
git config --global alias.br branch
git config --global alias.wdiff "diff --color-words"
git config --global core.editor vim
git config --global merge.summary true
\end{Verbatim}

To set up on another computer, you can copy your \code{\textasciitilde{}/.gitconfig} file,
or run the commands above.


\paragraph{In detail}
\label{devel/gitwash/configure_git:in-detail}

\subparagraph{user.name and user.email}
\label{devel/gitwash/configure_git:user-name-and-user-email}
It is good practice to tell \href{http://git-scm.com/}{git} who you are, for labeling any changes
you make to the code.  The simplest way to do this is from the command
line:

\begin{Verbatim}[commandchars=@\[\]]
git config --global user.name "Your Name"
git config --global user.email you@PYGZat[]yourdomain.example.com
\end{Verbatim}

This will write the settings into your git configuration file,  which
should now contain a user section with your name and email:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]user@PYGZrb[]
      name = Your Name
      email = you@PYGZat[]yourdomain.example.com
\end{Verbatim}

Of course you'll need to replace \code{Your Name} and \code{you@yourdomain.example.com}
with your actual name and email address.


\subparagraph{Aliases}
\label{devel/gitwash/configure_git:aliases}
You might well benefit from some aliases to common commands.

For example, you might well want to be able to shorten \code{git checkout}
to \code{git co}.  Or you may want to alias \code{git diff -{-}color-words}
(which gives a nicely formatted output of the diff) to \code{git wdiff}

The following \code{git config -{-}global} commands:

\begin{Verbatim}[commandchars=@\[\]]
git config --global alias.ci "commit -a"
git config --global alias.co checkout
git config --global alias.st "status -a"
git config --global alias.stat "status -a"
git config --global alias.br branch
git config --global alias.wdiff "diff --color-words"
\end{Verbatim}

will create an \code{alias} section in your \code{.gitconfig} file with contents
like this:

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]alias@PYGZrb[]
        ci = commit -a
        co = checkout
        st = status -a
        stat = status -a
        br = branch
        wdiff = diff --color-words
\end{Verbatim}


\subparagraph{Editor}
\label{devel/gitwash/configure_git:editor}
You may also want to make sure that your editor of choice is used

\begin{Verbatim}[commandchars=@\[\]]
git config --global core.editor vim
\end{Verbatim}


\subparagraph{Merging}
\label{devel/gitwash/configure_git:merging}
To enforce summaries when doing merges (\code{\textasciitilde{}/.gitconfig} file again):

\begin{Verbatim}[commandchars=@\[\]]
@PYGZlb[]merge@PYGZrb[]
   log = true
\end{Verbatim}

Or from the command line:

\begin{Verbatim}[commandchars=@\[\]]
git config --global merge.log true
\end{Verbatim}


\subsubsection{Development workflow}
\label{devel/gitwash/development_workflow:id1}\label{devel/gitwash/development_workflow::doc}\label{devel/gitwash/development_workflow:development-workflow}
You already have your own forked copy of the \href{http://nipy.org/nipype}{nipype} repository, by
following {\hyperref[devel/gitwash/forking_hell:forking]{\emph{Making your own copy (fork) of nipype}}}, {\hyperref[devel/gitwash/set_up_fork:set-up-fork]{\emph{Set up your fork}}}, and you have configured
\href{http://git-scm.com/}{git} by following {\hyperref[devel/gitwash/configure_git:configure-git]{\emph{Configure git}}}.


\paragraph{Workflow summary}
\label{devel/gitwash/development_workflow:workflow-summary}\begin{itemize}
\item {} 
Keep your \code{master} branch clean of edits that have not been merged
to the main \href{http://nipy.org/nipype}{nipype} development repo.  Your \code{master} then will follow
the main \href{http://nipy.org/nipype}{nipype} repository.

\item {} 
Start a new \emph{feature branch} for each set of edits that you do.

\item {} 
If you can avoid it, try not to merge other branches into your feature
branch while you are working.

\item {} 
Ask for review!

\end{itemize}

This way of working really helps to keep work well organized, and in
keeping history as clear as possible.

See — for example — \href{http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html}{linux git workflow}.


\paragraph{Making a new feature branch}
\label{devel/gitwash/development_workflow:making-a-new-feature-branch}
\begin{Verbatim}[commandchars=@\[\]]
git branch my-new-feature
git checkout my-new-feature
\end{Verbatim}

Generally, you will want to keep this also on your public \href{http://github.com}{github} fork
of \href{http://nipy.org/nipype}{nipype}.  To do this, you \href{http://www.kernel.org/pub/software/scm/git/docs/git-push.html}{git push} this new branch up to your \href{http://github.com}{github}
repo.  Generally (if you followed the instructions in these pages, and
by default), git will have a link to your \href{http://github.com}{github} repo, called
\code{origin}.  You push up to your own repo on \href{http://github.com}{github} with:

\begin{Verbatim}[commandchars=@\[\]]
git push origin my-new-feature
\end{Verbatim}

In git \textgreater{}1.7 you can ensure that the link is correctly set by using the
\code{-{-}set-upstream} option:

\begin{Verbatim}[commandchars=@\[\]]
git push --set-upstream origin my-new-feature
\end{Verbatim}

From now on \href{http://git-scm.com/}{git} will know that \code{my-new-feature} is related to the
\code{my-new-feature} branch in the \href{http://github.com}{github} repo.


\paragraph{The editing workflow}
\label{devel/gitwash/development_workflow:the-editing-workflow}

\subparagraph{Overview}
\label{devel/gitwash/development_workflow:overview}
\begin{Verbatim}[commandchars=@\[\]]
@# hack hack
git add my@_new@_file
git commit -am 'NF - some message'
git push
\end{Verbatim}


\subparagraph{In more detail}
\label{devel/gitwash/development_workflow:in-more-detail}\begin{enumerate}
\item {} 
Make some changes

\item {} 
See which files have changed with \code{git status} (see \href{http://www.kernel.org/pub/software/scm/git/docs/git-status.html}{git status}).
You'll see a listing like this one:

\begin{Verbatim}[commandchars=@\[\]]
@# On branch ny-new-feature
@# Changed but not updated:
@#   (use "git add @textless[]file@textgreater[]..." to update what will be committed)
@#   (use "git checkout -- @textless[]file@textgreater[]..." to discard changes in working directory)
@#
@#  modified:   README
@#
@# Untracked files:
@#   (use "git add @textless[]file@textgreater[]..." to include in what will be committed)
@#
@#  INSTALL
no changes added to commit (use "git add" and/or "git commit -a")
\end{Verbatim}

\item {} 
Check what the actual changes are with \code{git diff} (\href{http://www.kernel.org/pub/software/scm/git/docs/git-diff.html}{git diff}).

\item {} 
Add any new files to version control \code{git add new\_file\_name} (see
\href{http://www.kernel.org/pub/software/scm/git/docs/git-add.html}{git add}).

\item {} 
To commit all modified files into the local copy of your repo,, do
\code{git commit -am 'A commit message'}.  Note the \code{-am} options to
\code{commit}. The \code{m} flag just signals that you're going to type a
message on the command line.  The \code{a} flag — you can just take on
faith — or see \href{http://www.gitready.com/beginner/2009/01/18/the-staging-area.html}{why the -a flag?} — and the helpful use-case
description in the \href{http://tomayko.com/writings/the-thing-about-git}{tangled working copy problem}. The \href{http://www.kernel.org/pub/software/scm/git/docs/git-commit.html}{git commit} manual
page might also be useful.

\item {} 
To push the changes up to your forked repo on \href{http://github.com}{github}, do a \code{git
push} (see \emph{git push}).

\end{enumerate}


\paragraph{Asking for code review}
\label{devel/gitwash/development_workflow:asking-for-code-review}\begin{enumerate}
\item {} 
Go to your repo URL — e.g. \code{http://github.com/your-user-name/nipype}.

\item {} 
Click on the \emph{Branch list} button:

\includegraphics{branch_list.png}

\item {} 
Click on the \emph{Compare} button for your feature branch — here \code{my-new-feature}:

\includegraphics{branch_list_compare.png}

\item {} 
If asked, select the \emph{base} and \emph{comparison} branch names you want to
compare.  Usually these will be \code{master} and \code{my-new-feature}
(where that is your feature branch name).

\item {} 
At this point you should get a nice summary of the changes.  Copy the
URL for this, and post it to the \href{http://mail.scipy.org/mailman/listinfo/nipy-devel}{nipype mailing list}, asking for
review.  The URL will look something like:
\code{http://github.com/your-user-name/nipype/compare/master...my-new-feature}.
There's an example at
\href{http://github.com/matthew-brett/nipy/compare/master...find-install-data}{http://github.com/matthew-brett/nipy/compare/master...find-install-data}
See: \href{http://github.com/blog/612-introducing-github-compare-view}{http://github.com/blog/612-introducing-github-compare-view} for
more detail.

\end{enumerate}

The generated comparison, is between your feature branch
\code{my-new-feature}, and the place in \code{master} from which you branched
\code{my-new-feature}.  In other words, you can keep updating \code{master}
without interfering with the output from the comparison.  More detail?
Note the three dots in the URL above (\code{master...my-new-feature}).

\begin{notice}{note}{Two vs three dots}

Imagine a series of commits A, B, C, D...  Imagine that there are two
branches, \emph{topic} and \emph{master}.  You branched \emph{topic} off \emph{master} when
\emph{master} was at commit `E'.  The graph of the commits looks like this:

\begin{Verbatim}[commandchars=@\[\]]
      A---B---C topic
      /
D---E---F---G master
\end{Verbatim}

Then:

\begin{Verbatim}[commandchars=@\[\]]
git diff master..topic
\end{Verbatim}

will output the difference from G to C (i.e. with effects of F and G),
while:

\begin{Verbatim}[commandchars=@\[\]]
git diff master...topic
\end{Verbatim}

would output just differences in the topic branch (i.e. only A, B, and
C). \footnote{
Thanks to Yarik Halchenko for this explanation.
}
\end{notice}


\paragraph{Asking for your changes to be merged with the main repo}
\label{devel/gitwash/development_workflow:asking-for-your-changes-to-be-merged-with-the-main-repo}
When you are ready to ask for the merge of your code:
\begin{enumerate}
\item {} 
Go to the URL of your forked repo, say
\code{http://github.com/your-user-name/nipype.git}.

\item {} 
Click on the `Pull request' button:

\includegraphics{pull_button.png}

Enter a message; we suggest you select only \code{nipype} as the
recipient.  The message will go to the \href{http://mail.scipy.org/mailman/listinfo/nipy-devel}{nipype mailing list}.  Please
feel free to add others from the list as you like.

\end{enumerate}


\paragraph{Merging from trunk}
\label{devel/gitwash/development_workflow:merging-from-trunk}
This updates your code from the upstream \href{http://github.com/nipy/nipype}{nipype github}  repo.


\subparagraph{Overview}
\label{devel/gitwash/development_workflow:id3}
\begin{Verbatim}[commandchars=@\[\]]
@# go to your master branch
git checkout master
@# pull changes from github
git fetch upstream
@# merge from upstream
git merge upstream/master
\end{Verbatim}


\subparagraph{In detail}
\label{devel/gitwash/development_workflow:in-detail}
We suggest that you do this only for your \code{master} branch, and leave
your `feature' branches unmerged, to keep their history as clean as
possible.  This makes code review easier:

\begin{Verbatim}[commandchars=@\[\]]
git checkout master
\end{Verbatim}

Make sure you have done {\hyperref[devel/gitwash/set_up_fork:linking-to-upstream]{\emph{Linking your repository to the upstream repo}}}.

Merge the upstream code into your current development by first pulling
the upstream repo to a copy on your local machine:

\begin{Verbatim}[commandchars=@\[\]]
git fetch upstream
\end{Verbatim}

then merging into your current branch:

\begin{Verbatim}[commandchars=@\[\]]
git merge upstream/master
\end{Verbatim}


\paragraph{Deleting a branch on github}
\label{devel/gitwash/development_workflow:deleting-a-branch-on-github}
\begin{Verbatim}[commandchars=@\[\]]
git checkout master
@# delete branch locally
git branch -D my-unwanted-branch
@# delete branch on github
git push origin :my-unwanted-branch
\end{Verbatim}

(Note the colon \code{:} before \code{test-branch}.  See also:
\href{http://github.com/guides/remove-a-remote-branch}{http://github.com/guides/remove-a-remote-branch}


\paragraph{Several people sharing a single repository}
\label{devel/gitwash/development_workflow:several-people-sharing-a-single-repository}
If you want to work on some stuff with other people, where you are all
committing into the same repository, or even the same branch, then just
share it via \href{http://github.com}{github}.

First fork nipype into your account, as from {\hyperref[devel/gitwash/forking_hell:forking]{\emph{Making your own copy (fork) of nipype}}}.

Then, go to your forked repository github page, say
\code{http://github.com/your-user-name/nipype}

Click on the `Admin' button, and add anyone else to the repo as a
collaborator:
\begin{quote}

\includegraphics{pull_button.png}
\end{quote}

Now all those people can do:

\begin{Verbatim}[commandchars=@\[\]]
git clone git@PYGZat[]githhub.com:your-user-name/nipype.git
\end{Verbatim}

Remember that links starting with \code{git@} use the ssh protocol and are
read-write; links starting with \code{git://} are read-only.

Your collaborators can then commit directly into that repo with the
usual:

\begin{Verbatim}[commandchars=@\[\]]
git commit -am 'ENH - much better code'
git push origin master @# pushes directly into your repo
\end{Verbatim}


\paragraph{Exploring your repository}
\label{devel/gitwash/development_workflow:exploring-your-repository}
To see a graphical representation of the repository branches and
commits:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{gitk} \PYG{o}{-}\PYG{o}{-}\PYG{n+nb}{all}
\end{Verbatim}

To see a linear list of commits for this branch:

\begin{Verbatim}[commandchars=@\[\]]
git log
\end{Verbatim}

You can also look at the \href{http://github.com/blog/39-say-hello-to-the-network-graph-visualizer}{network graph visualizer} for your \href{http://github.com}{github}
repo.


\subsection{git resources}
\label{devel/gitwash/git_resources::doc}\label{devel/gitwash/git_resources:git-resources}\label{devel/gitwash/git_resources:id1}

\subsubsection{Tutorials and summaries}
\label{devel/gitwash/git_resources:tutorials-and-summaries}\begin{itemize}
\item {} 
\href{http://help.github.com}{github help} has an excellent series of how-to guides.

\item {} 
\href{http://learn.github.com/}{learn.github} has an excellent series of tutorials

\item {} 
The \href{http://progit.org/}{pro git book} is a good in-depth book on git.

\item {} 
A \href{http://github.com/guides/git-cheat-sheet}{git cheat sheet} is a page giving summaries of common commands.

\item {} 
The \href{http://www.kernel.org/pub/software/scm/git/docs/user-manual.html}{git user manual}

\item {} 
The \href{http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html}{git tutorial}

\item {} 
The \href{http://book.git-scm.com/}{git community book}

\item {} 
\href{http://www.gitready.com/}{git ready} — a nice series of tutorials

\item {} 
\href{http://www.gitcasts.com/}{git casts} — video snippets giving git how-tos.

\item {} 
\href{http://www-cs-students.stanford.edu/~blynn/gitmagic/index.html}{git magic} — extended introduction with intermediate detail

\item {} 
The \href{http://tom.preston-werner.com/2009/05/19/the-git-parable.html}{git parable} is an easy read explaining the concepts behind git.

\item {} 
Our own \href{http://matthew-brett.github.com/pydagogue/foundation.html}{git foundation} expands on the \href{http://tom.preston-werner.com/2009/05/19/the-git-parable.html}{git parable}.

\item {} 
Fernando Perez' git page — \href{http://www.fperez.org/py4science/git.html}{Fernando's git page} — many
links and tips

\item {} 
A good but technical page on \href{http://www.eecs.harvard.edu/~cduan/technical/git/}{git concepts}

\item {} 
\href{http://git-scm.com/course/svn.html}{git svn crash course}: \href{http://git-scm.com/}{git} for those of us used to \href{http://subversion.tigris.org/}{subversion}

\end{itemize}


\subsubsection{Advanced git workflow}
\label{devel/gitwash/git_resources:advanced-git-workflow}
There are many ways of working with \href{http://git-scm.com/}{git}; here are some posts on the
rules of thumb that other projects have come up with:
\begin{itemize}
\item {} 
Linus Torvalds on \href{http://kerneltrap.org/Linux/Git\_Management}{git management}

\item {} 
Linus Torvalds on \href{http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html}{linux git workflow} .  Summary; use the git tools
to make the history of your edits as clean as possible; merge from
upstream edits as little as possible in branches where you are doing
active development.

\end{itemize}


\subsubsection{Manual pages online}
\label{devel/gitwash/git_resources:manual-pages-online}
You can get these on your own machine with (e.g) \code{git help push} or
(same thing) \code{git push -{-}help}, but, for convenience, here are the
online manual pages for some common commands:
\begin{itemize}
\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-add.html}{git add}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-branch.html}{git branch}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html}{git checkout}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-clone.html}{git clone}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-commit.html}{git commit}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-config.html}{git config}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-diff.html}{git diff}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-log.html}{git log}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-pull.html}{git pull}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-push.html}{git push}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-remote.html}{git remote}

\item {} 
\href{http://www.kernel.org/pub/software/scm/git/docs/git-status.html}{git status}

\end{itemize}


\section{Architecture (discussions from 2009)}
\label{devel/architecture:architecture-discussions-from-2009}\label{devel/architecture::doc}
This section reflects notes and discussion between developers during the
start of the nipype project in 2009.


\subsection{Design Guidelines}
\label{devel/architecture:design-guidelines}
These are guidelines that the core nipype developers have agreed on:

Interfaces should keep all parameters affecting construction of the
appropriate command in the ``input'' bunch.

The .run() method of an Interface should include all required inputs
as explicitly named parameters, and they should take a default value
of None.

Any Interface should at a minimum support cwd as a command-line
argument to .run(). This may be accomplished by allowing cwd as an
element of the input Bunch, or handled as a separate case.

Relatedly, any Interface should output all files to cwd if it is set,
and otherwise to os.getcwd() (or equivalent).

We need to decide on a consistent policy towards the maintinence of
paths to files. It seems like the best strategy might be to do
absolute (os.realpath?)  filenames by default, allowing for relative
paths by explicitly including something that doesn't start with a
`/'. This could include `.' in some sort of path-spec.

Class attributes should never be modified by an instance of that class. And
probably not ever.


\subsection{Providing for Provenance}
\label{devel/architecture:providing-for-provenance}
The following is a specific discussion that should be thought out an more
generally applied to the way we handle auto-generation / or ``sourcing'' of
settings in an interface.

There are two possible sources (at a minimum) from which the interface instance could obtain ``outputtype'' - itself, or FSLInfo. Currently, the outputtype gets read from FSLInfo if self.outputtype (er, \_outputtype?) is None.

In the case of other opt\_map specifications, there are defaults that get specified if the value is None. For example output filenames are often auto-generated. If you look at the code for fsl.Bet for example, there is no way for the outfile to get picked up at the pipeline level, because it is a transient variable. This is OK, as the generation of the outfile name is contingent ONLY on inputs which ARE available to the pipeline machinery (i.e., via inspection of the Bet instance's attributes).

However, with outputtype, we are in a situation in which ``autogeneration'' incorporates potentially transient information external to the instance itself. Thus, some care needs to be taken in always ensuring this information is hashable.


\subsection{Design Principles}
\label{devel/architecture:design-principles}
These are (currently) Dav Clark's best guess at what the group might agree on:

It should be very easy to figure out what was done by the pypeline.

Code should support relocatability - this could be via URIs, relative
paths or potentially other mechanisms.

Unless otherwise called for, code should be thread safe, just in case.

The pipeline should make it easy to change aspects of an analysis with
minimal recomputation, downloading, etc. (This is not the case
currently - any change will overwrite the old node). Also, the fact
that multiple files get rolled into a single node is problematic for
similar reasons. E.g. - node({[}file1 ...  file100{]}) will get recomputed
if we add only one file!.

However, it should also be easy to identify and delete things you
don't need anymore.

Pipelines and bits of pipelines should be easy to share.

Things that are the same should be called the same thing in most
places. For interfaces that have an obvious meaning for the terms,
``infiles'' and ``outfile(s)''. If a file is in both the inputs and
outputs, it should be called the same thing in both places. If it is
produced by one interface and consumed by another, same thing should
be used.


\subsection{Discussions}
\label{devel/architecture:discussions}

\subsubsection{Auto-generated filenames}
\label{devel/filename_generation:auto-generated-filenames}\label{devel/filename_generation::doc}
In refactoring the inputs in the traitlets branch I'm working through
the different ways that filenames are generated and want to make sure
the interface is consistent.  The notes below are all using fsl.Bet as
that's the first class we're Traiting. Other interface classes may
handle this differently, but should agree on a convention and apply it
across all Interfaces (if possible).


\paragraph{Current Rules}
\label{devel/filename_generation:current-rules}
These rules are for fsl.Bet, but it appears they are the same for all
fsl and spm Interfaces.

Bet has two mandatory parameters, \code{infile} and \code{outfile}.  These
are the rules for how they are handled in different use cases.
\begin{enumerate}
\item {} 
If \code{infile} or \code{outfile} are absolute paths, they are used
as-is and never changed.  This allows users to override any
filename/path generation.

\item {} 
If \code{outfile} is not specified, a filename is generated.

\item {} 
Generated filenames (at least for \code{outfile}) are based on:

\end{enumerate}
\begin{itemize}
\item {} 
\code{infile}, the filename minus the extensions.

\item {} 
A suffix specified by the Interface. For example Bet uses
\emph{\_brain} suffix.

\item {} 
The current working directory, os.getcwd().  Example:

If \code{infile} == `foo.nii' and the cwd is \code{/home/cburns} then
generated \code{outfile} for Bet will be
\code{/home/cburns/foo\_brain.nii.gz}

\end{itemize}
\begin{enumerate}
\setcounter{enumi}{3}
\item {} 
If \code{outfile} is not an absolute path, for instance just a
filename, the absolute path is generated using
\code{os.path.realpath}. This absolute path is needed to make sure the
packages (Bet in this case) write the output file to a location of
our choosing.  The generated absolute path is only used in the
\code{cmdline} at runtime and does \_\_not\_\_ overwrite the class attr
\code{self.inputs.outfile}.  It is generated only when the \code{cmdline}
is invoked.

\end{enumerate}


\paragraph{Walking through some examples}
\label{devel/filename_generation:walking-through-some-examples}
In this example we assign \code{infile} directly but \code{outfile} is
generated in \code{Bet.\_parse\_inputs} based on \code{infile}.  The generated
\code{outfile} is only used in the cmdline at runtime and not stored in
\code{self.inputs.outfile}.  This seems correct.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [15]: }\PYG{k+kn}{from} \PYG{n+nn}{nipype.interfaces} \PYG{k+kn}{import} \PYG{n}{fsl}

\PYG{g+gp}{In [16]: }\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [17]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile} \PYG{o}{=} \PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [18]: }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [19]: }\PYG{n}{res}\PYG{o}{.}\PYG{n}{runtime}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[19]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/foo\PYGZus{}brain.nii.gz}\PYG{l+s}{'}

\PYG{g+gp}{In [21]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}
\PYG{g+go}{Out[21]: }\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{center}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{flags}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{frac}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{functional}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
\PYG{g+go}{infile='foo.nii', mask=None, mesh=None, nooutput=None, outfile=None,}
\PYG{g+go}{outline=None, radius=None, reduce\PYGZus{}bias=None, skull=None, threshold=None,}
\PYG{g+go}{verbose=None, vertical\PYGZus{}gradient=None)}

\PYG{g+gp}{In [24]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[24]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/foo\PYGZus{}brain.nii.gz}\PYG{l+s}{'}

\PYG{g+gp}{In [25]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}

\PYG{g+gp}{In [26]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile}
\PYG{g+go}{Out[26]: }\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}
\end{Verbatim}

We get the same behavior here when we assign \code{infile} at initialization:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [28]: }\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{n}{infile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{)}

\PYG{g+gp}{In [29]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[29]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/foo\PYGZus{}brain.nii.gz}\PYG{l+s}{'}

\PYG{g+gp}{In [30]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}
\PYG{g+go}{Out[30]: }\PYG{n}{Bunch}\PYG{p}{(}\PYG{n}{center}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{flags}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{frac}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{n}{functional}\PYG{o}{=}\PYG{n+nb+bp}{None}\PYG{p}{,}
\PYG{g+go}{infile='foo.nii', mask=None, mesh=None, nooutput=None, outfile=None,}
\PYG{g+go}{outline=None, radius=None, reduce\PYGZus{}bias=None, skull=None, threshold=None,}
\PYG{g+go}{verbose=None, vertical\PYGZus{}gradient=None)}

\PYG{g+gp}{In [31]: }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [32]: }\PYG{n}{res}\PYG{o}{.}\PYG{n}{runtime}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[32]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/foo\PYGZus{}brain.nii.gz}\PYG{l+s}{'}
\end{Verbatim}

Here we specify absolute paths for both \code{infile} and
\code{outfile}. The command line's look as expected:

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [53]: }\PYG{k+kn}{import} \PYG{n+nn}{os}

\PYG{g+gp}{In [54]: }\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [55]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{infile} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/Users/cburns/tmp/junk}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{)}
\PYG{g+gp}{In [56]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/Users/cburns/tmp/junk}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{)}

\PYG{g+gp}{In [57]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[57]: }\PYG{l+s}{'}\PYG{l+s}{bet /Users/cburns/tmp/junk/foo.nii /Users/cburns/tmp/junk/bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [58]: }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [59]: }\PYG{n}{res}\PYG{o}{.}\PYG{n}{runtime}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[59]: }\PYG{l+s}{'}\PYG{l+s}{bet /Users/cburns/tmp/junk/foo.nii /Users/cburns/tmp/junk/bar.nii}\PYG{l+s}{'}
\end{Verbatim}

Here passing in a new \code{outfile} in the \code{run} method will update
\code{mybet.inputs.outfile} to the passed in value.  Should this be the
case?

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [110]: }\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{n}{infile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{outfile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{)}

\PYG{g+gp}{In [111]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}
\PYG{g+go}{Out[111]: }\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [112]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[112]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [113]: }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{outfile} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{path}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{l+s}{'}\PYG{l+s}{/Users/cburns/tmp/junk}\PYG{l+s}{'}\PYG{p}{,} \PYG{l+s}{'}\PYG{l+s}{not\PYGZus{}bar.nii}\PYG{l+s}{'}\PYG{p}{)}\PYG{p}{)}

\PYG{g+gp}{In [114]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}
\PYG{g+go}{Out[114]: }\PYG{l+s}{'}\PYG{l+s}{/Users/cburns/tmp/junk/not\PYGZus{}bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [115]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[115]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/tmp/junk/not\PYGZus{}bar.nii}\PYG{l+s}{'}
\end{Verbatim}

In this case we provide \code{outfile} but not as an absolue path, so the
absolue path is generated and used for the \code{cmdline} when run, but
\code{mybet.inputs.outfile} is not updated with the absolute path.

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{In [74]: }\PYG{n}{mybet} \PYG{o}{=} \PYG{n}{fsl}\PYG{o}{.}\PYG{n}{Bet}\PYG{p}{(}\PYG{n}{infile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{foo.nii}\PYG{l+s}{'}\PYG{p}{,} \PYG{n}{outfile}\PYG{o}{=}\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}\PYG{p}{)}

\PYG{g+gp}{In [75]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}
\PYG{g+go}{Out[75]: }\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [76]: }\PYG{n}{mybet}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[76]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [77]: }\PYG{n}{res} \PYG{o}{=} \PYG{n}{mybet}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{p}{)}

\PYG{g+gp}{In [78]: }\PYG{n}{res}\PYG{o}{.}\PYG{n}{runtime}\PYG{o}{.}\PYG{n}{cmdline}
\PYG{g+go}{Out[78]: }\PYG{l+s}{'}\PYG{l+s}{bet foo.nii /Users/cburns/src/nipy-sf/nipype/trunk/nipype/interfaces/tests/bar.nii}\PYG{l+s}{'}

\PYG{g+gp}{In [80]: }\PYG{n}{res}\PYG{o}{.}\PYG{n}{interface}\PYG{o}{.}\PYG{n}{inputs}\PYG{o}{.}\PYG{n}{outfile}
\PYG{g+go}{Out[80]: }\PYG{l+s}{'}\PYG{l+s}{bar.nii}\PYG{l+s}{'}
\end{Verbatim}


\chapter{Changes in Nipype}
\label{changes:changes-in-nipype}\label{changes:changes}\label{changes::doc}\label{changes:wikipedia-pca}

\section{Release 0.4 (FUTURE)}
\label{changes:release-0-4-future}\begin{itemize}
\item {} \begin{description}
\item[{API: Workflow run function no longer supports (inseries, createdirsonly).}] \leavevmode
Functions used in connect string must be pickleable

\end{description}

\item {} 
API: SPM EstimateContrast: ignore\_derivs replaced by use\_derivs

\item {} 
API: All interfaces: added new config option ignore\_exception

\item {} \begin{description}
\item[{API: SpecifModel no longer supports (concatenate\_runs, output\_specs). high\_pass\_filter}] \leavevmode
cutoff is mandatory (even if its set to np.inf). Additional interfaces
SpecifySPMModel and SpecifySparseModel support other types of data.

\end{description}

\item {} 
API: fsl.DTIFit input ``save'' is now called ``save\_tensor''

\item {} \begin{description}
\item[{API: All inputs of IdentityInterfaces are mandatory by default. You can turn}] \leavevmode
this off by specifying mandatory\_inputs=False to the constructor.

\end{description}

\item {} 
API: fsl FILMGLS input ``autocorr\_estimate'' is now called ``autocorr\_estimate\_only''

\item {} \begin{description}
\item[{API: fsl ContrastMgr now requires access to specific files (no longer accepts}] \leavevmode
the result directory)

\end{description}

\item {} 
ENH: All commandline interfaces display stdout and stderr

\item {} 
ENH: All interfaces raise exceptions on error with an option to suppress

\item {} \begin{description}
\item[{ENH: Supports a plugin interface for execution (current support for multiprocessing,}] \leavevmode
IPython, SGE)

\end{description}

\item {} 
ENH: MapNode runs in parallel under IPython, SGE, MultiProc

\item {} 
ENH: Optionally allows keeping only required outputs

\item {} \begin{description}
\item[{ENH: New interface: utility.Rename to change the name of files, optionally}] \leavevmode
using python string-formatting with inputs or regular expressions matching

\end{description}

\item {} 
ENH: New interface: freesurfer.ApplyMask (mri\_mask)

\item {} 
ENH: New FSL interface -- SwapDimensions (fslswapdim)

\item {} 
ENH: Sparse models allow regressor scaling and temporal derivatives

\item {} \begin{description}
\item[{ENH: Added support for the component parts of FSL's TBSS workflow (TBSSSkeleton}] \leavevmode
and DistanceMap)

\end{description}

\item {} 
ENH: dcm2nii interface exposes bvals, bvecs, reoriented and cropped images

\item {} \begin{description}
\item[{ENH: Added several higher-level interfaces to the fslmaths command:}] \leavevmode\begin{itemize}
\item {} 
ChangeDataType, Threshold, MeanImage, IsotropicSmooth, ApplyMask, TemporalFilter
DilateImage, ErodeImage, SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths

\end{itemize}

\end{description}

\item {} 
ENH: added support for networx 1.4 and improved iterable expansion

\item {} 
ENH: Replaced BEDPOSTX and EddyCurrent with nipype pipelines

\item {} 
ENH: Ability to create a hierarchical dot file

\item {} 
ENH: Improved debugging information for rerunning nodes

\item {} 
ENH: Added `stop\_on\_first\_rerun' option

\item {} 
BF: dcm2nii interface handles gzipped files correctly

\item {} 
BF: FNIRT generates proper outputs

\item {} 
BF: fsl.DTIFit now properly collects tensor volume

\item {} 
BF: updatehash now removes old result hash file

\end{itemize}


\section{Release 0.3.4 (Jan 12, 2011)}
\label{changes:release-0-3-4-jan-12-2011}\begin{itemize}
\item {} 
API: hash values for float use a string conversion up to the 10th decimal place.

\item {} 
API: Iterables in output path will always be generated as \_var1\_val1\_var2\_val2 pairs

\item {} 
ENH: Added support to nipy: GLM fit, contrast estimation and calculating mask from EPI

\item {} \begin{description}
\item[{ENH: Added support for manipulating surface files in Freesurfer:}] \leavevmode\begin{itemize}
\item {} 
projecting volume images onto the surface

\item {} 
smoothing along the surface

\item {} 
transforming a surface image from one subject to another

\item {} 
using tksurfer to save pictures of the surface

\end{itemize}

\end{description}

\item {} 
ENH: Added support for flash processing using FreeSurfer

\item {} 
ENH: Added support for flirt matrix in BBRegister

\item {} 
ENH: Added support for FSL convert\_xfm

\item {} 
ENH: hashes can be updated again without rerunning all nodes.

\item {} 
ENH: Added multiple regression design for FSL

\item {} 
ENH: Added SPM based Analyze to Nifti converter

\item {} 
ENH: Added increased support for PyXNAT

\item {} 
ENH: Added support for MCR-based binary version of SPM

\item {} 
ENH: Added SPM node for calculating various threshold statistics

\item {} 
ENH: Added distance and dissimilarity measurements

\item {} 
BF: Diffusion toolkit gets installed

\item {} \begin{description}
\item[{BF: Changed FNIRT interface to accept flexible lists (rather than 4-tuples)}] \leavevmode
on all options specific to different subsampling levels

\end{description}

\end{itemize}


\section{Release 0.3.3 (Sep 16, 2010)}
\label{changes:release-0-3-3-sep-16-2010}\begin{itemize}
\item {} 
API: subject\_id in ModelSpec is now deprecated

\item {} 
API: spm.Threshold
- does not need mask, beta, RPV anymore
- takes only one image (stat\_image - mind the name change)
- works with SPM2 SPM.mat
- returns additional map - pre topological FDR

\item {} 
ENH: Added support for Diffusion toolkit

\item {} 
ENH: Added support for FSL slicer and overlay

\item {} 
ENH: Added support for dcm2nii

\item {} 
BF: DataSink properly handles lists of lists now

\item {} 
BF: DataGrabber has option for raising Exception on getting empty lists

\item {} 
BF: Traits logic for `requires' metadata

\item {} 
BF: allows workflows to be relocatable

\item {} 
BF: nested workflows with connections don't raise connection not found error

\item {} 
BF: multiple workflows with identical nodenames and iterables do not create nestsed workflows

\end{itemize}


\section{Release 0.3.2 (Aug 03, 2010)}
\label{changes:release-0-3-2-aug-03-2010}

\subsection{Enhancements}
\label{changes:enhancements}\begin{itemize}
\item {} 
all outputs from nodes are now pickled as part of workflow processing

\item {} 
added git developer docs

\end{itemize}


\subsection{Bugs fixed}
\label{changes:bugs-fixed}\begin{itemize}
\item {} 
FreeSurfer
\begin{itemize}
\item {} 
Fixed bugs in SegStats doctest

\end{itemize}

\end{itemize}


\section{Release 0.3.1 (Jul 29, 2010)}
\label{changes:release-0-3-1-jul-29-2010}

\subsection{Bugs fixed}
\label{changes:id1}\begin{itemize}
\item {} 
FreeSurfer
\begin{itemize}
\item {} 
Fixed bugs in glmfit and concatenate

\item {} 
Added group t-test to freesurfer tutorial

\end{itemize}

\end{itemize}


\section{Release 0.3 (Jul 27, 2010)}
\label{changes:release-0-3-jul-27-2010}

\subsection{Incompatible changes}
\label{changes:incompatible-changes}\begin{itemize}
\item {} 
Complete redesign of the Interface class - heavy use of Traits.

\item {} 
Changes in the engine API - added Workflow and MapNode. Compulsory name argument.

\end{itemize}


\subsection{Features added}
\label{changes:features-added}\begin{itemize}
\item {} 
General:
\begin{itemize}
\item {} 
Type checking of inputs and outputs using Traits from \href{http://code.enthought.com/projects/tool-suite.php}{ETS}.

\item {} 
Support for nested workflows.

\item {} 
Preliminary Slicer and AFNI support.

\item {} 
New flexible DataGrabber node.

\item {} 
AtlasPick and Threshold nodes.

\item {} 
Preliminary support for XNAT.

\item {} 
Doubled number of the tutorials.

\end{itemize}

\item {} 
FSL:
\begin{itemize}
\item {} 
Added DTI processing nodes (note that TBSS nodes are still experimental).

\item {} 
Recreated FEAT workflow.

\end{itemize}

\item {} 
SPM:
\begin{itemize}
\item {} 
Added New Segment and many other nodes.

\item {} 
Redesigned second level analysis.

\end{itemize}

\end{itemize}



\renewcommand{\indexname}{Index}
\printindex
\end{document}
