This file is indexed.

/usr/share/doc/python-nifti/html/examples.html is in python-nifti 0.20100607.1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Examples &mdash; Home</title>
    <link rel="stylesheet" href="_static/pynifti.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.20100607.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Home" href="index.html" />
    <link rel="next" title="Module Reference" href="modref.html" />
    <link rel="prev" title="Installation" href="installation.html" />
  <meta name="keywords" content="python, neuroscience, nifti, analyze, nifticlib, fsl">
  <link REL="icon" HREF="/_images/favicon.png" TYPE="image/png">

  </head>
  <body>
  <div id="header">
  PyNIfTI - Pythonic access to NIfTI and ANALYZE files
  </div>

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modref.html" title="Module Reference"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installation"
             accesskey="P">previous</a> |</li>
  <li><a href="http://niftilib.sourceforge.net" target="_blank">NIfTI Libraries</a> |&nbsp;</li>
  <li><a href="index.html">PyNIfTI Home</a> |&nbsp;</li>
  <li><a href="contents.html">Documentation</a> &raquo;</li>
 
      </ul>
    </div>

      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Examples</a><ul>
<li><a class="reference internal" href="#loading-and-saving-nifti-files">Loading and saving NIfTI files</a></li>
<li><a class="reference internal" href="#nifti-files-from-array-data">NIfTI files from array data</a></li>
<li><a class="reference internal" href="#select-rois">Select ROIs</a></li>
<li><a class="reference internal" href="#linear-detrending-of-timeseries-scipy-module-is-required-for-this-example">Linear detrending of timeseries (SciPy module is required for this example)</a></li>
<li><a class="reference internal" href="#make-a-quick-plot-of-a-voxel-s-timeseries-matplotlib-module-is-required">Make a quick plot of a voxel&#8217;s timeseries (matplotlib module is required)</a></li>
<li><a class="reference internal" href="#show-a-slice-of-a-3d-volume-matplotlib-module-is-required">Show a slice of a 3d volume (Matplotlib module is required)</a></li>
<li><a class="reference internal" href="#compute-and-display-peristimulus-signal-timecourse-of-multiple-conditions">Compute and display peristimulus signal timecourse of multiple conditions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="installation.html"
                        title="previous chapter">Installation</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="modref.html"
                        title="next chapter">Module Reference</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/examples.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="examples">
