Skip to content

Commit

Permalink
Workspace constructors (#200)
Browse files Browse the repository at this point in the history
* new constructors implemented, not documented

* fkp normalisation implemented
  • Loading branch information
damonge authored Jul 23, 2024
1 parent 773f019 commit 70d3cec
Show file tree
Hide file tree
Showing 30 changed files with 877 additions and 352 deletions.
63 changes: 55 additions & 8 deletions doc/1BasicFunctionality.html

Large diffs are not rendered by default.

55 changes: 47 additions & 8 deletions doc/1BasicFunctionality.ipynb

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions doc/2Spin.html
Original file line number Diff line number Diff line change
Expand Up @@ -7762,12 +7762,9 @@ <h2 id="2.3-Mode-coupling-matrices-">2.3 Mode-coupling matrices <a class="anchor
<span class="n">b</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtBin</span><span class="o">.</span><span class="n">from_nside_linear</span><span class="p">(</span><span class="n">nside</span><span class="p">,</span> <span class="n">nlb</span><span class="o">=</span><span class="n">delta_ell</span><span class="p">)</span>

<span class="c1"># Create a NaMaster workspaces for the different spin combinations</span>
<span class="n">w00</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w00</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f0</span><span class="p">,</span> <span class="n">f0</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w02</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w02</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f0</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w22</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w22</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f2</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w00</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f0</span><span class="p">,</span> <span class="n">f0</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w02</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f0</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w22</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f2</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>

<span class="c1"># Extract the mode-coupling matrix</span>
<span class="n">mcm00</span> <span class="o">=</span> <span class="n">w00</span><span class="o">.</span><span class="n">get_coupling_matrix</span><span class="p">()</span>
Expand Down Expand Up @@ -8044,8 +8041,7 @@ <h2 id="2.5-Purification-">2.5 Purification <a class="anchor" id="Ss2.5"></a><a
<span class="n">f2p</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="p">[</span><span class="n">mpQ</span><span class="o">*</span><span class="n">maskbin</span><span class="p">,</span> <span class="n">mpU</span><span class="o">*</span><span class="n">maskbin</span><span class="p">],</span> <span class="n">purify_b</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="c1"># Now compute the MCM</span>
<span class="n">w22p</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w22p</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f2p</span><span class="p">,</span> <span class="n">f2p</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w22p</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f2p</span><span class="p">,</span> <span class="n">f2p</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">mcm22p</span> <span class="o">=</span> <span class="n">w22p</span><span class="o">.</span><span class="n">get_coupling_matrix</span><span class="p">()</span><span class="o">.</span><span class="n">reshape</span><span class="p">([</span><span class="mi">3</span><span class="o">*</span><span class="n">nside</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="o">*</span><span class="n">nside</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="n">mcm22p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">mcm22p</span><span class="p">,</span> <span class="n">axes</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>

Expand Down
12 changes: 4 additions & 8 deletions doc/2Spin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,9 @@
"b = nmt.NmtBin.from_nside_linear(nside, nlb=delta_ell)\n",
"\n",
"# Create a NaMaster workspaces for the different spin combinations\n",
"w00 = nmt.NmtWorkspace()\n",
"w00.compute_coupling_matrix(f0, f0, b)\n",
"w02 = nmt.NmtWorkspace()\n",
"w02.compute_coupling_matrix(f0, f2, b)\n",
"w22 = nmt.NmtWorkspace()\n",
"w22.compute_coupling_matrix(f2, f2, b)\n",
"w00 = nmt.NmtWorkspace.from_fields(f0, f0, b)\n",
"w02 = nmt.NmtWorkspace.from_fields(f0, f2, b)\n",
"w22 = nmt.NmtWorkspace.from_fields(f2, f2, b)\n",
"\n",
"# Extract the mode-coupling matrix\n",
"mcm00 = w00.get_coupling_matrix()\n",
Expand Down Expand Up @@ -510,8 +507,7 @@
"f2p = nmt.NmtField(mask, [mpQ*maskbin, mpU*maskbin], purify_b=True)\n",
"\n",
"# Now compute the MCM\n",
"w22p = nmt.NmtWorkspace()\n",
"w22p.compute_coupling_matrix(f2p, f2p, b)\n",
"w22p = nmt.NmtWorkspace.from_fields(f2p, f2p, b)\n",
"mcm22p = w22p.get_coupling_matrix().reshape([3*nside, 4, 3*nside, 4])\n",
"mcm22p = np.transpose(mcm22p, axes=[1, 0, 3, 2])\n",
"\n",
Expand Down
21 changes: 7 additions & 14 deletions doc/3Covariances.html
Original file line number Diff line number Diff line change
Expand Up @@ -7693,12 +7693,10 @@ <h2 id="3.1-Gaussian-covariance-of-scalar-fields-">3.1 Gaussian covariance of sc
<span class="n">f</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

<span class="c1"># MCM</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>

<span class="c1"># Covariance MCM</span>
<span class="n">cw</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="p">()</span>
<span class="n">cw</span><span class="o">.</span><span class="n">compute_coupling_coefficients</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="n">cw</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="n">fsky</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">mask</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
Expand Down Expand Up @@ -8126,11 +8124,9 @@ <h2 id="3.3-Covariance-of-spin-fields-">3.3 Covariance of spin fields <a class="

<span class="c1"># MCMs</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">purify_b</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">wp</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">wp</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">wp</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>

<span class="c1"># Sims</span>
<span class="n">nsims</span> <span class="o">=</span> <span class="mi">100</span>
Expand Down Expand Up @@ -8191,16 +8187,13 @@ <h2 id="3.3-Covariance-of-spin-fields-">3.3 Covariance of spin fields <a class="
<span class="c1"># Compute covariance workspaces</span>
<span class="c1"># As scalar fields</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">w0</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="p">()</span>
<span class="n">w0</span><span class="o">.</span><span class="n">compute_coupling_matrix</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">w0</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">pcl_ee</span> <span class="o">=</span> <span class="n">w0</span><span class="o">.</span><span class="n">couple_cell</span><span class="p">([</span><span class="n">cl_ee</span><span class="p">])</span><span class="o">/</span><span class="n">fsky</span>
<span class="n">pcl_bb</span> <span class="o">=</span> <span class="n">w0</span><span class="o">.</span><span class="n">couple_cell</span><span class="p">([</span><span class="n">cl_bb</span><span class="p">])</span><span class="o">/</span><span class="n">fsky</span>
<span class="n">cw0</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="p">()</span>
<span class="n">cw0</span><span class="o">.</span><span class="n">compute_coupling_coefficients</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="n">cw0</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="c1"># As spin-2 fields</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtField</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">cw2</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="p">()</span>
<span class="n">cw2</span><span class="o">.</span><span class="n">compute_coupling_coefficients</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="n">cw2</span> <span class="o">=</span> <span class="n">nmt</span><span class="o">.</span><span class="n">NmtCovarianceWorkspace</span><span class="o">.</span><span class="n">from_fields</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>

<span class="c1"># Gaussian covariance as scalar fields</span>
<span class="c1"># EE</span>
Expand Down
21 changes: 7 additions & 14 deletions doc/3Covariances.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@
"f = nmt.NmtField(mask, None, spin=0)\n",
"\n",
"# MCM\n",
"w = nmt.NmtWorkspace()\n",
"w.compute_coupling_matrix(f, f, b)\n",
"w = nmt.NmtWorkspace.from_fields(f, f, b)\n",
"\n",
"# Covariance MCM\n",
"cw = nmt.NmtCovarianceWorkspace()\n",
"cw.compute_coupling_coefficients(f, f)\n",
"cw = nmt.NmtCovarianceWorkspace.from_fields(f, f)\n",
"fsky = np.mean(mask**2)"
]
},
Expand Down Expand Up @@ -558,11 +556,9 @@
"\n",
"# MCMs\n",
"f = nmt.NmtField(mask, None, spin=2)\n",
"w = nmt.NmtWorkspace()\n",
"w.compute_coupling_matrix(f, f, b)\n",
"w = nmt.NmtWorkspace.from_fields(f, f, b)\n",
"f = nmt.NmtField(mask, None, spin=2, purify_b=True)\n",
"wp = nmt.NmtWorkspace()\n",
"wp.compute_coupling_matrix(f, f, b)\n",
"wp = nmt.NmtWorkspace.from_fields(f, f, b)\n",
"\n",
"# Sims\n",
"nsims = 100\n",
Expand Down Expand Up @@ -616,16 +612,13 @@
"# Compute covariance workspaces\n",
"# As scalar fields\n",
"f = nmt.NmtField(mask, None, spin=0)\n",
"w0 = nmt.NmtWorkspace()\n",
"w0.compute_coupling_matrix(f, f, b)\n",
"w0 = nmt.NmtWorkspace.from_fields(f, f, b)\n",
"pcl_ee = w0.couple_cell([cl_ee])/fsky\n",
"pcl_bb = w0.couple_cell([cl_bb])/fsky\n",
"cw0 = nmt.NmtCovarianceWorkspace()\n",
"cw0.compute_coupling_coefficients(f, f)\n",
"cw0 = nmt.NmtCovarianceWorkspace.from_fields(f, f)\n",
"# As spin-2 fields\n",
"f = nmt.NmtField(mask, None, spin=2)\n",
"cw2 = nmt.NmtCovarianceWorkspace()\n",
"cw2.compute_coupling_coefficients(f, f)\n",
"cw2 = nmt.NmtCovarianceWorkspace.from_fields(f, f)\n",
"\n",
"# Gaussian covariance as scalar fields\n",
"# EE\n",
Expand Down
Loading

0 comments on commit 70d3cec

Please sign in to comment.