-
Notifications
You must be signed in to change notification settings - Fork 0
/
photometry.py
executable file
·117 lines (82 loc) · 4.87 KB
/
photometry.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP/LAM <[email protected]> & Maxime Tarrasse - IRAP <[email protected]>
Photometry functions.
"""
from typing import Union, Tuple
import numpy as np
import astropy.units as u
def countToMag(data: Union[float, np.ndarray], 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::
d [{\rm{mag}}] = -2.5 \log_{10} d [{\rm{e^{-}/s}}] + {\rm{zpt}}
where :math:`d` is the data and :math:`\rm{zpt}` is the magnitude zeropoint. The error is given by
.. math::
\Delta d [{\rm{mag}}] = 1.08 \Delta d [{\rm{e^{-}/s}}] / d [{\rm{e^{-}/s}}]
: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: (: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: 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: :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: flux in :math:`\rm{erg/cm^2/s/Hz}` and associated error
: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 FluxToCount(flux: Union[float, np.ndarray, u.Quantity], eflux: Union[float, np.ndarray, u.Quantity], zeropoint: float) -> Tuple[Union[float, np.ndarray], Union[float, np.ndarray]]:
r'''
.. codeauthor:: Hugo Plombat - LUPM <[email protected]> & Wilfried Mercier - IRAP <[email protected]>
Convert flux values and their associated error into dta count in :math:`\rm{e^{-}/s}`.
:param flux: flux in :math:`\rm{erg/cm^2/s/Hz}`. If provided as an Astropy Quantity it will be parsed to this unit.
:type flux: :python:`float`, `ndarray`_ [:python:`float`] or `Astropy Quantity`_
:param eflux: std errors in :math:`\rm{erg/cm^2/s/Hz}`. If provided as an Astropy Quantity it will be parsed to this unit.
:type eflux: :python:`float`, `ndarray`_ [:python:`float`] or `Astropy Quantity`_
:param zeropoint: zeropoint associated to the data
:type zeropoint: :python:`float`
:returns: data count in :math:`\rm{e^{-}/s}` and associated error
:rtype: (:python:`float` or `ndarray`_ [:python:`float`], :python:`float` or `ndarray`_ [:python:`float`])
'''
if isinstance(flux, u.Quantity):
flux = flux.to( 'erg/(s*Hz*cm^2)').value
eflux = eflux.to('erg/(s*Hz*cm^2)').value
fac = 10**((zeropoint+48.6)/2.5)
count = flux * fac
err = flux * fac
return count, err
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