<h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h1>
<p>The next sections contains some examples showing ways to use PyNIfTI to
read and write imaging data from within Python to be able to process it with
some random Python library.</p>
<p>All examples assume that you have imported the PyNIfTI module by invoking:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">nifti</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
<div class="section" id="loading-and-saving-nifti-files">
<h2>Loading and saving NIfTI files<a class="headerlink" href="#loading-and-saving-nifti-files" title="Permalink to this headline"></a></h2>
<p>First we will open the tiny example NIfTI file that is included in the PyNIfTI
source tarball. No filename extension is necessary as libniftiio determines it
automatically:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span><span class="s">&#39;example4d&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The filename is available via the &#8216;filename&#8217; attribute:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">nim</span><span class="o">.</span><span class="n">filename</span>
<span class="go">example4d.nii.gz</span>
</pre></div>
</div>
<p>This indicates a compressed NIfTI image. If you want to save this image as an
uncompressed image simply do:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">&#39;something.nii&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The filetype is determined from the filename. If you want to save to gzipped
ANALYZE file pairs instead the following would be an alternative to calling
the <tt class="docutils literal"><span class="pre">save()</span></tt> with a new filename:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">setFilename</span><span class="p">(</span><span class="s">&#39;analyze.img.gz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre></div>
</div>
<p>Please see the documentation of <a class="reference internal" href="modref.html#nifti.image.NiftiImage.setFilename" title="nifti.image.NiftiImage.setFilename"><tt class="xref py py-meth docutils literal"><span class="pre">setFilename()</span></tt></a>
to learn how the filetypes are determined from the filenames.</p>
</div>
<div class="section" id="nifti-files-from-array-data">
<h2>NIfTI files from array data<a class="headerlink" href="#nifti-files-from-array-data" title="Permalink to this headline"></a></h2>
<p>The next code snipped demonstrates how to create a 4d NIfTI image containing
gaussian noise. First we need to import the NumPy module</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">N</span>
</pre></div>
</div>
<p>Now we generate the noise dataset. Let&#8217;s generate noise for 100 volumes with 16
slices and a 32x32 inplane matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">noise</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span><span class="mi">16</span><span class="p">,</span><span class="mi">32</span><span class="p">,</span><span class="mi">32</span><span class="p">)</span>
</pre></div>
</div>
<p>Please notice the order in which the dimensions are specified: (t, z, y, x).</p>
<p>The datatype of the array is by default <cite>float64</cite>, which can be verified by:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">noise</span><span class="o">.</span><span class="n">dtype</span>
<span class="go">dtype(&#39;float64&#39;)</span>
</pre></div>
</div>
<p>Converting this dataset into a NIfTI image is done by invoking the
<a class="reference internal" href="modref.html#nifti.image.NiftiImage" title="nifti.image.NiftiImage"><tt class="xref py py-class docutils literal"><span class="pre">NiftiImage</span></tt></a> constructor with the noise dataset as argument:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span><span class="n">noise</span><span class="p">)</span>
</pre></div>
</div>
<p>The relevant header information is extracted from the NumPy array. If you
query the header information about the dimensionality of the image, it returns
the desired values:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">nim</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;dim&#39;</span><span class="p">]</span>
<span class="go">[4, 32, 32, 16, 100, 1, 1, 1]</span>
</pre></div>
</div>
<p>First value shows the number of dimensions in the datset: 4 (good, that&#8217;s what
we wanted). The following numbers are dataset size on the x, y, z, t, u, v, w
axis (NIfTI files can handle up to 7 dimensions). Please notice, that the
order of dimensions is now &#8216;correct&#8217;: We have 32x32 inplane resolution, 16
slices in z direction and 100 volumes.</p>
<p>Also the datatype was set appropriately:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">nifti.clib</span> <span class="kn">as</span> <span class="nn">ncl</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;datatype&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">ncl</span><span class="o">.</span><span class="n">NIFTI_TYPE_FLOAT64</span>
<span class="go">True</span>
</pre></div>
</div>
<p>To save the noise file to disk, we can simply call the
<a class="reference internal" href="modref.html#nifti.image.NiftiImage.save" title="nifti.image.NiftiImage.save"><tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt></a> method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">&#39;noise.nii.gz&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="select-rois">
<h2>Select ROIs<a class="headerlink" href="#select-rois" title="Permalink to this headline"></a></h2>
<p>Suppose you want to have the first ten volumes of the noise dataset we have
previously created in a separate file. First, we open the file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span><span class="s">&#39;noise.nii.gz&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Now we select the first ten volumes and store them to another file, while
preserving as much header information as possible</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim2</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span><span class="n">nim</span><span class="o">.</span><span class="n">data</span><span class="p">[:</span><span class="mi">10</span><span class="p">],</span> <span class="n">nim</span><span class="o">.</span><span class="n">header</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nim2</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">&#39;part.hdr.gz&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="modref.html#nifti.image.NiftiImage" title="nifti.image.NiftiImage"><tt class="xref py py-class docutils literal"><span class="pre">NiftiImage</span></tt></a> constructor takes a dictionary with header
information as an optional argument. Settings that are not determined by the
array (e.g.  size, datatype) are taken from the dictionary and stored to the
new NIfTI image.</p>
</div>
<div class="section" id="linear-detrending-of-timeseries-scipy-module-is-required-for-this-example">
<h2>Linear detrending of timeseries (SciPy module is required for this example)<a class="headerlink" href="#linear-detrending-of-timeseries-scipy-module-is-required-for-this-example" title="Permalink to this headline"></a></h2>
<p>Let&#8217;s load another 4d NIfTI file and perform a linear detrending, by fitting
a straight line to the timeseries of each voxel and substract that fit from
the data. Although this might sound complicated at first, thanks to the
excellent SciPy module it is just a few lines of code. For this example we
will first create a NIfTI image with just a single voxel and 50 timepoints
(basically a linear function with some noise):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span>
<span class="gp">... </span>          <span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">50</span><span class="p">))</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">50</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">timepoints</span>
<span class="go">50</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span><span class="o">.</span><span class="n">volextent</span>
<span class="go">(1, 1, 1)</span>
</pre></div>
</div>
<p>Depending on the datatype of the input image the detrending process might
change the datatype from integer to float. As operations that change the
(binary) size of the NIfTI image are not supported, we need to make a copy
of the data and later create a new NIfTI image. Remember that the array has the
time axis as its first dimension (in contrast to the NIfTI file where it is
the 4th).</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">signal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data_detrended</span> <span class="o">=</span> <span class="n">signal</span><span class="o">.</span><span class="n">detrend</span><span class="p">(</span><span class="n">nim</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<p>Finally, create a new NIfTI image using header information from the original
source image.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim_detrended</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span> <span class="n">data_detrended</span><span class="p">,</span> <span class="n">nim</span><span class="o">.</span><span class="n">header</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="make-a-quick-plot-of-a-voxel-s-timeseries-matplotlib-module-is-required">
<h2>Make a quick plot of a voxel&#8217;s timeseries (matplotlib module is required)<a class="headerlink" href="#make-a-quick-plot-of-a-voxel-s-timeseries-matplotlib-module-is-required" title="Permalink to this headline"></a></h2>
<p>Plotting is essential to get a &#8216;feeling&#8217; for the data. The Matlab-style plotting
via <a class="reference external" href="http://matplotlib.sourceforge.net">matplotlib</a> make it really easy to plot something with (e.g. when
running Python interactively via <a class="reference external" href="http://ipython.scipy.org">IPython</a>). Please note, that there are many
other possibilities for plotting, e.g. <a class="reference external" href="http://www.r-project.org">R</a>  via <a class="reference external" href="http://rpy.sourceforge.net">RPy</a> or <a class="reference external" href="http://www.gnuplot.info">Gnuplot</a> via the
<a class="reference external" href="http://gnuplot-py.sourceforge.net">Gnuplot python bindings</a></p>
<p>However, using matplotlib is really easy. For this example we will plot the
two timeseries from the previous example, i.e. the raw and the detrended one.
First we import the pylab module:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pylab</span> <span class="kn">as</span> <span class="nn">P</span>
</pre></div>
</div>
<p>Now we can easly plot both timeseries of the single voxel in our artifical
image:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">line1</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">nim</span><span class="o">.</span><span class="n">data</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">line2</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">nim_detrended</span><span class="o">.</span><span class="n">data</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,])</span>
</pre></div>
</div>
<p>A <cite>P.show()</cite> call would render the plot on the screen.</p>
</div>
<div class="section" id="show-a-slice-of-a-3d-volume-matplotlib-module-is-required">
<h2>Show a slice of a 3d volume (Matplotlib module is required)<a class="headerlink" href="#show-a-slice-of-a-3d-volume-matplotlib-module-is-required" title="Permalink to this headline"></a></h2>
<p>This example demonstrates howto use the Matlab-style plotting of <a class="reference external" href="http://matplotlib.sourceforge.net">matplotlib</a>
to view a slice from a 3d volume. We will actually use a 4D image as data
source and limit us to the first volume:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">nim</span> <span class="o">=</span> <span class="n">NiftiImage</span><span class="p">(</span><span class="s">&#39;example4d&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">volume</span> <span class="o">=</span> <span class="n">nim</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
</pre></div>
</div>
<p>If everything went fine, we can now view a slice (x,y):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">xyplot</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">volume</span><span class="p">[</span><span class="mi">16</span><span class="p">],</span>
<span class="gp">... </span>                  <span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
<span class="gp">... </span>                  <span class="n">cmap</span><span class="o">=</span><span class="n">P</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">gray</span><span class="p">)</span>
</pre></div>
</div>
<p>Again a call to the <cite>P.show()</cite> function would render the plot on the screen.</p>
<p>When you want to have a look at a yz-slice, NumPy array magic comes into
play.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">yzplot</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">volume</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">,:,</span><span class="mi">18</span><span class="p">],</span>
<span class="gp">... </span>                  <span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
<span class="gp">... </span>                  <span class="n">cmap</span><span class="o">=</span><span class="n">P</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">gray</span><span class="p">)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">::-1</span></tt> notation causes the z-axis to be flipped in the images. This
makes a much nicer view, if the used example volume has the z-axis originally
oriented upsidedown.</p>
</div>
<div class="section" id="compute-and-display-peristimulus-signal-timecourse-of-multiple-conditions">
<h2>Compute and display peristimulus signal timecourse of multiple conditions<a class="headerlink" href="#compute-and-display-peristimulus-signal-timecourse-of-multiple-conditions" title="Permalink to this headline"></a></h2>
<p>Sometimes one wants to look at the signal timecourse of some voxel after a
certain stimulation onset. An easy way would be to have some fMRI data viewer
that displays a statistical map and one could click on some activated voxel
and the peristimulus signal timecourse of some condition in that voxel would
be displayed.</p>
<p>This can easily be done by using <tt class="docutils literal"><span class="pre">pynifti_pst</span></tt> and <tt class="docutils literal"><span class="pre">FSLView</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">pynifti_pst</span></tt> comes with a manpage that explains all options and arguments.
Basically <tt class="docutils literal"><span class="pre">pynifti_pst</span></tt> needs a 4d image (e.g. an fMRI timeseries; possibly
preprocessed/filtered) and some stimulus onset information. This information
can either be given directly on the command line or is read from files.
Additionally one can specify onsets as volume numbers or as onset times.</p>
<p><tt class="docutils literal"><span class="pre">pynifti_pst</span></tt> understands the FSL custom EV file format so one can easily
use those files as input.</p>
<p>An example call could look like this:</p>
<div class="highlight-python"><pre>pynifti_pst --times --nvols 5 -p uf92.feat/filtered_func_data.nii.gz \
    pst_cond_a.nii.gz uf92.feat/custom_timing_files/ev1.txt \
    uf92.feat/custom_timing_files/ev2.txt</pre>
