Skip to content

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
WilfriedMercier committed Oct 4, 2021
1 parent d10075e commit 2363afc
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/API/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Catalogue classes" href="catalogues.html" />
<link rel="prev" title="Example 2: Resolved stellar mass map with LePhare" href="../examples/example2.html" />
<link rel="prev" title="Example 2: Resolved SFR map with LePhare from an output file" href="../examples/example2.html" />

</head>

Expand Down
14 changes: 8 additions & 6 deletions docs/_modules/SED/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/plot_directive.css" type="text/css" />
<link rel="stylesheet" href="../../_static/_static/custom.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />

Expand Down Expand Up @@ -125,15 +124,15 @@
</ul>
<p class="caption" role="heading"><span class="caption-text">Examples</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example1.html">1. Generate a LePhare configuration file</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example2.html">2. Resolved stellar mass map with LePhare</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example3.html">3. Resolved SFR map from an already existing LePhare output file</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example1.html">1. Resolved stellar mass map with LePhare</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example2.html">2. Resolved SFR map from an already existing LePhare output file</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">----------------------------------------</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../API/index.html">API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../API/catalogues.html">Catalogue classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../API/filters.html">Filter classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../API/misc/index.html">Miscellaneous</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../API/outputs.html">SED fitting code output classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../API/sed.html">SED classes</a></li>
</ul>
Expand Down Expand Up @@ -504,6 +503,9 @@ <h1>Source code for SED.filters</h1><div class="highlight"><pre>
<span class="c1"># Clean and add noise to variance map</span>
<span class="n">data</span><span class="p">,</span> <span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleanAndNoise</span><span class="p">(</span><span class="n">filt</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">filt</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">,</span> <span class="n">cleanMethod</span><span class="o">=</span><span class="n">cleanMethod</span><span class="p">,</span> <span class="n">texp</span><span class="o">=</span><span class="n">filt</span><span class="o">.</span><span class="n">texp</span><span class="p">,</span> <span class="n">texpFac</span><span class="o">=</span><span class="n">texpFac</span><span class="p">)</span>

