/usr/share/doc/python-pynfft-doc/html/tutorial.html is in python-pynfft-doc 1.3.2-2.
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 | <!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>Using the NFFT — pyNFFT 1.3.2 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.3.2',
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="pyNFFT 1.3.2 documentation" href="index.html" />
<link rel="next" title="API Reference" href="api.html" />
<link rel="prev" title="Welcome to pyNFFT’s documentation!" href="index.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<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="api.html" title="API Reference"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to pyNFFT’s documentation!"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">pyNFFT 1.3.2 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="using-the-nfft">
<h1>Using the NFFT<a class="headerlink" href="#using-the-nfft" title="Permalink to this headline">¶</a></h1>
<p>In this tutorial, we assume that you are already familiar with the <a class="reference external" href="http://en.wikipedia.org/wiki/Non-uniform_discrete_Fourier_transform">non-uniform
discrete Fourier transform</a> and the
<a class="reference external" href="http://www-user.tu-chemnitz.de/~potts/nfft/">NFFT library</a> used for fast
computation of NDFTs.</p>
<p>Like the <a class="reference external" href="http://www.fftw.org/">FFTW library</a>, the NFFT library relies on a
specific data structure, called a plan, which stores all the data required for
efficient computation and re-use of the NDFT. Each plan is tailored for a
specific transform, depending on the geometry, level of precomputation and
design parameters. The <a class="reference external" href="http://www-user.tu-chemnitz.de/~potts/nfft/guide3/html/index.html">NFFT manual</a> contains
comprehensive explanation on the NFFT implementation.</p>
<p>The pyNFFT package provides a set of Pythonic wrappers around the main data
structures of the NFFT library. Use of Python wrappers allows to simplify the
manipulation of the library, whilst benefiting from the significant speedup
provided by its C-implementation. Although the NFFT library supports many more
applications, only the NFFT and iterative solver components have been wrapped
so far.</p>
<p>This tutorial is split into three main sections. In the first one, the general
workflow for using the core of the <code class="xref py py-class docutils literal"><span class="pre">pynfft.NFFT</span></code> class will be
explained. Then, the <code class="xref py py-class docutils literal"><span class="pre">pynfft.NFFT</span></code> class API will be detailed and
illustrated with examples for the univariate and multivariate cases. Finally,
the <code class="xref py py-class docutils literal"><span class="pre">pynfft.Solver</span></code> iterative solver class will be briefly presented.</p>
<div class="section" id="workflow">
<span id="id1"></span><h2>Workflow<a class="headerlink" href="#workflow" title="Permalink to this headline">¶</a></h2>
<p>For users already familiar with the NFFT C-library, the workflow is basically
the same. It consists in the following three steps:</p>
<blockquote>
<div><ol class="arabic simple">
<li>instantiation</li>
<li>precomputation</li>
<li>execution</li>
</ol>
</div></blockquote>
<p>In step 1, information such as the geometry of the transform or the desired
level of precomputation is provided to the constructor, which takes care of
allocating the internal arrays of the plan.</p>
<p>Precomputation (step 2) can be started once the location of the non-uniform
nodes have been set to the plan. Depending on the size of the transform and
level of precomputation, this step may take some time.</p>
<p>Finally (step 3), the forward or adjoint NFFT is computed by first setting the
input data in either <cite>f_hat</cite> (forward) or <cite>f</cite> (adjoint), calling the
corresponding function, and reading the output in <cite>f</cite> (forward) or <cite>f_hat</cite>
(adjoint).</p>
</div>
<div class="section" id="using-nfft">
<span id="id2"></span><h2>Using the NFFT<a class="headerlink" href="#using-nfft" title="Permalink to this headline">¶</a></h2>
<p>The core of this library is encapsulated in the <code class="xref py py-class docutils literal"><span class="pre">pyfftw.NFFT</span> <span class="pre">class</span></code>.</p>
<p><strong>instantiation</strong></p>
<p>The bare minimum to instantiate a new <code class="xref py py-class docutils literal"><span class="pre">pynfft.NFFT</span></code> plan is to specify
the geometry to the transform, i.e. the shape of the matrix containing the
uniform data <cite>N</cite> and the number of non-uniform nodes <cite>M</cite>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pynfft.nfft</span> <span class="kn">import</span> <span class="n">NFFT</span>
<span class="gp">>>> </span><span class="n">plan</span> <span class="o">=</span> <span class="n">NFFT</span><span class="p">([</span><span class="mi">16</span><span class="p">,</span> <span class="mi">16</span><span class="p">],</span> <span class="mi">92</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">plan</span><span class="o">.</span><span class="n">M</span>
<span class="go">96</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">plan</span><span class="o">.</span><span class="n">N</span>
<span class="go">(16, 16)</span>
</pre></div>
</div>
<p>More control over the precision, storage and speed of the NFFT can be gained by
overriding the default design parameters <cite>m</cite>, <cite>n</cite> and <cite>flags</cite>. For more
information, please consult the <a class="reference external" href="http://www-user.tu-chemnitz.de/~potts/nfft/guide3/html/index.html">NFFT manual</a>.</p>
<p><strong>precomputation</strong></p>
<p>Precomputation <em>must</em> be performed before calling any of the transforms. The
user can manually set the nodes of the NFFT object using the
<code class="xref py py-attr docutils literal"><span class="pre">pynfft.nfft.NFFT.x</span></code> attribute before calling the
<code class="xref py py-meth docutils literal"><span class="pre">pynfft.nfft.NFFT.precompute()</span></code> method.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">plan</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
<span class="gp">>>> </span><span class="n">plan</span><span class="o">.</span><span class="n">precompute</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>execution</strong></p>
<p>The actual forward and adjoint NFFT are performed by calling the
<code class="xref py py-meth docutils literal"><span class="pre">pynfft.nfft.NFFT.trafo()</span></code> and <code class="xref py py-meth docutils literal"><span class="pre">pynfft.nfft.NFFT.adjoint()</span></code> methods.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="c1"># forward transform</span>
<span class="gp">>>> </span><span class="n">plan</span><span class="o">.</span><span class="n">f_hat</span> <span class="o">=</span> <span class="n">f_hat</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">plan</span><span class="o">.</span><span class="n">trafo</span><span class="p">()</span>
<span class="gp">>>> </span><span class="c1"># adjoint transform</span>
<span class="gp">>>> </span><span class="n">plan</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">f</span>
<span class="gp">>>> </span><span class="n">f_hat</span> <span class="o">=</span> <span class="n">plan</span><span class="o">.</span><span class="n">adjoint</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="using-the-iterative-solver">
<span id="using-solver"></span><h2>Using the iterative solver<a class="headerlink" href="#using-the-iterative-solver" title="Permalink to this headline">¶</a></h2>
<p><strong>instantiation</strong></p>
<p>The instantiation of a <code class="xref py py-class docutils literal"><span class="pre">pynfft.solver.Solver</span></code> object requires an
instance of <code class="xref py py-class docutils literal"><span class="pre">pynfft.nfft.NFFT</span></code>. The following code shows you a simple
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pynfft</span> <span class="kn">import</span> <span class="n">NFFT</span><span class="p">,</span> <span class="n">Solver</span>
<span class="gp">>>> </span><span class="n">plan</span> <span class="o">=</span> <span class="n">NFFT</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">infft</span> <span class="o">=</span> <span class="n">Solver</span><span class="p">(</span><span class="n">plan</span><span class="p">)</span>
</pre></div>
</div>
<p>It is strongly recommended to use an already <em>precomputed</em>
<code class="xref py py-class docutils literal"><span class="pre">pynfft.nfft.NFFT</span></code> object to instantiate a <code class="xref py py-class docutils literal"><span class="pre">pynfft.solver.Solver</span></code>
object, or at the very least, make sure to call its precompute method before
using solver.</p>
<p>Since the solver will typically run several iterations before converging to a
stable solution, it is also strongly encourage to use the maximum level of
precomputation to speed-up each call to the NFFT. Please check the paragraph
regarding the choice of precomputation flags for the <code class="xref py py-class docutils literal"><span class="pre">pynfft.nfft.NFFT</span></code>.</p>
<p>By default, the <code class="xref py py-class docutils literal"><span class="pre">pynfft.solver.Solver</span></code> class uses the Conjugate Gradient
of the first kind method (CGNR flag). This may be overriden in the constructor:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">infft</span> <span class="o">=</span> <span class="n">Solver</span><span class="p">(</span><span class="n">plan</span><span class="p">,</span> <span class="n">flags</span><span class="o">=</span><span class="s1">'CGNE'</span><span class="p">)</span>
</pre></div>
</div>
<p>Convergence to a stable solution can be significantly speed-up using the right
pre-conditioning weights. These can accessed by the
<code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.w</span></code> and <code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.w_hat</span></code>
attributes. By default, these weights are set to 1.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">infft</span> <span class="o">=</span> <span class="n">Solver</span><span class="p">(</span><span class="n">plan</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span>
</pre></div>
</div>
<p><strong>using the solver</strong></p>
<p>Before iterating, the solver has to be intialized. As a reminder, make sure the
<code class="xref py py-class docutils literal"><span class="pre">pynfft.nfft.NFFT</span></code> object used to instantiate the solver has been
<em>precomputed</em>. Otherwise, the solver will be in an undefined state and will not
behave properly.</p>
<p>Initialization of the solver is performed by first setting the non-uniform
samples <code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.y</span></code>, an initial guess of the solution
<code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.f_hat_iter</span></code> and then calling the
<code class="xref py py-meth docutils literal"><span class="pre">pynfft.solver.Solver.before_loop()</span></code> method.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>
<span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">f_hat_iter</span> <span class="o">=</span> <span class="n">f_hat_iter</span>
<span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">before_loop</span><span class="p">()</span>
</pre></div>
</div>
<p>By default, the initial guess of the solution is set to 0.</p>
<p>After initialization of the solver, a single iteration can be performed by
calling the <code class="xref py py-meth docutils literal"><span class="pre">pynfft.solver.Solver.loop_one_step()</span></code> method. With each
iteration, the current solution is written in the
<code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.f_hat_iter</span></code> attribute.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">loop_one_step</span><span class="p">()</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">infft</span><span class="o">.</span><span class="n">f_hat_iter</span>
<span class="gp">>>> </span><span class="n">infft</span><span class="o">.</span><span class="n">loop_one_step</span><span class="p">()</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">infft</span><span class="o">.</span><span class="n">f_hat_iter</span>
</pre></div>
</div>
<p>The <code class="xref py py-class docutils literal"><span class="pre">pynfft.Solver</span></code> class only supports one iteration at a time. It is
at the discretion to implement the desired stopping condition, based for
instance on a maximum iteration count or a threshold value on the residuals.
The residuals can be read in the <code class="xref py py-attr docutils literal"><span class="pre">pynfft.solver.Solver.r_iter</span></code> attribute.
Below are two simple examples:</p>
<blockquote>
<div><ul class="simple">
<li>with a maximum number of iterations:</li>
</ul>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">niter</span> <span class="o">=</span> <span class="mi">10</span> <span class="c1"># set number of iterations to 10</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">iiter</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">niter</span><span class="p">):</span>
<span class="gp">>>> </span> <span class="n">infft</span><span class="o">.</span><span class="n">loop_one_step</span><span class="p">()</span>
</pre></div>
</div>
<ul class="simple">
<li>with a threshold value:</li>
</ul>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">threshold</span> <span class="o">=</span> <span class="mf">1e-3</span>
<span class="gp">>>> </span><span class="k">try</span><span class="p">:</span>
<span class="gp">>>> </span> <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="gp">>>> </span> <span class="n">infft</span><span class="o">.</span><span class="n">loop_one_step</span><span class="p">()</span>
<span class="gp">>>> </span> <span class="k">if</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">infft</span><span class="o">.</span><span class="n">r_iter</span> <span class="o"><</span> <span class="n">threshold</span><span class="p">)):</span>
<span class="gp">>>> </span> <span class="k">raise</span> <span class="n">StopCondition</span>
<span class="gp">>>> </span><span class="k">except</span> <span class="n">StopCondition</span><span class="p">:</span>
<span class="gp">>>> </span> <span class="c1"># rest of the algorithm</span>
</pre></div>
</div>
</div></blockquote>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Using the NFFT</a><ul>
<li><a class="reference internal" href="#workflow">Workflow</a></li>
<li><a class="reference internal" href="#using-nfft">Using the NFFT</a></li>
<li><a class="reference internal" href="#using-the-iterative-solver">Using the iterative solver</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Welcome to pyNFFT’s documentation!</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">API Reference</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/tutorial.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<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="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<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="api.html" title="API Reference"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to pyNFFT’s documentation!"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">pyNFFT 1.3.2 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2013, Ghislain Vaillant.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
</div>
</body>
</html>
|