This repository has been archived by the owner on May 26, 2023. It is now read-only.
forked from nipraxis/textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintroducing_nipype.Rmd
113 lines (88 loc) · 2.98 KB
/
introducing_nipype.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
jupyter:
jupytext:
text_representation:
extension: .Rmd
format_name: rmarkdown
format_version: '1.2'
jupytext_version: 1.11.5
---
$\newcommand{L}[1]{\| #1 \|}\newcommand{VL}[1]{\L{ \vec{#1} }}\newcommand{R}[1]{\operatorname{Re}\,(#1)}\newcommand{I}[1]{\operatorname{Im}\, (#1)}$
## Introducing nipype
[Nipype](http://nipy.org/nipype) is a Python module that provides Python interfaces to many imaging
tools, including SPM, AFNI and FSL.
We install it with `pip` in the usual way:
```
pip3 install --user nipype
```
After this has run, check that you can import nipype with:
```{python}
import nipype
```
We are interested in the nipype `interfaces` sub-package. Specifically, we
want the interfaces to the SPM routines:
```{python}
from nipype.interfaces import spm
```
Our first job is to make sure that nipype can run MATLAB. Let’s check with a
test call:
If `nipype` does not have the right command to start MATLAB, this will fail
with an error. We can set the command to start MATLAB like this:
```{python}
nim.MatlabCommand.set_default_matlab_cmd('/Applications/MATLAB_R2014a.app/bin/matlab')
```
where `/Applications/MATLAB_R2014a.app/bin/matlab` is the path to the MATLAB
application file.
Check this is working by running the code above.
Next we need to make sure that nipype has SPM on the MATLAB path when it
is running MATLAB. Try running this command to get the SPM version.
If this gives an error message, you may not have SPM set up on your MATLAB
path by default. You can use Nipype to add SPM to the MATLAB path like this:
```{python}
nim.MatlabCommand.set_default_paths('/Users/mb312/dev_trees/spm12')
```
Another option is to use the MATLAB GUI to add this directory to the MATLAB
path, and save this path for future sessions.
Now try running the `spm ver` command again:
We are going to put the setup we need into a Python file we can import from
any script that we write that uses nipype.
In your current directory, make a new file called `nipype_settings.py` with
contents like this:
```
""" Defaults for using nipype
"""
import nipype.interfaces.matlab as nim
# If you needed to set the default matlab command above
nim.MatlabCommand.set_default_matlab_cmd('/Applications/MATLAB_R2014a.app/bin/matlab')
# If you needed to set the SPM path above
nim.MatlabCommand.set_default_paths('/Users/mb312/dev_trees/spm12')
```
Now try:
These should run without error.
<!-- vim:ft=rst -->
<!-- Course -->
<!-- BIC -->
<!-- Python distributions -->
<!-- Version control -->
<!-- Editors -->
<!-- Python and common libraries -->
<!-- IPython -->
<!-- Virtualenv and helpers -->
<!-- Pypi and packaging -->
<!-- Mac development -->
<!-- Windows development -->
<!-- Nipy and friends -->
<!-- FMRI datasets -->
<!-- Languages -->
<!-- Imaging software -->
<!-- Installation -->
<!-- Tutorials -->
<!-- MB tutorials -->
<!-- Ideas -->
<!-- Psych-214 -->
<!-- People -->
<!-- Licenses -->
<!-- Neuroimaging stuff -->
<!-- OpenFMRI projects -->
<!-- Unix -->
<!-- Substitutions -->