</div>
<p>This computes a peristimulus timeseries using the preprocessed fMRI from a
FEAT output directory and two custom EV files that both together make up
condition A. <tt class="docutils literal"><span class="pre">--times</span></tt> indicates that the EV files list onset times (not
volume ids) and <tt class="docutils literal"><span class="pre">--nvols</span></tt> requests the mean peristimulus timecourse for 4
volumes after stimulus onset (5 including onset). <tt class="docutils literal"><span class="pre">-p</span></tt> recodes the
peristimulus timeseries into percent signalchange, where the onset is always
zero and any following value is the signal change with respect to the onset
volume.</p>
<div class="figure">
<img alt="_images/fslview_pst.png" src="_images/fslview_pst.png" />
<p class="caption">FSLView with <tt class="docutils literal"><span class="pre">pynifti_pst</span></tt> example.</p>
</div>
<p>This call produces a simple 4d NIfTI image that can be loaded into FSLView as
any other timeseries. The following call can be used to display an FSL zmap
from the above results path on top of some anatomy. Additionally the
peristimulus timeseries of two conditions are loaded. The figure shows how it
could look like. One of the nice features of FSLView is that its timeseries
window can remember selected curves, which can be useful to compare signal
timecourses from different voxels (blue and green line in the figure).</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modref.html" title="Module Reference"
             >next</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installation"
             >previous</a> |</li>
  <li><a href="http://niftilib.sourceforge.net" target="_blank">NIfTI Libraries</a> |&nbsp;</li>
  <li><a href="index.html">PyNIfTI Home</a> |&nbsp;</li>
  <li><a href="contents.html">Documentation</a> &raquo;</li>
 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2006-2009, Michael Hanke.
      Last updated on Oct 18, 2011.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>