<span class="n">test</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">var</span><span class="p">)</span><span class="o">/</span><span class="n">data</span>
<span class="nb">print</span><span class="p">(</span><span class="n">test</span><span class="p">[</span><span class="o">~</span><span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">test</span><span class="p">)])</span>

<span class="c1"># Scale data to have compatible values with LePhare for the flux</span>
<span class="n">data</span><span class="p">,</span> <span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">var</span><span class="p">,</span> <span class="n">meanMap</span><span class="p">,</span> <span class="n">factor</span><span class="o">=</span><span class="n">scaleFactor</span><span class="p">)</span>

Expand All @@ -518,7 +520,7 @@ <h1>Source code for SED.filters</h1><div class="highlight"><pre>
<span class="n">data</span><span class="p">[</span><span class="n">mask0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="n">var</span><span class="p">[</span> <span class="n">mask0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>

<span class="c1"># Compute std instead of variance</span>
<span class="c1"># Compute std instead of variance and go to mag</span>
<span class="n">data</span><span class="p">,</span> <span class="n">std</span> <span class="o">=</span> <span class="n">countToMag</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">var</span><span class="p">),</span> <span class="n">filt</span><span class="o">.</span><span class="n">zpt</span><span class="p">)</span>

<span class="c1"># Cast back pixels with NaN values to -99 mag to specify they are not to be used in the SED fitting</span>
Expand Down Expand Up @@ -747,7 +749,7 @@ <h1>Source code for SED.filters</h1><div class="highlight"><pre>

<span class="c1"># Add Poisson noise to the variance map</span>
<span class="k">if</span> <span class="n">texp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poissonVar</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">texp</span><span class="o">=</span><span class="n">texp</span><span class="p">,</span> <span class="n">texpFac</span><span class="o">=</span><span class="n">texpFac</span><span class="p">)</span>
<span class="n">var</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">poissonVar</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">texp</span><span class="o">=</span><span class="n">texp</span><span class="p">,</span> <span class="n">texpFac</span><span class="o">=</span><span class="n">texpFac</span><span class="p">)</span>

<span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">var</span></div>

Expand Down
5 changes: 3 additions & 2 deletions docs/_modules/SED/sed.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Examples</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example1.html">1. Resolved stellar mass map with LePhare</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/example2.html">2. Resolved SFR map from an already existing LePhare output file</a></li>
Expand Down Expand Up @@ -533,9 +534,9 @@ <h1>Source code for SED.sed</h1><div class="highlight"><pre>

<span class="s1">&#39;FIR_SCALE&#39;</span> <span class="p">:</span> <span class="n">FloatProperty</span><span class="p">(</span><span class="s1">&#39;-1&#39;</span><span class="p">),</span>

<span class="s1">&#39;FIR_FREESCALE&#39;</span> <span class="p">:</span> <span class="n">YESNO</span><span class="p">(</span><span class="n">YESNO</span><span class="o">.</span><span class="n">NO</span><span class="p">),</span>
<span class="s1">&#39;FIR_FREESCALE&#39;</span> <span class="p">:</span> <span class="n">EnumProperty</span><span class="p">(</span><span class="n">YESNO</span><span class="o">.</span><span class="n">NO</span><span class="p">),</span>

<span class="s1">&#39;FIR_SUBSTELLAR&#39;</span> <span class="p">:</span> <span class="n">YESNO</span><span class="p">(</span><span class="n">YESNO</span><span class="o">.</span><span class="n">NO</span><span class="p">),</span>
<span class="s1">&#39;FIR_SUBSTELLAR&#39;</span> <span class="p">:</span> <span class="n">EnumProperty</span><span class="p">(</span><span class="n">YESNO</span><span class="o">.</span><span class="n">NO</span><span class="p">),</span>

<span class="s1">&#39;PHYS_LIB&#39;</span> <span class="p">:</span> <span class="n">PathProperty</span><span class="p">(</span><span class="s1">&#39;NONE&#39;</span><span class="p">),</span>

Expand Down
2 changes: 1 addition & 1 deletion docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<li class="toctree-l1"><a class="reference internal" href="../examples/example1.html">1. Resolved stellar mass map with LePhare</a></li>
<li class="toctree-l1"><a class="reference internal" href="../examples/example2.html">2. Resolved SFR map from an already existing LePhare output file</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">----------------------------------------</span></p>
<p class="caption" role="heading"><span class="caption-text">―――――――――――――――</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../API/index.html">API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../API/catalogues.html">Catalogue classes</a></li>
Expand Down
21 changes: 17 additions & 4 deletions docs/_sources/examples/example1.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ We define the galaxy name, the bands used, their zeropoints and the absolute pat
.. code-block:: python
import os.path as opath
import matplotlib.pyplot as plt
from astropy.io import fits
import SED
Expand Down Expand Up @@ -79,8 +78,22 @@ To generate a resolved stellar mass map we need to provide additional parameters

.. code-block:: python
from matplotlib import rc
import matplotlib as mpl
import matplotlib.pyplot as plt
output.link(flist)
mass_star = output.toImage('mass_med')
mass_star = output.toImage('mass_med')
rc('font', **{'family': 'serif', 'serif': ['Times']})
rc('text', usetex=True)
mpl.rcParams['text.latex.preamble'] = r'\usepackage{newtxmath}'
rc('figure', figsize=(5, 4.5))
ret = plt.imshow(mass_star.data, origin='lower', cmap='rainbow')
plt.xlabel('X [pixel]', size=13)
plt.ylabel('Y [pixel]', size=13)
plt.imshow(mass_star.data, origin='lower', cmap='rainbow')
plt.show()
cbar = plt.colorbar(ret, orientation='vertical', shrink=0.9)
cbar.set_label(r'$\log_{10} M_{\star}$ [M$_{\odot}$]', size=13)
plt.show()
14 changes: 14 additions & 0 deletions docs/_sources/examples/example2.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ As in :doc:`example 1 </examples/example1>`, we can now generate a resolved map

.. code:: python
from matplotlib import rc
import matplotlib as mpl
import matplotlib.pyplot as plt
rc('font', **{'family': 'serif', 'serif': ['Times']})
rc('text', usetex=True)
mpl.rcParams['text.latex.preamble'] = r'\usepackage{newtxmath}'
rc('figure', figsize=(5, 4.5))
sfr = output.toImage('sfr_med')
plt.imshow(sfr.data, origin='lower', cmap='rainbow')
plt.xlabel('X [pixel]', size=13)
plt.ylabel('Y [pixel]', size=13)
cbar = plt.colorbar(ret, orientation='vertical', shrink=0.9)
cbar.set_label(r'$\log_{10}$ SFR [M$_{\odot}$ yr$^{-1}$]', size=13)
plt.show()
2 changes: 1 addition & 1 deletion docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ We provide a few complete code examples below using the galaxy given in the :cod
2. Resolved SFR map from an already existing LePhare output file <examples/example2>

.. toctree::
:caption: ----------------------------------------
:caption: ―――――――――――――――
:hidden:

API/index
21 changes: 17 additions & 4 deletions docs/examples/example1.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ <h1>Example 1: Generating a resolved stellar mass map with LePhare<a class="head
<p>We start by importing <code class="code docutils literal notranslate"><span class="pre">os.path</span></code> module (useful to deal with paths between different OS), this library (<code class="code docutils literal notranslate"><span class="pre">SED</span></code>) and <code class="code docutils literal notranslate"><span class="pre">astropy.io.fits</span></code> to open the mask file.</p>
<p>We define the galaxy name, the bands used, their zeropoints and the absolute path of the data and variance maps</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os.path</span> <span class="k">as</span> <span class="nn">opath</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">astropy.io</span> <span class="kn">import</span> <span class="n">fits</span>
<span class="kn">import</span> <span class="nn">SED</span>

Expand Down Expand Up @@ -218,10 +217,24 @@ <h1>Example 1: Generating a resolved stellar mass map with LePhare<a class="head
</pre></div>
</div>
<p>To generate a resolved stellar mass map we need to provide additional parameters. The simplest method is to link the filter list to the output object</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">output</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="n">flist</span><span class="p">)</span>
<span class="n">mass_star</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">toImage</span><span class="p">(</span><span class="s1">&#39;mass_med&#39;</span><span class="p">)</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">rc</span>
<span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>

<span class="n">output</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="n">flist</span><span class="p">)</span>
<span class="n">mass_star</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">toImage</span><span class="p">(</span><span class="s1">&#39;mass_med&#39;</span><span class="p">)</span>

<span class="n">rc</span><span class="p">(</span><span class="s1">&#39;font&#39;</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;family&#39;</span><span class="p">:</span> <span class="s1">&#39;serif&#39;</span><span class="p">,</span> <span class="s1">&#39;serif&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;Times&#39;</span><span class="p">]})</span>
<span class="n">rc</span><span class="p">(</span><span class="s1">&#39;text&#39;</span><span class="p">,</span> <span class="n">usetex</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s1">&#39;text.latex.preamble&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\usepackage</span><span class="si">{newtxmath}</span><span class="s1">&#39;</span>
<span class="n">rc</span><span class="p">(</span><span class="s1">&#39;figure&#39;</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mf">4.5</span><span class="p">))</span>

<span class="n">ret</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">mass_star</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="s1">&#39;lower&#39;</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">&#39;rainbow&#39;</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;X [pixel]&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Y [pixel]&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span>

<span class="n">plt</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">mass_star</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="s1">&#39;lower&#39;</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">&#39;rainbow&#39;</span><span class="p">)</span>
<span class="n">cbar</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">orientation</span><span class="o">=</span><span class="s1">&#39;vertical&#39;</span><span class="p">,</span> <span class="n">shrink</span><span class="o">=</span><span class="mf">0.9</span><span class="p">)</span>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;$\log_</span><span class="si">{10}</span><span class="s1"> M_{\star}$ [M$_{\odot}$]&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
Expand Down
Loading

0 comments on commit 2363afc

Please sign in to comment.