| 1 |
.. _pysynphot-using: |
| 2 |
|
| 3 |
######## |
| 4 |
Overview |
| 5 |
######## |
| 6 |
|
| 7 |
There are two basic objects in **pysynphot**: |
| 8 |
|
| 9 |
* :ref:`pysynphot-spectrum` |
| 10 |
* :ref:`pysynphot-bandpass` |
| 11 |
|
| 12 |
A source spectrum can be created from: |
| 13 |
|
| 14 |
* FITS or ASCII table file |
| 15 |
* Wavelength and flux arrays |
| 16 |
* Pre-defined analytic forms (:ref:`blackbody <pysynphot-planck-law>`, |
| 17 |
:ref:`flat <pysynphot-flat-spec>`, |
| 18 |
:ref:`Gaussian <pysynphot-gaussian>`, or |
| 19 |
:ref:`power-law <pysynphot-powerlaw>`) |
| 20 |
|
| 21 |
A bandpass can be created from: |
| 22 |
|
| 23 |
* FITS or ASCII table file |
| 24 |
* Wavelength and transmission arrays |
| 25 |
* Pre-defined analytic forms (:ref:`box <pysynphot-box-bandpass>`) |
| 26 |
* :ref:`Observation mode <pysynphot-obsmode-bandpass>` string expression |
| 27 |
(e.g., ``"acs,wfc1,f555w"``) |
| 28 |
|
| 29 |
A source spectrum can be: |
| 30 |
|
| 31 |
* :ref:`Added to another source spectrum <pysynphot-composite-spectrum>` |
| 32 |
* :ref:`Multiplied by a constant or a bandpass <pysynphot-composite-spectrum>` |
| 33 |
* :ref:`Redshifted <pysynphot-redshift>` |
| 34 |
* :ref:`Normalized <pysynphot-renorm>` |
| 35 |
* Changed to different :ref:`units <pysynphot-units>` (both wavelength and flux) |
| 36 |
|
| 37 |
A bandpass can be: |
| 38 |
|
| 39 |
* :ref:`Multiplied by a constant, another bandpass, or a source spectrum <pysynphot-composite-spectrum>` |
| 40 |
* Change :ref:`units <pysynphot-units>` (wavelength only) |
| 41 |
|
| 42 |
Flux (for source spectrum) and throughput (for bandpass) values are not |
| 43 |
actually calculated they are sampled. Evaluation on an as-needed basis |
| 44 |
enables accurate sampling, especially for asymptotic curves (e.g., power-law) |
| 45 |
and :ref:`composite spectra <pysynphot-composite-spectrum>`. |
| 46 |
|
| 47 |
Both source spectrum and bandpass can be written out to FITS or ASCII tables |
| 48 |
(see :ref:`pysynphot-io`). |
| 49 |
|
| 50 |
An :ref:`observation <pysynphot-observation>` can be created using a |
| 51 |
source spectrum and a bandpass. |
| 52 |
An observation is a special kind of spectrum that enables effective stimulus |
| 53 |
(including count rate) and wavelength calculations. |
| 54 |
It has two different datasets: |
| 55 |
|
| 56 |
* As defined by the native wavelength set, which is constructed when combining |
| 57 |
the source spectrum and the bandpass. |
| 58 |
* As defined by the binned wavelength set, which uses the optimal binning for |
| 59 |
the detector (as used by its |
| 60 |
:meth:`~pysynphot.observation.Observation.countrate` method). |
| 61 |
|
| 62 |
While units can be changed, unless explicitly stated otherwise, all calculations |
| 63 |
are done in pre-defined internal units: |
| 64 |
|
| 65 |
* Angstrom for wavelength |
| 66 |
* ``photlam`` for flux |
| 67 |
|
| 68 |
Below are some items that are commonly mentioned in **pysynphot**: |
| 69 |
|
| 70 |
* ``obsmode`` - Passband created from a specific HST instrument configuration, |
| 71 |
a.k.a. observation mode. |
| 72 |
* ``form`` - Flux unit of the output data. For example, ``flam``, counts, |
| 73 |
or ``obmag``. |
| 74 |
* ``waveset`` - Wavelength array on which passband and spectrum will be |
| 75 |
calculated. |
| 76 |
* ``ref`` - Reference data parameters, which include graph, component, and |
| 77 |
thermal tables, telecope collecting area, and default wavelength set. |
| 78 |
To access them, use :func:`~pysynphot.refs.setref` or |
| 79 |
:func:`~pysynphot.refs.showref`. |
| 80 |
They are analogous to ``refdata`` in IRAF STSDAS SYNPHOT. |
| 81 |
|
| 82 |
|
| 83 |
.. _pysynphot-primary-passband: |
| 84 |
|
| 85 |
Passband and Spectral Computations |
| 86 |
================================== |
| 87 |
|
| 88 |
The tables below summarize some main functionality of **pysynphot**. |
| 89 |
These are only for quick reference. Detailed explanations are available |
| 90 |
in their respective sections in other parts of this document. |
| 91 |
|
| 92 |
**Create a passband:** |
| 93 |
|
| 94 |
+-------------------------------------+----------------------------------------+ |
| 95 |
|Command |Description | |
| 96 |
+=====================================+========================================+ |
| 97 |
|bp = S.FileBandpass(filename) |Load from file. | |
| 98 |
+-------------------------------------+----------------------------------------+ |
| 99 |
|bp = S.ObsBandpass(obsmode) |HST observation mode. | |
| 100 |
+-------------------------------------+----------------------------------------+ |
| 101 |
|bp = S.Box(mu, width) |Box centered at ``mu`` with given width.| |
| 102 |
+-------------------------------------+----------------------------------------+ |
| 103 |
|
| 104 |
.. _pysynphot-passband-parameters: |
| 105 |
|
| 106 |
**Calculate bandpass parameters:** |
| 107 |
|
| 108 |
+--------------------+----------------------------------------------------------------------------+ |
| 109 |
|Command |Description | |
| 110 |
+====================+============================================================================+ |
| 111 |
|bp.avgwave() |Average wavelength of bandpass. | |
| 112 |
+--------------------+----------------------------------------------------------------------------+ |
| 113 |
|bp.efficiency() |Dimensionless efficiency. | |
| 114 |
+--------------------+----------------------------------------------------------------------------+ |
| 115 |
|bp.equivwidth() |Equivalent width of passband. | |
| 116 |
+--------------------+----------------------------------------------------------------------------+ |
| 117 |
|bp.rectwidth() |Rectangular width of passband. | |
| 118 |
+--------------------+----------------------------------------------------------------------------+ |
| 119 |
|bp.rmswidth() |RMS band width as in | |
| 120 |
| |:ref:`Koornneef et al. 1986 <synphot-ref-koornneef1986>` (page 836). | |
| 121 |
+--------------------+----------------------------------------------------------------------------+ |
| 122 |
|bp.throughput.max() |Peak throughput of passband. | |
| 123 |
+--------------------+----------------------------------------------------------------------------+ |
| 124 |
|bp.pivot() |Pivot wavelength of passband. | |
| 125 |
+--------------------+----------------------------------------------------------------------------+ |
| 126 |
|bp.unit_response() |Unit response; flux (in ``flam``) that produces 1 count/second in the | |
| 127 |
| |passband. | |
| 128 |
+--------------------+----------------------------------------------------------------------------+ |
| 129 |
|bp.thermback() |Expose the thermal background calculation presently hidden in | |
| 130 |
| |`~pysynphot.observationmode`. Only bandpasses for which thermal | |
| 131 |
| |information has been supplied in the graph table supports this method. | |
| 132 |
+--------------------+----------------------------------------------------------------------------+ |
| 133 |
|bp.photbw() |RMS band width compatible with SYNPHOT calculation. | |
| 134 |
+--------------------+----------------------------------------------------------------------------+ |
| 135 |
|
| 136 |
.. _pysynphot-spectra-creation: |
| 137 |
|
| 138 |
**Create a spectrum:** |
| 139 |
|
| 140 |
+------------------------------------------------+--------------------------------------------+ |
| 141 |
|Command |Description | |
| 142 |
+================================================+============================================+ |
| 143 |
|sp = S.FileSpectrum(filename) |Load from file. | |
| 144 |
+------------------------------------------------+--------------------------------------------+ |
| 145 |
|sp = S.BlackBody(Teff) |Blackbody spectrum with specified | |
| 146 |
| |temperature, ``Teff``, in Kelvin. The flux | |
| 147 |
| |of the spectrum is normalized to a star of | |
| 148 |
| |solar radius at a distance of 1 kpc. | |
| 149 |
+------------------------------------------------+--------------------------------------------+ |
| 150 |
|sp = S.FlatSpectrum(value[, fluxunits]) |Flat spectrum with constant flux of given | |
| 151 |
| |value and optionally flux unit. | |
| 152 |
+------------------------------------------------+--------------------------------------------+ |
| 153 |
|sp = S.PowerLaw(refval, expon[, fluxunits]) |Power-law spectrum of the form | |
| 154 |
| |:math:`f = (\lambda / refval)^{expon}`. | |
| 155 |
| |The spectrum is normalized to a flux of 1 | |
| 156 |
| |(in given unit) at ``refval`` (in Angstrom).| |
| 157 |
+------------------------------------------------+--------------------------------------------+ |
| 158 |
|sp = S.GaussianSource(totflux, mu, fwhm[, |Emission line centered on wavelength, ``mu``| |
| 159 |
|fluxunits]) |, with a Gaussian profile that has given | |
| 160 |
| |FWHM and total flux in given unit. | |
| 161 |
+------------------------------------------------+--------------------------------------------+ |
| 162 |
|sp = S.Icat(catalog, key1, ...) |Interpolate a spectrum from given catalog, | |
| 163 |
| |selected by given search criteria | |
| 164 |
| |(``key1, ...``) that could be temperature, | |
| 165 |
| |surface gravity, or metallicity. | |
| 166 |
+------------------------------------------------+--------------------------------------------+ |
| 167 |
|sp = S.ArraySpectrum(wave, flux [, waveunits, |Create from given wavelength and flux | |
| 168 |
|fluxunits, name]) |arrays, in given units and name. | |
| 169 |
+------------------------------------------------+--------------------------------------------+ |
| 170 |
|
| 171 |
.. _pysynphot-observation-creation: |
| 172 |
|
| 173 |
**Create an observation:** |
| 174 |
|
| 175 |
+---------------------------+---------------------------------------------------+ |
| 176 |
|Command |Description | |
| 177 |
+===========================+===================================================+ |
| 178 |
|obs = S.Observation(sp, bp)|Given spectrum as observed through given bandpasss.| |
| 179 |
+---------------------------+---------------------------------------------------+ |
| 180 |
|
| 181 |
.. _pysynphot-observation-parameters: |
| 182 |
|
| 183 |
**Calculate observational parameters:** |
| 184 |
|
| 185 |
+------------------------+-----------------------------------------------------------------------+ |
| 186 |
|Command |Description | |
| 187 |
+========================+=======================================================================+ |
| 188 |
|obs.countrate() |Calculate the response of a HST instrument for the given model spectrum| |
| 189 |
| |and passband. | |
| 190 |
+------------------------+-----------------------------------------------------------------------+ |
| 191 |
|obs.effstim(fluxunit) |Calculate the effective stimulus in given unit. | |
| 192 |
+------------------------+-----------------------------------------------------------------------+ |
| 193 |
|obs.efflam() |Calculate the effective wavelength. This is performed on the binned | |
| 194 |
| |wavelength set by default. | |
| 195 |
+------------------------+-----------------------------------------------------------------------+ |
| 196 |
|obs.efflam(binned=False)|Calculate the effective wavelength. This is performed on the native | |
| 197 |
| |wavelength set. | |
| 198 |
+------------------------+-----------------------------------------------------------------------+ |
| 199 |
|
| 200 |
.. _pysynphot-spectra-modify: |
| 201 |
|
| 202 |
**Modify a spectrum:** |
| 203 |
|
| 204 |
+------------------------------------+--------------------------------------------+ |
| 205 |
|Command |Description | |
| 206 |
+====================================+============================================+ |
| 207 |
|sp2 = sp.renorm(value, fluxunit, bp)|Renormalize the spectrum to given flux value| |
| 208 |
| |in given unit over the given passband. The | |
| 209 |
| |evaluator computes the integral of the | |
| 210 |
| |spectrum over the specified passband and | |
| 211 |
| |rescales it by appropriate factor, forcing | |
| 212 |
| |the integral to have the requested | |
| 213 |
| |value. | |
| 214 |
+------------------------------------+--------------------------------------------+ |
| 215 |
|sp2 = sp.redshift(z) |Redshift a spectrum by the amount, ``z``. | |
| 216 |
+------------------------------------+--------------------------------------------+ |
| 217 |
|sp2 = sp * S.Extinction(ebv, law) |Apply an extinction of given :math:`E(B-V)` | |
| 218 |
| |using the selected extinction law. | |
| 219 |
+------------------------------------+--------------------------------------------+ |
| 220 |
|
| 221 |
.. _pysynphot-utility-task: |
| 222 |
|
| 223 |
**Utility tasks:** |
| 224 |
|
| 225 |
+---------------------------------------+-------------------------------------------------------+ |
| 226 |
|Command |Description | |
| 227 |
+=======================================+=======================================================+ |
| 228 |
|wv = S.Waveset(minwave, maxwave, dwave)|Generate a wavelength set with given min, max, and | |
| 229 |
| |delta. Alternatively, this can also be done using | |
| 230 |
| |`numpy`. | |
| 231 |
+---------------------------------------+-------------------------------------------------------+ |
| 232 |
|S.showref() |Show the current settings for graph, component, and | |
| 233 |
| |thermal component tables, in addition to wavelength set| |
| 234 |
| |and telescope collecting area. | |
| 235 |
+---------------------------------------+-------------------------------------------------------+ |
| 236 |
|S.setref(...) |Override the default values by setting any or all of | |
| 237 |
| |the supported keywords, or reset to software default if| |
| 238 |
| |no parameters are given. | |
| 239 |
+---------------------------------------+-------------------------------------------------------+ |
| 240 |
|bp.showfiles() |Print all the files that went into generating the | |
| 241 |
| |passband. | |
| 242 |
+---------------------------------------+-------------------------------------------------------+ |
| 243 |
|bp.check_overlap(sp) |Check whether the wavelength range of ``sp`` is defined| |
| 244 |
| |everywhere of that in ``bp``. The result can be | |
| 245 |
| |``"full"``, ``"partial"``, or ``"none"``. | |
| 246 |
+---------------------------------------+-------------------------------------------------------+ |
| 247 |
|
| 248 |
|
| 249 |
.. _pysynphot-io: |
| 250 |
|
| 251 |
File I/O |
| 252 |
======== |
| 253 |
|
| 254 |
Source spectrum and bandpass can be read from FITS or ASCII table via |
| 255 |
`~pysynphot.spectrum.FileSourceSpectrum` (also callable as |
| 256 |
``pysynphot.FileSpectrum``) and `~pysynphot.spectrum.FileSpectralElement` |
| 257 |
(also callable as ``pysynphot.FileBandpass``), respectively. |
| 258 |
|
| 259 |
For FITS table, data is extracted from extension 1, where the first column |
| 260 |
contains wavelength values, and the second flux (for source spectrum) or |
| 261 |
throughput (for bandpass). The extension header must contain the following |
| 262 |
keywords: |
| 263 |
|
| 264 |
* ``TUNIT1`` set to |
| 265 |
:ref:`wavelength unit name recognized by pysynphot <pysynphot-wave-units>`. |
| 266 |
* ``TUNIT2`` set to |
| 267 |
:ref:`flux unit name recognized by pysynphot <pysynphot-flux-units>` |
| 268 |
(source spectrum only). |
| 269 |
* ``TTYPE1`` set to "WAVELENGTH". |
| 270 |
* ``TTYPE2`` set to "FLUX" (for source spectrum; could be modified with |
| 271 |
``fluxname`` keyword during object initialization) or "THROUGHPUT" (for |
| 272 |
bandpass; could be modified with ``thrucol`` keyword during object |
| 273 |
initialization). |
| 274 |
|
| 275 |
In an ASCII table, wavelength and flux/throughput values must be in the first |
| 276 |
and the second columns, respectively. Wavelength must be in Angstrom. For source |
| 277 |
spectrum, flux must be in ``flam``. All values will be read in as |
| 278 |
double-precision floating point. The ASCII file may contain blank or |
| 279 |
comment lines (defined as any lines starting with ``"#"``). |
| 280 |
|
| 281 |
For source spectrum, regardless of file format, flux with negative values will |
| 282 |
be automatically set to zero, unless ``keepneg=True`` is set during |
| 283 |
initialization. |
| 284 |
|
| 285 |
Both source spectrum and bandpass can be written out to a FITS table with their |
| 286 |
respective ``writefits()`` attribute, which provide options to overwrite existing |
| 287 |
file with the same name, remove redundant zero flux/throughput rows from both |
| 288 |
ends, set floating point precision, and add extra information to the primary |
| 289 |
header in extension 0. |
| 290 |
|
| 291 |
|
| 292 |
Examples |
| 293 |
======== |
| 294 |
|
| 295 |
Read a source spectrum from FITS table: |
| 296 |
|
| 297 |
>>> sp = S.FileSpectrum('/some/place/spectrum.fits') |
| 298 |
|
| 299 |
Read a source spectrum from ASCII table. |
| 300 |
Wavelength and flux values must already be in the units of Angstrom and |
| 301 |
``flam``, respectively: |
| 302 |
|
| 303 |
>>> sp = S.FileSpectrum('/some/place/spectrum.dat') |
| 304 |
|
| 305 |
Write a source spectrum to FITS table. Options are set to overwrite any existing |
| 306 |
file, trim redundant rows with zero flux at both ends, force double precision, |
| 307 |
and add a new keyword ``MYKEY1`` to primary header: |
| 308 |
|
| 309 |
>>> sp.writefits('/some/place/spectrum.fits', clobber=True, trimzero=True, |
| 310 |
... precision='double', hkeys={'MYKEY1':42}) |
| 311 |
|
| 312 |
Read a bandpass from FITS table: |
| 313 |
|
| 314 |
>>> bp = S.FileBandpass('/some/place/bandpass.fits') |
| 315 |
|
| 316 |
Read a bandpass from ASCII table. Wavelength values must already be in the unit |
| 317 |
of Angstrom: |
| 318 |
|
| 319 |
>>> bp = S.FileBandpass('/some/place/bandpass.dat') |
| 320 |
|
| 321 |
Write a bandpass to FITS table with default options: |
| 322 |
|
| 323 |
>>> bp.writefits('/some/place/bandpass.fits') |
| 324 |
|
| 325 |
Plot a bandpass: |
| 326 |
|
| 327 |
>>> plt.plot(bp.wave, bp.throughput) |
| 328 |
|
| 329 |
Plot a source spectrum: |
| 330 |
|
| 331 |
>>> plt.plot(sp.wave, sp.flux) |