+ - 0:00:00
Notes for current slide
Notes for next slide

Introduction

to Nipype

1 / 16

2 / 16

What is Nipype?

  • open-source, community-developed software package written in Python.

  • Provides unified way of interfacing with heterogeneous neuroimaging software like SPM, FSL, FreeSurfer, AFNI, ANTS, Camino, MRtrix, MNE, Slicer and many more.

  • Allows users to create flexible, complex workflows consisting of multiple processing steps using any software package above

  • Efficient and optimized computation through parallel execution plugins

3 / 16

I don't need that, I'm happy with SPM12!

I mean, there's no problem with SPM's batch system...

ok, ok... it gets tiring to have a separate batch script for each subject and MATLAB license issues are sometimes a pain.

But hey, the nice looking GUI makes it so easy to use!

4 / 16

SPM in Nipype

Using SPM12 with Nipype is simpler than any matlabbatch and it's intuitive to read:

from nipype.interfaces.spm import Smooth
smooth = Smooth()
smooth.inputs.in_files = 'functional.nii'
smooth.inputs.fwhm = 6
smooth.run()
5 / 16

I don't need that, I'm happy with FSL!

The GUI might look a bit old fashion but the command line interface gives me all the flexibility I need!

I don't care that it might be more difficult to learn than other neuroimaging software.

At least it doesn't take me 20 clicks to do simple motion correction.

And once you figure out the underlying commands, it's rather simple to script.

6 / 16

FSL in Nipype

Nipype makes using FSL even easier:

from nipype.interfaces.fsl import MCFLIRT
mcflt = MCFLIRT()
mcflt.inputs.in_file = 'functional.nii'
mcflt.run()

And gives you transparency to what's happening under the hood with one additional line:

In [1]: mcflt.cmdline
Out[1]: 'mcflirt -in functional.nii -out functional_mcf.nii'
7 / 16

I don't need that, I'm happy with FreeSurfer!

You and your problems with fMRI data. I'm perfectly happy with FreeSurfer's command line interface. It gives me all I need to do surface-based analyses.

Of course, you can run your sequential FreeSurfer scripts as you want.

But wouldn't it be nice to optimize computation time by using parallel computation?

8 / 16

FreeSurfer in Nipype

Let's imagine you want to do smoothing on the surface...

  • with two different smoothing kernels values

  • on both hemispheres

  • on six subjects

  • all in parallel?

9 / 16

FreeSurfer in Nipype

Let's imagine you want to do smoothing on the surface...

  • with two different smoothing kernels values

  • on both hemispheres

  • on six subjects

  • all in parallel?

With Nipype this is as simple as that:

from nipype.interfaces.freesurfer import SurfaceSmooth
smoother = SurfaceSmooth()
smoother.inputs.in_file = "{hemi}.func.mgz"
smoother.iterables = [("hemi", ['lh', 'rh']),
("fwhm", [4, 8]),
("subject_id", ['sub01', 'sub02', 'sub03',
'sub04', 'sub05', 'sub06']),
]
smoother.run(mode='parallel')
10 / 16

But I like my neuroimaging toolbox

  • You can keep it! But instead of being stuck in MATLAB with SPM, or having scripting issues with FreeSurfer, ANTs or FSL,..

  • Nipype gives you the possibility to select the algorithms that you prefer from many different software packages.

  • In short, you can have all the advantages without the disadvantage of being stuck with a programming language or software package

11 / 16

A Short Example

Let's assume we want to do preprocessing that uses SPM for motion correction, FreeSurfer for coregistration, ANTS for normalization and FSL for smoothing. Normally this would be a hell of a mess.

It would mean switching between multiple scripts in different programming languages with a lot of manual intervention. Nipype comes to the rescue!

12 / 16

Code Example

The code to create a Nipype workflow like the example before would look something like this:

# Import modules
from nipype.interfaces.freesurfer import BBRegister
from nipype.interfaces.ants import WarpTimeSeriesImageMultiTransform
from nipype.interfaces.fsl import SUSAN
from nipype.interfaces.spm import Realign
# Motion Correction (SPM)
realign = Realign(register_to_mean=True)
# Coregistration (FreeSurfer)
coreg = BBRegister()
# Normalization (ANTS)
normalize = WarpTimeSeriesImageMultiTransform()
# Smoothing (FSL)
smooth = SUSAN(fwhm=6.0)
13 / 16
# Where can the raw data be found?
grabber = nipype.DataGrabber()
grabber.inputs.base_directory = '~/experiment_folder/data'
grabber.inputs.subject_id = ['subject1', 'subject2', 'subject3']
# Where should the output data be stored at?
sink = nipype.DataSink()
sink.inputs.base_directory = '~/experiment_folder/output_folder'
14 / 16
# Where can the raw data be found?
grabber = nipype.DataGrabber()
grabber.inputs.base_directory = '~/experiment_folder/data'
grabber.inputs.subject_id = ['subject1', 'subject2', 'subject3']
# Where should the output data be stored at?
sink = nipype.DataSink()
sink.inputs.base_directory = '~/experiment_folder/output_folder'
# Create a workflow to connect all those nodes
preprocflow = nipype.Workflow()
# Connect the nodes to each other
preprocflow.connect([(grabber -> realign ),
(realign -> coreg ),
(coreg -> normalize),
(normalize -> smooth ),
(smooth -> sink )
])
# Run the workflow in parallel
preprocflow.run(mode='parallel')

Important: This code is a shortened and simplified version of the real Nipype code. But it gives you a good idea of how intuitive it is to use Nipype for your neuroimaging analysis.

15 / 16

So again, what is Nipype?

Nipype consists of many parts, but the main ones are Interfaces, the Workflow Engine and the Execution Plugins:

  • Interface: Wraps a program or function

  • Node/MapNode: Wraps an Interface for use in a Workflow

  • Workflow: A graph or forest of graphs whose edges represent data flow

  • Plugin: A component that describes how a Workflow should be executed

16 / 16

2 / 16
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow