Skip to content

Commit

Permalink
updated photometry functions and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
WilfriedMercier committed Feb 28, 2022
1 parent d4a397e commit b1ec6c7
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions photometry.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <[email protected]>
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <[email protected]> & Maxime Tarrasse - IRAP <[email protected]>
Photometry functions.
"""

import numpy as np
import astropy.units as u
from typing import Union, Tuple
import numpy as np
import astropy.units as u

def countToMag(data, err, zeropoint):
def countToMag(data: Union[float, np.ndaray], err: Union[float, np.ndarray], zeropoint: float) -> Tuple[Union[float, np.ndarray], Union[float, np.ndarray]]:
r'''
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <[email protected]>
Convert data counts and their associated error into AB magnitudes using the formula
.. math::
.. math:: python
d [{\rm{mag}}] = -2.5 \log_{10} d [{\rm{e^{-}/s}}] + {\rm{zpt}}
Expand All @@ -23,36 +26,65 @@ def countToMag(data, err, zeropoint):
\Delta d [{\rm{mag}}] = 1.08 \Delta d [{\rm{e^{-}/s}}] / d [{\rm{e^{-}/s}}]
:param data: data in electron/s
:type data: float or ndarray[float]
:param err: std errors in electron/s
:type err: float or ndarray[foat]
:param float zeropoint: zeropoint associated to the data
:param data: data in :math:`\rm{e^{-1}/s}`
:type data: :python:`float` or `ndarray`_ [:python:`float`]
:param err: std errors in :math:`\rm{e^{-1}/s}`
:type err: :python:`float` or `ndarray`_ [:python:`float`]
:param zeropoint: zeropoint associated to the data
:type zeropoint: :python:`float`
:returns: AB magnitude and associated error
:rtype: float or ndarray[float], float or ndarray[float]
:rtype: (:python:`float` or `ndarray`_ [:python:`float`], :python:`float` or `ndarray`_ [:python:`float`]
'''

mag = -2.5 * np.log10(data) + zeropoint
emag = 1.08 * err/data

return mag, emag

def countToFlux(data, err, zeropoint):
def countToFlux(data: Union[float, np.ndarray], err: Union[float, np.ndarray], zeropoint: float) -> Tuple[u.Quantity, u.Quantity]:
r'''
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <[email protected]>
Convert data counts and their associated error into flux in :math:`\rm{erg/cm^2/s/Hz}`.
:param data: data in :math:`electron/s`
:type data: float or ndarray[float]
:param err: std errors in :math:`electron/s`
:type err: float or ndarray[float]
:param float zeropoint: zeropoint associated to the data
:type data: :python:`float` or `ndarray`_ [:python:`float`]
:param err: std errors in :math:`\rm{e^{-1}/s}`
:type err: :python:`float` or `ndarray`_ [:python`float`]
:param zeropoint: zeropoint associated to the data
:type zeropoint: :python:`float`
:returns: AB magnitude and associated error
:rtype: Astropy Quantity, Astropy Quantity
:rtype: (`Astropy Quantity`_, `Astropy Quantity`_)
'''

flux = u.Quantity(data * 10**(-(zeropoint+48.6)/2.5), unit='erg/(s*Hz*cm^2)')
eflux = u.Quantity(err * 10**(-(zeropoint+48.6)/2.5), unit='erg/(s*Hz*cm^2)')

return flux, eflux

def MagTocount(mag: Union[float, np.ndarray], emag: Union[float, np.ndarray], zeropoint: float) -> Tuple[Union[float, np.ndarray], Union[float, np.ndarray]]:
r'''
.. codeauthor:: Maxime Tarrasse - IRAP <[email protected]>
Converts magnitudes and their associated error into data counts and their associated errors.
:param mag: AB magnitude
:type mag: :python:`float` or `ndarray`_ [:python:`float`]
:param emag: error on AB magnitudes
:type emag: :python:`float` or `ndarray`_ [:python:`float`]
:param zeropoint: zeropoint associated to the data
:type zeropoint: :python:`float`
:returns : data in :math:`\rm{e^{-}/s}` and associated errors
:rtype: (:python:`float` or `ndarray`_ [:python:`float`], :python:`float` or `ndarray`_ [:python:`float`])
'''

data = 10**((zeropoint-mag)/2.5)
err = data*emag/1.08

return data, err



0 comments on commit b1ec6c7

Please sign in to comment.