| 1 |
.. _pysynphot-units: |
| 2 |
|
| 3 |
******************* |
| 4 |
Units and Constants |
| 5 |
******************* |
| 6 |
|
| 7 |
**pysynphot** understands some :ref:`pysynphot-flux-units` and |
| 8 |
:ref:`pysynphot-wave-units` that are commonly used in astronomy. |
| 9 |
Unit conversion can be easily done within spectral objects by using |
| 10 |
:meth:`pysynphot.spectrum.SourceSpectrum.convert` (for flux and wavelength) and |
| 11 |
:meth:`pysynphot.spectrum.SpectralElement.convert` (wavelength only, as |
| 12 |
throughput is unitless) methods. As in IRAF STSDAS SYNPHOT, only lowercase |
| 13 |
unit names are valid. |
| 14 |
|
| 15 |
Unless explicitly stated otherwise in API documentations, all calculations are |
| 16 |
done in the following internal units first, and then presented in |
| 17 |
user-specified units: |
| 18 |
|
| 19 |
* Angstrom for wavelength |
| 20 |
* ``photlam`` for flux |
| 21 |
|
| 22 |
|
| 23 |
.. _pysynphot-constants: |
| 24 |
|
| 25 |
Constants |
| 26 |
========= |
| 27 |
|
| 28 |
These are the constants used in unit conversion: |
| 29 |
|
| 30 |
========================== ====================== =============== |
| 31 |
Constant Description Value |
| 32 |
========================== ====================== =============== |
| 33 |
``pysynphot.units.C`` Speed of light, *c* |speed_c_math| |
| 34 |
``pysynphot.units.H`` Planck's constant, *h* |planck_h_math| |
| 35 |
``pysynphot.units.ABZERO`` ``abmag`` zero point -48.6 mag |
| 36 |
``pysynphot.units.STZERO`` ``stmag`` zero point -21.1 mag |
| 37 |
========================== ====================== =============== |
| 38 |
|
| 39 |
.. |speed_c_math| replace:: :math:`2.99792458 \times 10^{18} \; \AA \; \mathrm{s}^{-1}` |
| 40 |
.. |planck_h_math| replace:: :math:`6.62620 \times 10^{-27} \; \mathrm{ergs} \; \mathrm{s}` |
| 41 |
|
| 42 |
|
| 43 |
.. _pysynphot-flux-units: |
| 44 |
|
| 45 |
Flux Units |
| 46 |
========== |
| 47 |
|
| 48 |
The recognized flux units for source spectrum and observation objects are as |
| 49 |
tabulated below. For IRAF STSDAS SYNPHOT users, the unit name is equivalent to |
| 50 |
``form``, which has become ``fluxunits`` in **pysynphot** (see |
| 51 |
:ref:`pysynphot-units-examples`). Most calculation and sampling results are |
| 52 |
presented in the given flux unit (e.g., |
| 53 |
:meth:`~pysynphot.spectrum.SourceSpectrum.sample` and |
| 54 |
:meth:`~pysynphot.observation.Observation.effstim`). |
| 55 |
Since all internal flux calculations are done using ``photlam``, no special |
| 56 |
steps are necessary when an operation is done on source spectra with different |
| 57 |
flux units. |
| 58 |
:ref:`pysynphot-units-counts-mags` further explains the units of ``vegamag``, |
| 59 |
``abmag``, ``stmag``, ``obmag``, and counts. The rest of the supported |
| 60 |
flux units should be self-evident. |
| 61 |
|
| 62 |
+-------+--------------------------+--------------+ |
| 63 |
|Name |Class Object |Unit | |
| 64 |
+=======+==========================+==============+ |
| 65 |
|photlam|`~pysynphot.units.Photlam`||photlam_math|| |
| 66 |
+-------+--------------------------+--------------+ |
| 67 |
|photnu |`~pysynphot.units.Photnu` ||photnu_math| | |
| 68 |
+-------+--------------------------+--------------+ |
| 69 |
|flam |`~pysynphot.units.Flam` ||flam_math| | |
| 70 |
+-------+--------------------------+--------------+ |
| 71 |
|fnu |`~pysynphot.units.Fnu` ||fnu_math| | |
| 72 |
+-------+--------------------------+--------------+ |
| 73 |
|stmag |`~pysynphot.units.STMag` ||stmag_math| | |
| 74 |
+-------+--------------------------+--------------+ |
| 75 |
|abmag |`~pysynphot.units.ABMag` ||abmag_math| | |
| 76 |
+-------+--------------------------+--------------+ |
| 77 |
|obmag |`~pysynphot.units.OBMag` ||obmag_math| | |
| 78 |
+-------+--------------------------+--------------+ |
| 79 |
|vegamag|`~pysynphot.units.VegaMag`||vegamag_math|| |
| 80 |
+-------+--------------------------+--------------+ |
| 81 |
|count |`~pysynphot.units.Counts` ||counts_math| | |
| 82 |
| | | | |
| 83 |
|counts | | | |
| 84 |
+-------+--------------------------+--------------+ |
| 85 |
|jy |`~pysynphot.units.Jy` ||jy_math| | |
| 86 |
+-------+--------------------------+--------------+ |
| 87 |
|mjy |`~pysynphot.units.mJy` ||mjy_math| | |
| 88 |
+-------+--------------------------+--------------+ |
| 89 |
|ujy |`~pysynphot.units.muJy` ||mujy_math| | |
| 90 |
| | | | |
| 91 |
|mujy | | | |
| 92 |
| | | | |
| 93 |
|microjy| | | |
| 94 |
+-------+--------------------------+--------------+ |
| 95 |
|njy |`~pysynphot.units.nJy` ||njy_math| | |
| 96 |
| | | | |
| 97 |
|nanojy | | | |
| 98 |
+-------+--------------------------+--------------+ |
| 99 |
|
| 100 |
.. |photlam_math| replace:: :math:`\mathrm{photon} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \; \AA^{-1}` |
| 101 |
.. |photnu_math| replace:: :math:`\mathrm{photon} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \; \mathrm{Hz}^{-1}` |
| 102 |
.. |flam_math| replace:: :math:`\mathrm{erg} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \; \AA^{-1}` |
| 103 |
.. |fnu_math| replace:: :math:`\mathrm{erg} \; \mathrm{s}^{-1} \mathrm{cm}^{-2} \mathrm{Hz}^{-1}` |
| 104 |
.. |stmag_math| replace:: :math:`-2.5 \times \log(\mathrm{flam}) - 21.1` |
| 105 |
.. |abmag_math| replace:: :math:`-2.5 \times \log(\mathrm{fnu}) - 48.6` |
| 106 |
.. |obmag_math| replace:: :math:`-2.5 \times \log(\mathrm{count})` |
| 107 |
.. |vegamag_math| replace:: :math:`-2.5 \times \log(\mathrm{flux} \; / \; \mathrm{flux}_{\mathrm{Vega}})` |
| 108 |
.. |counts_math| replace:: :math:`\mathrm{photon} \; \mathrm{s}^{-1}` |
| 109 |
.. |jy_math| replace:: :math:`10^{-23} \; \mathrm{erg} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \mathrm{Hz}^{-1}` |
| 110 |
.. |mjy_math| replace:: :math:`10^{-26} \; \mathrm{erg} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \mathrm{Hz}^{-1}` |
| 111 |
.. |mujy_math| replace:: :math:`10^{-29} \; \mathrm{erg} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \mathrm{Hz}^{-1}` |
| 112 |
.. |njy_math| replace:: :math:`10^{-32} \; \mathrm{erg} \; \mathrm{s}^{-1} \; \mathrm{cm}^{-2} \mathrm{Hz}^{-1}` |
| 113 |
|
| 114 |
|
| 115 |
.. _pysynphot-units-counts-mags: |
| 116 |
|
| 117 |
Counts and Magnitudes |
| 118 |
--------------------- |
| 119 |
|
| 120 |
.. |ab_nu| replace:: :math:`\mathrm{AB}_{\nu}` |
| 121 |
.. |st_lam| replace:: :math:`\mathrm{ST}_{\lambda}` |
| 122 |
|
| 123 |
**pysynphot** supports counts and the following magnitude systems: |
| 124 |
|
| 125 |
* ``obmag``, the instrumental magnitude that is the logarithmic form of counts. |
| 126 |
Conversion involving counts and ``obmag`` assumes a |
| 127 |
:ref:`pre-defined telescope collecting area <pysynphot-area>`. |
| 128 |
* ``abmag``, the |ab_nu| magnitude from :ref:`Oke (1974) <synphot-ref-oke1974>`, |
| 129 |
which is based on a constant flux density per unit frequency. |
| 130 |
* ``stmag``, the |st_lam| or Space Telescope magnitude, which is based on a |
| 131 |
constant flux density per unit wavelength. |
| 132 |
* ``vegamag``, which is defined by setting the magnitude of Vega to |
| 133 |
zero in all bands. The :ref:`adopted Vega spectrum <pysynphot-vega-spec>` |
| 134 |
is defined over a wavelength range of 900 Angstroms to 300 microns. |
| 135 |
|
| 136 |
``vegamag`` offers a reasonable approximation to many of the conventional |
| 137 |
photometric systems that use the spectrum of Vega to define |
| 138 |
magnitude zero in one or more passbands. In broadband photometry, the relevant |
| 139 |
passband integral is calculated first for the source spectrum and then again |
| 140 |
for the spectrum of Vega, and the ratio of the two results is converted to a |
| 141 |
magnitude. This would not be a scientifically meaningful option for |
| 142 |
spectrophotometry. |
| 143 |
|
| 144 |
Meanwhile, ``abmag`` and ``stmag`` are appropriate for either spectrophotometry |
| 145 |
or photometry. Their zero point values of 48.60 and 21.10 mag, respectively, are |
| 146 |
chosen for convenience so that Vega has |ab_nu| and |st_lam| magnitudes close |
| 147 |
to 0 in the Johnson *V* passband, as shown in the following figure: |
| 148 |
|
| 149 |
.. figure:: _static/VegaPhotomSys.png |
| 150 |
:width: 600px |
| 151 |
:alt: Standard photometric system |
| 152 |
|
| 153 |
Standard photometric systems generally use the spectrum of Vega to |
| 154 |
define magnitude zero. The spectrophotometric magnitudes |
| 155 |
|ab_nu| and |st_lam| refer instead to spectra of constant :math:`f_{\nu}` |
| 156 |
and :math:`f_{\lambda}`, respectively. Magnitude zero in both systems is |
| 157 |
defined to be the mean flux density of Vega in the Johnson *V* passband. |
| 158 |
Thus all three of the spectra shown here produce the same count rate in |
| 159 |
the Johnson *V* passband. The pivot wavelength of Johnson *V* is defined to |
| 160 |
be the crossing point of the |ab_nu|:math:`= 0` and |st_lam|:math:`= 0` |
| 161 |
spectra. |
| 162 |
|
| 163 |
Because the ``abmag`` and ``stmag`` systems are defined such that they result in |
| 164 |
constant magnitudes for spectra having constant flux per unit frequency and |
| 165 |
wavelength, respectively, they will not provide magnitudes on a conventional |
| 166 |
system, such as *UBVRI*, without first deriving an appropriate transformation |
| 167 |
onto the desired standard system. |
| 168 |
|
| 169 |
``obmag`` and counts are used to predict detected count rates. For instance, |
| 170 |
:meth:`~pysynphot.observation.Observation.countrate` calculates the |
| 171 |
predicted number of detected counts per second integrated over the passband. |
| 172 |
There are two important things to remember concerning this unit: |
| 173 |
|
| 174 |
#. The number of counts per channel depends on the width (in wavelength space) |
| 175 |
of the channel in the wavelength grid that is used. |
| 176 |
As stated above, all flux calculations are done internally in |
| 177 |
the unit of ``photlam``, so when the output unit of counts or ``obmag`` is |
| 178 |
requested, the ``photlam`` values are multiplied by the collecting area of |
| 179 |
the telescope and by the width (in Angstroms) of each channel in the |
| 180 |
wavelength grid. Therefore, in order to accurately predict the number of |
| 181 |
counts per channel for a spectroscopic instrument, it is necessary to use |
| 182 |
a wavelength grid that provides a good match to the dispersion properties |
| 183 |
of the selected instrument mode (see :ref:`pysynphot-wavelength-table`). |
| 184 |
For supported HST instruments, the appropriate wavelength grid will be |
| 185 |
automatically selected. |
| 186 |
#. The unit "counts" refers to the actual detector counts for the FOC, FOS, HRS, |
| 187 |
and HSP instruments. While for the WF/PC-1, WFPC2, NICMOS, WFC3, COS, ACS, |
| 188 |
and STIS instruments, it refers to electrons. In order to obtain counts in |
| 189 |
the unit of data number (DN) for some of the latter instruments, include the |
| 190 |
appropriate keyword for ADC gain, if supported (see |
| 191 |
:ref:`pysynphot-appendixb`). |
| 192 |
|
| 193 |
|
| 194 |
.. _pysynphot-wave-units: |
| 195 |
|
| 196 |
Wavelength Units |
| 197 |
================ |
| 198 |
|
| 199 |
These are the recognized wavelength units for all spectrum objects: |
| 200 |
|
| 201 |
+--------------+--------------------------------+----------------+ |
| 202 |
|Name |Class Object |Unit | |
| 203 |
+==============+================================+================+ |
| 204 |
|m |`~pysynphot.units.Meter` |SI base unit for| |
| 205 |
| | |length | |
| 206 |
|meter | | | |
| 207 |
+--------------+--------------------------------+----------------+ |
| 208 |
|cm |`~pysynphot.units.Cm` ||cm_math| | |
| 209 |
+--------------+--------------------------------+----------------+ |
| 210 |
|mm |`~pysynphot.units.Mm` ||mm_math| | |
| 211 |
+--------------+--------------------------------+----------------+ |
| 212 |
|um |`~pysynphot.units.Micron` ||micron_math| | |
| 213 |
| | | | |
| 214 |
|micron | | | |
| 215 |
| | | | |
| 216 |
|microns | | | |
| 217 |
+--------------+--------------------------------+----------------+ |
| 218 |
|nm |`~pysynphot.units.Nm` ||nm_math| | |
| 219 |
+--------------+--------------------------------+----------------+ |
| 220 |
|angstrom |`~pysynphot.units.Angstrom` ||angstrom_math| | |
| 221 |
| | | | |
| 222 |
|angstroms | | | |
| 223 |
+--------------+--------------------------------+----------------+ |
| 224 |
|1/um |`~pysynphot.units.InverseMicron`||invmicron_math|| |
| 225 |
| | | | |
| 226 |
|inversemicron | | | |
| 227 |
| | | | |
| 228 |
|inversemicrons| | | |
| 229 |
+--------------+--------------------------------+----------------+ |
| 230 |
|hertz |`~pysynphot.units.Hz` ||hz_math| | |
| 231 |
+--------------+--------------------------------+----------------+ |
| 232 |
|
| 233 |
.. |cm_math| replace:: :math:`10^{-2} \; \mathrm{m}` |
| 234 |
.. |mm_math| replace:: :math:`10^{-3} \; \mathrm{m}` |
| 235 |
.. |micron_math| replace:: :math:`10^{-6} \; \mathrm{m}` |
| 236 |
.. |nm_math| replace:: :math:`10^{-9} \; \mathrm{m}` |
| 237 |
.. |angstrom_math| replace:: :math:`10^{-10} \; \mathrm{m}` |
| 238 |
.. |invmicron_math| replace:: :math:`10^{6} \; \mathrm{m}^{-1}` |
| 239 |
.. |hz_math| replace:: :math:`\mathrm{s}^{-1}` |
| 240 |
|
| 241 |
|
| 242 |
.. _pysynphot-units-examples: |
| 243 |
|
| 244 |
Examples |
| 245 |
======== |
| 246 |
|
| 247 |
Create a source spectrum from arrays with default units: |
| 248 |
|
| 249 |
>>> sp = S.ArraySpectrum( |
| 250 |
... np.array([1000, 2000, 3000]), np.array([0.1, 0.2, 0.3])) |
| 251 |
>>> print('{0}, {1}'.format(sp.waveunits.name, sp.fluxunits.name)) |
| 252 |
angstrom, photlam |
| 253 |
|
| 254 |
Convert both wavelength and flux units: |
| 255 |
|
| 256 |
>>> sp.convert('nm') |
| 257 |
>>> sp.convert('flam') |
| 258 |
>>> print('{0}, {1}'.format(sp.waveunits.name, sp.fluxunits.name)) |
| 259 |
nm, flam |
| 260 |
>>> sp.wave |
| 261 |
array([ 100., 200., 300.]) |
| 262 |
>>> sp.flux |
| 263 |
array([ 1.98648479e-12, 1.98648479e-12, 1.98648479e-12]) |
| 264 |
|
| 265 |
To sample the spectrum in user units (i.e., nm and ``flam``), use its |
| 266 |
:meth:`~pysynphot.spectrum.SourceSpectrum.sample` method: |
| 267 |
|
| 268 |
>>> sp.sample(200) |
| 269 |
1.9864847851996004e-12 |
| 270 |
|
| 271 |
To sample the spectrum in internal units (i.e., Angstrom and ``photlam``), |
| 272 |
use its :py:meth:`~object.__call__` method: |
| 273 |
|
| 274 |
>>> sp(2000) |
| 275 |
0.20000000000000001 |