hplmtransformation.html 16.5 KB
Newer Older
Philipp Frank's avatar
Philipp Frank committed
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

<!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>nifty.operators.fft_operator.transformations.hplmtransformation &#8212; NIFTY 3.0.x documentation</title>
    
    <link rel="stylesheet" href="../../../../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../../../',
        VERSION:     '3.0.x',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </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>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../../search.html" />
   
  <link rel="stylesheet" href="../../../../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head>
  <body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for nifty.operators.fft_operator.transformations.hplmtransformation</h1><div class="highlight"><pre>
<span></span><span class="c1"># NIFTy</span>
<span class="c1"># Copyright (C) 2017  Theo Steininger</span>
<span class="c1">#</span>
<span class="c1"># Author: Theo Steininger</span>
<span class="c1">#</span>
<span class="c1"># This program is free software: you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation, either version 3 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">nifty.config</span> <span class="k">import</span> <span class="n">dependency_injector</span> <span class="k">as</span> <span class="n">gdi</span>
<span class="kn">from</span> <span class="nn">nifty</span> <span class="k">import</span> <span class="n">HPSpace</span><span class="p">,</span> <span class="n">LMSpace</span>
<span class="kn">from</span> <span class="nn">slicing_transformation</span> <span class="k">import</span> <span class="n">SlicingTransformation</span>

<span class="kn">import</span> <span class="nn">lm_transformation_helper</span>

<span class="n">pyHealpix</span> <span class="o">=</span> <span class="n">gdi</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;pyHealpix&#39;</span><span class="p">)</span>


<div class="viewcode-block" id="HPLMTransformation"><a class="viewcode-back" href="../../../../../hplm_transformation.html#nifty.HPLMTransformation">[docs]</a><span class="k">class</span> <span class="nc">HPLMTransformation</span><span class="p">(</span><span class="n">SlicingTransformation</span><span class="p">):</span>

    <span class="c1"># ---Overwritten properties and methods---</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">domain</span><span class="p">,</span> <span class="n">codomain</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">module</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">module</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">module</span> <span class="o">=</span> <span class="s1">&#39;pyHealpix&#39;</span>

        <span class="k">if</span> <span class="n">module</span> <span class="o">!=</span> <span class="s1">&#39;pyHealpix&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unsupported SHT module.&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s1">&#39;pyHealpix&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">gdi</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span>
                <span class="s2">&quot;The module pyHealpix is needed but not available&quot;</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">HPLMTransformation</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="n">codomain</span><span class="p">,</span> <span class="n">module</span><span class="p">)</span>

    <span class="c1"># ---Mandatory properties and methods---</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">unitary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="kc">False</span>

<div class="viewcode-block" id="HPLMTransformation.get_codomain"><a class="viewcode-back" href="../../../../../hplm_transformation.html#nifty.HPLMTransformation.get_codomain">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">get_codomain</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">domain</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Generates a compatible codomain to which transformations are</span>
<span class="sd">            reasonable, i.e.\  an instance of the :py:class:`lm_space` class.</span>

<span class="sd">            Parameters</span>
<span class="sd">            ----------</span>
<span class="sd">            domain: HPSpace</span>
<span class="sd">                Space for which a codomain is to be generated</span>

<span class="sd">            Returns</span>
<span class="sd">            -------</span>
<span class="sd">            codomain : LMSpace</span>
<span class="sd">                A compatible codomain.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="n">HPSpace</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;domain needs to be a HPSpace&quot;</span><span class="p">)</span>

        <span class="n">lmax</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">domain</span><span class="o">.</span><span class="n">nside</span>

        <span class="n">result</span> <span class="o">=</span> <span class="n">LMSpace</span><span class="p">(</span><span class="n">lmax</span><span class="o">=</span><span class="n">lmax</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">result</span></div>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">check_codomain</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">domain</span><span class="p">,</span> <span class="n">codomain</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="n">HPSpace</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;domain is not a HPSpace&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">codomain</span><span class="p">,</span> <span class="n">LMSpace</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;codomain must be a LMSpace.&quot;</span><span class="p">)</span>

        <span class="n">lmax</span> <span class="o">=</span> <span class="n">codomain</span><span class="o">.</span><span class="n">lmax</span>
        <span class="n">nside</span> <span class="o">=</span> <span class="n">domain</span><span class="o">.</span><span class="n">nside</span>

        <span class="k">if</span> <span class="n">lmax</span> <span class="o">!=</span> <span class="mi">2</span><span class="o">*</span><span class="n">nside</span><span class="p">:</span>
            <span class="bp">cls</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Unrecommended: lmax != 2*nside.&quot;</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">HPLMTransformation</span><span class="p">,</span> <span class="bp">cls</span><span class="p">)</span><span class="o">.</span><span class="n">check_codomain</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="n">codomain</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_transformation_of_slice</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inp</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">inp</span><span class="o">.</span><span class="n">dtype</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">complex</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;The input array has dtype: </span><span class="si">%s</span><span class="s2">. The FFT will &quot;</span>
                             <span class="s2">&quot;be performed at double precision.&quot;</span> <span class="o">%</span>
                             <span class="nb">str</span><span class="p">(</span><span class="n">inp</span><span class="o">.</span><span class="n">dtype</span><span class="p">))</span>

        <span class="n">lmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">codomain</span><span class="o">.</span><span class="n">lmax</span>
        <span class="n">mmax</span> <span class="o">=</span> <span class="n">lmax</span>

        <span class="k">if</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">inp</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">complexfloating</span><span class="p">):</span>
            <span class="p">[</span><span class="n">resultReal</span><span class="p">,</span>
             <span class="n">resultImag</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">pyHealpix</span><span class="o">.</span><span class="n">map2alm</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">lmax</span><span class="p">,</span> <span class="n">mmax</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">(</span><span class="n">inp</span><span class="o">.</span><span class="n">real</span><span class="p">,</span> <span class="n">inp</span><span class="o">.</span><span class="n">imag</span><span class="p">)]</span>

            <span class="p">[</span><span class="n">resultReal</span><span class="p">,</span>
             <span class="n">resultImag</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">lm_transformation_helper</span><span class="o">.</span><span class="n">buildIdx</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">lmax</span><span class="o">=</span><span class="n">lmax</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="n">resultReal</span><span class="p">,</span> <span class="n">resultImag</span><span class="p">]]</span>

            <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_combine_complex_result</span><span class="p">(</span><span class="n">resultReal</span><span class="p">,</span> <span class="n">resultImag</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="n">pyHealpix</span><span class="o">.</span><span class="n">map2alm</span><span class="p">(</span><span class="n">inp</span><span class="p">,</span> <span class="n">lmax</span><span class="p">,</span> <span class="n">mmax</span><span class="p">)</span>
            <span class="n">result</span> <span class="o">=</span> <span class="n">lm_transformation_helper</span><span class="o">.</span><span class="n">buildIdx</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">lmax</span><span class="o">=</span><span class="n">lmax</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">result</span></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../../../index.html">
              <img class="logo" src="../../../../../_static/nifty_logo_black.png" alt="Logo"/>
            </a></p><div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../../../../index.html">Documentation overview</a><ul>
  <li><a href="../../../../index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2017, Theo Steininger.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
      
    </div>

    

    
  </body>
</html>