Skip to content

Commit

Permalink
updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfried (Mac) committed Dec 19, 2023
1 parent 86a56e8 commit f0fca97
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 15 deletions.
20 changes: 13 additions & 7 deletions source/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP/LAM <wilfried.mercier@ilam.fr>
Configuration script for Sphinx documentation.
"""
Expand All @@ -16,7 +16,7 @@ def skip(app, what, name, obj, would_skip, options):
###################################################

project = 'pixSED'
copyright = '2023, Wilfried Mercier'
copyright = '2022-2024, Wilfried Mercier'
author = 'Wilfried Mercier'
show_authors = True

Expand All @@ -43,9 +43,6 @@ def skip(app, what, name, obj, would_skip, options):
# Options for HTML output #
#######################################################

#html_theme = 'karma_sphinx_theme'
#html_theme = "sphinxawesome_theme"
# html_logo = "path/to/my/logo.png"
html_theme = "pydata_sphinx_theme"


Expand All @@ -70,8 +67,17 @@ def skip(app, what, name, obj, would_skip, options):
"type": "fontawesome",
}],

"announcement" : "Support for LePhare is currently deprecated as it relies on the old Fortran version. Please use Cigale instead.",
"show_nav_level" : 2
"logo": {

# Alt text for blind people
"alt_text" : "pixSED documentation - Home",
"text" : "pixSED",
"image_light" : "_static/logo1.png",
"image_dark" : "_static/logo1.png",
},

"announcement" : "Support for LePhare is currently deprecated as it relies on the old Fortran version. Please use Cigale instead.",
"show_nav_level" : 2
}

# Add sypport for custom css file
Expand Down
96 changes: 95 additions & 1 deletion source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,98 @@ Both :py:class:`~.CigaleOutput` and :py:class:`~.LePhareOutput` have a utility c
output.link(flist)
image = output.toImage('bayes.stellar.m_star')
where :python:`output` is the :py:class:`~.CigaleOutput` or :py:class:`~.LePhareOutput` object from above and :python:`flist` is the :py:class:`~.FilterList` object created :ref:`here <referenceToFilterList>`.
where :python:`output` is the :py:class:`~.CigaleOutput` or :py:class:`~.LePhareOutput` object from above and :python:`flist` is the :py:class:`~.FilterList` object created :ref:`here <referenceToFilterList>`.

We can now generate a resolved stellar mass 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))
plt.imshow(np.log10(image.to('Msun').value), origin='lower', cmap='rainbow', vmin=6)
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}$ M$_{\star}$ [M$_{\odot}$]', size=13)
plt.show()
.. jupyter-execute::
:hide-code:

import os.path as opath
from astropy.io import fits
import pixSED as SED
import numpy as np

from matplotlib import rc
import matplotlib as mpl
import matplotlib.pyplot as plt

# Define data file names
galName = '1' # Galaxy number
zeropoints = [25.68, 26.51, 25.69, 25.94, 24.87, 26.27, 26.23, 26.45, 25.94] # HST zeropoints
redshift = 0.622 # Redshift of the galaxy
bands = ['435', '606', '775', '814', '850', '105', '125', '140', '160'] # Bands
band_names = ['F435W', 'F606W', 'F775W', 'F814W', 'F850LP', 'F105W', 'F125W', 'F140W', 'F160W']

dataFiles = [] # Flux maps
data2Files = [] # Flux maps convolved by the PSF squared
varFiles = [] # Variance maps

for band in bands:

file = opath.abspath(opath.join('example', 'data', f'{galName}_{band}.fits'))
dataFiles.append(file)

file2 = opath.abspath(opath.join('example', 'data', f'{galName}_{band}_PSF2.fits'))
data2Files.append(file2)

vfile = opath.abspath(opath.join('example', 'data', f'{galName}_{band}_var.fits'))
varFiles.append(vfile)

# Get mask file
mfile = opath.abspath(opath.join('example', 'data', f'{galName}_mask.fits'))
with fits.open(mfile) as hdul:
mask = hdul[0].data == 0

### 1. Generate a FilterList object ###
filts = []
for band, data, data2, var, zpt in zip(bands, dataFiles, data2Files, varFiles, zeropoints):
filts.append(SED.Filter(band, data, var, zpt, file2=data2, verbose=False))

flist = SED.FilterList(filts, mask, code=SED.SEDcode.CIGALE, redshift=redshift)

### 2. Update data table and add Poisson noise (texpFac != 0) ###
flist.genTable(cleanMethod=SED.CleanMethod.ZERO, texpFac=1)

### 6. Generate a resolved stellar mass map ###
output = SED.CigaleOutput(opath.join('example', galName, 'out', 'results.fits'))
output.link(flist)

mass_star = np.log10(output.toImage('bayes.stellar.m_star').to('Msun').value)

### 7. Plot ###
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))
ret = plt.imshow(mass_star, origin='lower', cmap='rainbow', vmin=6)
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}$ M$_{\star}$ [M$_{\odot}$]', size=13)
plt.show()
16 changes: 9 additions & 7 deletions source/poisson.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where :math:`\tilde S` is the input image convolved by the square of the PSF (an
Practical implementation
------------------------

If Poisson noise is missing from the input variance map, this code will assume that the variance corresponds to :math:`\tilde \sigma^2`. To add Poisson noise, the first step is to provide the name of a file that contains :math:`\tilde S`, that is the data convolved by the square of the PSF, when creating the :py:class:`~.Filter` objects:
If Poisson noise is missing from the input variance map, this code will assume that the variance map provided by the user corresponds to :math:`\tilde \sigma^2`. To add Poisson noise, the first step is to provide the name of a file that contains :math:`\tilde S`, that is the data convolved by the square of the PSF, when creating the :py:class:`~.Filter` objects:

.. code:: python
Expand All @@ -67,7 +67,7 @@ Because this code was developed with HST images in mind, it assumes that the inp
* If :math:`\tilde S` is the signal in :math:`e^-\,s^{-1}`, then its value in :math:`e^-` must be given by :math:`\tilde S \times T_e`.
* If :math:`{\rm Var} [S']` is the total variance in :math:`e^-\,s^{-2}`, then its value in :math:`e^-` must be given by :math:`{\rm Var} [S'] \times T_e^2`.

Therefore, using the expression for :math:`{\rm Var} [S']` and the conversions between :math:`e^-` and :math:`e^-\,s^{-2}` given above, we find that the total variance in :math:`e^-\,s^{-1}` writes
Therefore, using the expression for :math:`{\rm Var} [S']` and the conversions between :math:`e^-` and :math:`e^-\,s^{-2}` given above, we find that the total variance in :math:`e^-\,s^{-2}` writes

.. math::
Expand All @@ -84,19 +84,21 @@ The methods :py:meth:`~.FilterList.setCode` or :py:meth:`~.FilterList.genTable`
flist.genTable(texpFac=10)
In this example, the exposure time will be divided by a factor of 10 when computing the Poisson noise contribution to the total variance. If :python:`texpFac` is equal to 0, no Poisson noise will be added.
will divide the exposure time by a factor of 10 when computing the Poisson noise contribution to the total variance. If :python:`texpFac` is equal to 0, no Poisson noise will be added.

This argument can be used to properly handle Poisson noise with data that are not in :math:`e^-\,s^{-1}`. Indeed, let us assume that the data are in an arbitrary unit :math:`u`, which can be converted to :math:`e^-\,s^{-1}` with a scale factor :math:`f` (i.e. :math:`S [u] = f \times S [e^-\,s^{-1}]`). Then,

* If :math:`\tilde \sigma^2` is the background variance in unit :math:`u`, its value in :math:`e^-` must be given by :math:`\tilde \sigma^2 \times T_e^2 / f^2`
* If :math:`\tilde \sigma^2` is the background variance in unit :math:`u^2`, its value in :math:`e^-` must be given by :math:`\tilde \sigma^2 \times T_e^2 / f^2`
* If :math:`\tilde S` is the signal in unit :math:`u`, then its value in :math:`e^-` must be given by :math:`\tilde S \times T_e / f`.
* If :math:`{\rm Var} [S']` is the total variance in unit :math:`u`, then its value in :math:`e^-` must be given by :math:`{\rm Var} [S'] \times T_e^2 / f^2`.
* If :math:`{\rm Var} [S']` is the total variance in unit :math:`u^2`, then its value in :math:`e^-` must be given by :math:`{\rm Var} [S'] \times T_e^2 / f^2`.

Following the same logic as in :ref:`this section <referenceToes>`, the total variance in unit :math:`u` writes
Following the same logic as in :ref:`the previous section <referenceToes>`, the total variance in unit :math:`u^2` writes

.. math::
{\rm Var} [S'] (x, y) = \tilde \sigma^2 (x, y) + f \times \tilde S (x, y) / T_e.
{\rm Var} [S'] (x, y) = \tilde \sigma^2 (x, y) + f \times \tilde S (x, y) / T_e,
where :math:`\tilde \sigma^2` is the background variance map in unit :math:`u^2` and :math:`\tilde S` is the input data convolved by the square of the PSF in unit :math:`u`.

Thus, the keyword argument :python:`texpFac` can be used as a conversion factor to properly compute the contribution of the Poisson noise to the total variance.

Expand Down

0 comments on commit f0fca97

Please sign in to comment.