Debian Codegraph @

doc/source/spectrum.rst

raw
1 .. _pysynphot-spectrum:
2
3 ***************
4 Source Spectrum
5 ***************
6
7 A source spectrum is used to represent astronomical sources, such as stars and
8 galaxies. It can be constructed in
9 :ref:`several different ways <pysynphot-create-source>`.
10 An :ref:`observation <pysynphot-observation>` is a special case of a
11 source spectrum that is convolved with a :ref:`bandpass <pysynphot-bandpass>`.
12
13 A source spectrum has these main components:
14
15 * ``flux``
16 * ``fluxunits`` (see :ref:`pysynphot-flux-units`)
17 * ``isAnalytic`` (This is `True` if the spectrum can be defined by
18 a mathematical formula. For instance, a Gaussian spectrum is analytic,
19 but an empirical spectrum is not.)
20 * ``name`` (Description of the spectrum; Also accessible via
21 :py:meth:`~object.__str__`)
22 * ``wave`` (a.k.a. ``waveset``)
23 * ``waveunits`` (see :ref:`pysynphot-wave-units`)
24
25 To evaluate its flux at a given wavelength, use its
26 :meth:`~pysynphot.spectrum.SourceSpectrum.sample` (uses ``fluxunits``) or
27 :py:meth:`~object.__call__` (uses ``photlam``) method, as given in the
28 following example. Internally, evaluation uses :func:`numpy.interp`.
29
30 >>> sp = S.Vega
31 >>> sp.fluxunits.name
32 'flam'
33 >>> sp.sample(5000) # flam
34 4.7280365616415988e-09
35 >>> sp(5000) # photlam
36 1190.0510381121621
37
38
39 .. _pysynphot-create-source:
40
41 Creating a Source
42 =================
43
44 A source spectrum can be constructed by one of the following methods:
45
46 * Using a pre-defined function (:ref:`pysynphot-planck-law`,
47 :ref:`pysynphot-gaussian`, :ref:`pysynphot-powerlaw`, or
48 :ref:`pysynphot-flat-spec`)
49 * Using built-in :ref:`pysynphot-vega-spec` spectrum
50 * :ref:`Reading from spectral atlas or catalog <pysynphot-spec-atlas>`
51 * :ref:`Loading from a FITS or ASCII table <pysynphot-source-from-file>`
52 * :ref:`Using your own wavelength and flux arrays <pysynphot-empirical-source>`
53 * :ref:`Thermal spectrum <pysynphot-thermal-spec>` is available for IR
54 instruments but is usually not used directly
55
56
57 .. _pysynphot-planck-law:
58
59 Blackbody Radiation
60 -------------------
61
62 Blackbody radiation is defined by Planck's law
63 (:ref:`Rybicki & Lightman 1979 <synphot-ref-rybicki1979>`):
64
65 .. math::
66
67 B_{\lambda}(T) = \frac{2 h c^{2} / \lambda^{5}}{\exp(h c / \lambda k T) - 1}
68
69 where the unit of :math:`B_{\lambda}(T)` is ``flam`` per steradian.
70
71 `~pysynphot.spectrum.BlackBody` generates a blackbody spectrum in
72 ``photlam`` for a given temperature, normalized to a star of :math:`1 R_{\odot}`
73 at a distance of 1 kpc. Its ``waveset`` is taken from :ref:`pysynphot-refdata`.
74
75 The example below creates a blackbody spectrum at 5000 Kelvin:
76
77 >>> bb = S.BlackBody(5000)
78 >>> plt.plot(bb.wave, bb.flux)
79 >>> plt.xlabel(bb.waveunits)
80 >>> plt.ylabel(bb.fluxunits)
81 >>> plt.title(bb.name)
82
83 .. image:: _static/bb_t5000_spec.png
84 :width: 600px
85 :alt: Blackbody spectrum with temperature 5000 Kelvin.
86
87
88 .. _pysynphot-gaussian:
89
90 Gaussian Emission
91 -----------------
92
93 `~pysynphot.spectrum.GaussianSource` could be used to represent an emission
94 line:
95
96 .. math::
97
98 \sigma = \frac{\mathrm{FWHM}}{2 \; \sqrt{2 \; ln \; 2}}
99
100 A = \frac{f_{\mathrm{tot}}}{\sqrt{2 \pi} \; \sigma}
101
102 \mathrm{flux} = A \; / \; \exp(\frac{(x - x_{0})^{2}}{2 \; \sigma^{2}})
103
104 where
105
106 * FWHM is the full-width at half-maximum
107 * :math:`x_{0}` is the central wavelength
108 * :math:`x` is the wavelength array
109 * :math:`A` is the amplitude at :math:`x_{0}`
110 * :math:`f_{\mathrm{tot}}` is the total flux under the curve
111
112 Its ``waveset`` is defined such that the spectrum is more tightly sampled around
113 the peak. To create an absorption line, instead of adding the Gaussian source to
114 the continuum spectrum, you subtract it.
115
116 The example below creates a Gaussian source spectrum with total flux of
117 18.3 ``abmag`` under the curve, central wavelength of 18000 Angstroms, and
118 FWHM of 2000 Angstroms:
119
120 >>> gs = S.GaussianSource(18.3, 18000, 2000, fluxunits='abmag')
121 >>> gs.name
122 'Gaussian: mu=18000 angstrom,fwhm=2000 angstrom, total flux=18.3 abmag'
123 >>> plt.plot(gs.wave, gs.flux)
124 >>> plt.xlabel(gs.waveunits)
125 >>> plt.ylabel(gs.fluxunits)
126
127 .. image:: _static/gaussian_spec.png
128 :width: 600px
129 :alt: Gaussian source spectrum.
130
131
132 .. _pysynphot-powerlaw:
133
134 Power-Law
135 ---------
136
137 `~pysynphot.spectrum.Powerlaw` (also callable as ``pysynphot.PowerLaw``)
138 generates a power-law source:
139
140 .. math::
141
142 \mathrm{flux} = (x \; / \; x_{0})^{-\alpha}
143
144 where
145
146 * :math:`x_{0}` is the reference wavelength
147 * :math:`x` is the wavelength array
148 * :math:`\alpha` is the powerlaw index
149
150 It is defined such that the flux is 1 (in given flux unit) at the reference
151 wavelength. Its ``waveset`` is taken from :ref:`pysynphot-refdata`.
152
153 The example below creates a power-law source spectrum with reference wavelength
154 of 10000 Angstroms and index of -2:
155
156 >>> pl = S.PowerLaw(10000, -2)
157 >>> plt.loglog(pl.wave, pl.flux)
158 >>> plt.axvline(10000, ls='--', color='k')
159 >>> plt.axhline(1, ls='--', color='k')
160 >>> plt.xlabel(pl.waveunits)
161 >>> plt.ylabel(pl.fluxunits)
162 >>> plt.title(pl.name)
163
164 .. image:: _static/powerlaw_10000_minus2_spec.png
165 :width: 600px
166 :alt: Powerlaw with refwave 10000 Angstroms and alpha minus 2.
167
168
169 .. _pysynphot-flat-spec:
170
171 Flat
172 ----
173
174 `~pysynphot.spectrum.FlatSpectrum` generates a flat spectrum that has a constant
175 flux value in the given unit. Note that flux that is constant in a given unit
176 might not be constant in another, as illustrated in the example below.
177 Its ``waveset`` is taken from :ref:`pysynphot-refdata`.
178
179 The example below creates a source spectrum that is flat in ``abmag`` with the
180 amplitude of 18 mag:
181
182 >>> flatsp = S.FlatSpectrum(18, fluxunits='abmag')
183 >>> plt.plot(flatsp.wave, flatsp.flux)
184 >>> plt.xlabel(flatsp.waveunits)
185 >>> plt.ylabel(flatsp.fluxunits)
186 >>> plt.title(flatsp.name)
187
188 .. image:: _static/flatspec_18abmag.png
189 :width: 600px
190 :alt: Flat source spectrum with amplitude of 18 ABMAG.
191
192 The spectrum above, however, is not flat in ``stmag``:
193
194 >>> flatsp.convert('stmag')
195 >>> plt.plot(flatsp.wave, flatsp.flux)
196 >>> plt.xlabel(flatsp.waveunits)
197 >>> plt.ylabel(flatsp.fluxunits)
198 >>> plt.title(flatsp.name)
199
200 .. image:: _static/flatspec_18abmag_stmag.png
201 :width: 600px
202 :alt: Flat source spectrum with amplitude of 18 ABMAG is not flat in STMAG.
203
204
205 .. _pysynphot-vega-spec:
206
207 Vega
208 ----
209
210 **pysynphot** uses built-in Vega spectrum for ``vegamag`` calculations. This
211 spectrum comes with the package and is defined by
212 ``pysynphot.locations.VegaFile``, which is loaded on import as
213 ``pysynphot.spectrum.Vega`` (also callable as ``pysynphot.Vega``). Other
214 versions of Vega spectrum are available as
215 ``$PYSYN_CDBS/calspec/alpha_lyr_*.fits``, which can be read using
216 :ref:`pysynphot-io` (also see :ref:`pysynphot-appendixa-calspec`).
217
218 The example below shows the built-in Vega spectrum:
219
220 >>> plt.plot(S.Vega.wave, S.Vega.flux)
221 >>> plt.xlim(0, 12000)
222 >>> plt.xlabel(S.Vega.waveunits)
223 >>> plt.ylabel(S.Vega.fluxunits)
224 >>> plt.title(os.path.basename(S.Vega.name))
225
226 .. image:: _static/vega_spec.png
227 :width: 600px
228 :alt: Vega spectrum.
229
230
231 .. _pysynphot-spec-atlas:
232
233 Catalogs and Spectral Atlases
234 -----------------------------
235
236 There are many :ref:`spectral atlases <pysynphot-appendixa>` consisting of both
237 observed and model data that are available for use with **pysynphot**.
238
239 Plotting the spectra is a handy way to explore the contents.
240 For instance, you are interested in making some HST observations of
241 Seyfert galaxies and want to see what sort of template spectra
242 are available to be used with **pysynphot** to predict observed count rates.
243 In this case, a good place to look would be in :ref:`pysynphot-appendixa-agn`
244 or :ref:`pysynphot-appendixa-kc96`. The example below plots the spectra of
245 a starburst and a Seyfert 1 galaxies from their respective atlases:
246
247 >>> starburst = S.FileSpectrum(os.path.join(
248 ... os.environ['PYSYN_CDBS'], 'grid', 'kc96', 'starb2_template.fits'))
249 >>> seyfert1 = S.FileSpectrum(os.path.join(
250 ... os.environ['PYSYN_CDBS'], 'grid', 'agn', 'seyfert1_template.fits'))
251 >>> plt.semilogy(starburst.wave, starburst.flux, 'r', label='Starburst 2')
252 >>> plt.semilogy(seyfert1.wave, seyfert1.flux, 'b', label='Seyfert 1')
253 >>> plt.xlabel(starburst.waveunits)
254 >>> plt.ylabel(starburst.fluxunits)
255 >>> plt.legend()
256
257 .. image:: _static/AGN_compare.png
258 :width: 600px
259 :alt: Starburst and Seyfert 1 galaxy spectra.
260
261 For most of the catalogs and atlases (except the three mentioned below), you
262 can load a spectrum :ref:`from file <pysynphot-source-from-file>` once you have
263 identified the desired filename that corresponds to the spectral parameters that
264 you want, as shown in the example above.
265
266 However, three of the atlases (:ref:`pysynphot-appendixa-ck04`,
267 :ref:`pysynphot-appendixa-kurucz1993`, and :ref:`pysynphot-appendixa-phoenix`)
268 have a grid of basis spectra which are indexed for various combinations of
269 effective temperature (:math:`T_{\mathrm{eff}}`) in Kelvin, metallicity
270 (``[M/H]``), and log surface gravity (:math:`\log g`). They are best
271 accessed with a special `~pysynphot.catalog.Icat` class.
272 You may specify any combination of the properties, so long as each is
273 within the allowed range, which differs from atlas to atlas. For example,
274 :ref:`pysynphot-appendixa-ck04` allows
275 :math:`3500 \; \mathrm{K} \le T_{\mathrm{eff}} \le 50000 \; \mathrm{K}`,
276 which means that no spectrum can be constructed for effective temperatures
277 below 3499 K or above 50001 K (i.e., an exception will be raised).
278 The example below obtains the spectrum for a
279 :ref:`pysynphot-appendixa-kurucz1993` model with
280 :math:`T_{\mathrm{eff}} = 6000 \; \mathrm{K}`, ``[M/H] = 0``, and
281 :math:`\log g = 4.3`:
282
283 >>> sp = S.Icat('k93models', 6440, 0, 4.3)
284
285 For completeness, the Kurucz spectrum is plotted below in comparison with
286 the Seyfert 1 from above. Note that the Kurucz spectrum has arbitrary
287 flux values and would need to be :ref:`renormalized <pysynphot-renorm>`
288 (not done here):
289
290 >>> plt.semilogy(sp.wave, sp.flux, 'r', label='Kurucz')
291 >>> plt.semilogy(seyfert1.wave, seyfert1.flux, 'b', label='Seyfert 1')
292 >>> plt.xlim(1000, 6000)
293 >>> plt.xlabel(sp.waveunits)
294 >>> plt.ylabel(sp.fluxunits)
295 >>> plt.legend(loc='center right')
296
297 .. image:: _static/spec_atlas_ex.png
298 :width: 600px
299 :alt: Kurucz stellar and Seyfert 1 galaxy spectra.
300
301
302 .. _pysynphot-source-from-file:
303
304 From File
305 ---------
306
307 A source spectrum can also be defined using a FITS or ASCII table containing
308 columns of wavelength and flux. See :ref:`pysynphot-io` for details on how to
309 create such tables.
310
311 The example below loads a source spectrum from FITS table, which happens to
312 be one of the :ref:`pysynphot-appendixa-calspec`:
313
314 >>> filename = os.path.join(
315 ... os.environ['PYSYN_CDBS'], 'calspec', 'g191b2b_mod_010.fits')
316 >>> sp = S.FileSpectrum(filename)
317 >>> sp.flux
318 array([ 6.83127903e-12, 6.83185409e-12, 6.83168973e-12, ...,
319 3.47564168e-21, 3.47547205e-21, 3.47530241e-21])
320
321 See :ref:`Tutorial 10 <pysynphot_tutorial_10>` for example on how to load a
322 source spectrum from an ASCII table of any format.
323
324
325 .. _pysynphot-empirical-source:
326
327 From Arrays
328 -----------
329
330 To create a source spectrum from arrays, use
331 `~pysynphot.spectrum.ArraySourceSpectrum` (also callable as
332 ``pysynphot.ArraySpectrum``). Note in the example below that the flux value of
333 -2 is automatically set to 0, which can be disabled by indicating
334 ``keepneg=True`` during initialization:
335
336 >>> w = np.array([1000, 2000, 3000]) # Angstrom
337 >>> f = np.array([1, -2, 3]) # photlam
338 >>> sp = S.ArraySpectrum(w, f, name='MySource')
339 Warning, 1 of 3 bins contained negative fluxes; they have been set to zero.
340 >>> sp.flux
341 array([ 1., 0., 3.])
342 >>> sp.sample(2500)
343 1.5
344
345
346 .. _pysynphot-thermal-spec:
347
348 Thermal
349 -------
350
351 `~pysynphot.spectrum.ThermalSpectralElement` handles a spectral element with
352 thermal properties. It is used in :ref:`pysynphot-obsmode-bandpass` for an IR
353 detector, particularly for
354 :meth:`~pysynphot.obsbandpass.ObsModeBandpass.thermback` calculation.
355
356 For instance, HST/WFC3 IR detector stores thermal information in
357 its ``$PYSYN_CDBS/comp/wfc3/*_th.fits`` files. In the table header (extension 1)
358 of each file, there are two keywords:
359
360 * ``DEFT``, the detector effective temperature in Kelvin; stored as
361 ``temperature`` class attribute
362 * ``BEAMFILL``, the beam filling factor, usually 1; stored as
363 ``beamFillFactor`` class attribute
364
365 **pysynphot** uses this information, applying the thermal emissivity to the
366 optical beam to create a thermal source spectrum, all done behind the scene via
367 :meth:`~pysynphot.observationmode.ObservationMode.ThermalSpectrum`, as follow:
368
369 1. :ref:`Blackbody source spectrum <pysynphot-planck-law>` is generated using
370 the ``DEFT`` value and the :func:`~pysynphot.planck.bb_photlam_arcsec`
371 function to calculate flux in ``photlam`` per square arcsec.
372 2. Thermal source spectrum is generated by multiplying the blackbody with
373 `~pysynphot.spectrum.ThermalSpectralElement` emissivity and ``BEAMFILL``
374 value.
375 3. If the observation mode has multiple thermal components, their respective
376 thermal source spectra are added together.
377
378 The example below calculates the thermal background (in counts/pixel) for
379 HST/WFC3 IR F140W bandpass and plots its thermal source spectrum:
380
381 >>> bp = S.ObsBandpass('wfc3,ir,f140w')
382 >>> bp.thermback()
383 0.069428780630446163
384 >>> thsp = bp.obsmode.ThermalSpectrum()
385 >>> plt.plot(thsp.wave, thsp.flux)
386 >>> plt.xlim(12000, 19000)
387 >>> plt.xlabel(thsp.waveunits)
388 >>> plt.ylabel(thsp.fluxunits)
389 >>> plt.title('Thermal spectrum for {0}'.format(bp.obsmode))
390
391 .. image:: _static/wfc3_ir_therm_spec.png
392 :width: 600px
393 :alt: Thermal source spectrum for HST/WFC3 IR F140W.
394
395
396 Manipulating Source Spectrum
397 ============================
398
399 Once you have created a source spectrum, you can manipulate it in several
400 different ways, namely creating a :ref:`pysynphot-composite-spectrum` from
401 different source spectra and/or bandpass, or applying
402 :ref:`pysynphot-extinction`, :ref:`pysynphot-redshift`, or
403 :ref:`pysynphot-renorm`.
404
405
406 .. _pysynphot-composite-spectrum:
407
408 Composite Spectrum
409 ------------------
410
411 A composite spectrum is the resultant spectrum from adding, subtracting, or
412 multiplying two spectra, which can be a source spectrum or bandpass.
413 It retains the information of the input spectra as ``component1`` and
414 ``component2`` class attributes. It does not compute the flux or throughput
415 until when explicitly sampled.
416 `~pysynphot.spectrum.CompositeSpectralElement` handles
417 operations between two bandpasses or between a bandpass and a number, while
418 `~pysynphot.spectrum.CompositeSourceSpectrum` handles everything else.
419 When an operation involves more than two spectra, the resultant composite
420 spectrum contains other composite spectra from intermediate steps (like a
421 binary tree).
422
423 The following table summarizes available operations in **pysynphot**:
424
425 =============== ============== =============== ========================== ===========
426 Operand 1 Operation Operand 2 Result Commutative
427 =============== ============== =============== ========================== ===========
428 Source Spectrum :math:`-` Source Spectrum Composite Source Spectrum No
429 Source Spectrum :math:`+` Source Spectrum Composite Source Spectrum Yes
430 Source Spectrum :math:`\times` Bandpass Composite Source Spectrum Yes
431 Source Spectrum :math:`\times` Scalar number Composite Source Spectrum Yes
432 Bandpass :math:`\times` Bandpass Composite Spectral Element Yes
433 Bandpass :math:`\times` Scalar number Composite Spectral Element Yes
434 =============== ============== =============== ========================== ===========
435
436 The example below creates a :ref:`pysynphot-powerlaw` source with reference
437 wavelength of 10000 Angstroms and index of -2, and a :ref:`pysynphot-gaussian`
438 with total flux of :math:`8.3 \times 10^{-9}` ``flam`` under the curve, central
439 wavelength of 18000 Angstroms, and FWHM of 20 Angstroms. Then, the two spectra
440 are added together to create a new composite source spectrum. They are also all
441 plotted for visualization:
442
443 >>> plaw = S.PowerLaw(10000, -2)
444 >>> gss = S.GaussianSource(8.3e-9, 18000, 20, fluxunits='flam')
445 >>> sp = plaw + gss
446 >>> plt.semilogy(sp.wave, sp.flux, 'k', label='plaw+gss')
447 >>> plt.semilogy(plaw.wave, plaw.flux, 'b:', label='plaw')
448 >>> plt.semilogy(gss.wave, gss.flux, 'r--', label='gss')
449 >>> plt.xlim(17900, 18100)
450 >>> plt.xlabel(sp.waveunits)
451 >>> plt.ylabel(sp.fluxunits)
452 >>> plt.legend(loc='center')
453
454 .. image:: _static/added_spec_tutorial_1.png
455 :width: 600px
456 :alt: Spectrum addition from Tutorial 1.
457
458
459 .. _pysynphot-extinction:
460
461 Extinction
462 ----------
463
464 You can also apply or remove the effects of interstellar reddening on a
465 source spectrum using `~pysynphot.reddening.Extinction` by providing a model
466 name and the value of :math:`E(B-V)` (negative value effectively de-reddens the
467 spectrum). The extinction is defined as:
468
469 .. math::
470
471 R(V) = \frac{A(V)}{E(B-V)}
472
473 Extinction curves for **pysynphot** has been modeled for different
474 representative regions (see table below). They are available via CRDS
475 (see :ref:`pysynphot-installation-setup`) and must be installed under
476 the ``$PYSYN_CDBS/extinction`` directory. These are the same
477 `models used by Exposure Time Calculator (ETC) <http://etc.stsci.edu/etcstatic/users_guide/1_ref_7_ebv.html>`_.
478
479 Pre-defined extinction models are as tabulated below. The default model can be
480 specified in three different ways, which are all equivalent. Deprecated models,
481 which are superseded by newer ones but are retained for backward compatibility,
482 are taken from IRAF STSDAS SYNPHOT. The deprecated model, ``gal2``, is not
483 available in **pysynphot** and will raise an exception if used.
484
485 +--------+---------------------------+--------------------------------------------------------+
486 |Name |Description |Reference |
487 +========+===========================+========================================================+
488 |gal3 |Milky Way Diffuse, R(V)=3.1|:ref:`Cardelli et al. (1989) <synphot-ref-cardelli1989>`|
489 | |**(Default)** | |
490 |mwavg | | |
491 | | | |
492 |`None` | | |
493 +--------+---------------------------+ |
494 |mwdense |Milky Way Dense, R(V)=5.0 | |
495 +--------+---------------------------+ |
496 |mwrv21 |Milky Way CCM, R(V)=2.1 | |
497 +--------+---------------------------+ |
498 |mwrv4 |Milky Way CCM, R(V)=4.0 | |
499 +--------+---------------------------+--------------------------------------------------------+
500 |lmc30dor|LMC Supershell, R(V)=2.76 |:ref:`Gordon et al. (2003) <synphot-ref-gordon2003>` |
501 +--------+---------------------------+ |
502 |lmcavg |LMC Average, R(V)=3.41 | |
503 +--------+---------------------------+ |
504 |smcbar |SMC Bar, R(V)=2.74 | |
505 +--------+---------------------------+--------------------------------------------------------+
506 |xgalsb |Starburst, R(V)=4.0 |:ref:`Calzetti et al. (2000) <synphot-ref-calzetti2000>`|
507 | |(attenuation law) | |
508 +--------+---------------------------+--------------------------------------------------------+
509 |gal1 |Milky Way **(Deprecated)** |:ref:`Seaton (1979) <synphot-ref-seaton1979>` |
510 +--------+---------------------------+--------------------------------------------------------+
511 |gal2 |Milky Way **(Unavailable)**|:ref:`Savage & Mathis (1979) <synphot-ref-savage1979>` |
512 +--------+---------------------------+--------------------------------------------------------+
513 |smc |SMC **(Deprecated)** |:ref:`Prevot et al. (1984) <synphot-ref-prevot1984>` |
514 +--------+---------------------------+--------------------------------------------------------+
515 |lmc |LMC **(Deprecated)** |:ref:`Howarth (1983) <synphot-ref-howarth1983>` |
516 +--------+---------------------------+--------------------------------------------------------+
517 |xgal |Extra-galactic |:ref:`Calzetti et al. (1994) <synphot-ref-calzetti1994>`|
518 | |**(Deprecated)** | |
519 +--------+---------------------------+--------------------------------------------------------+
520
521 The example below applies LMC (average) extinction with :math:`E(B-V) = 0.1`
522 to a :ref:`blackbody <pysynphot-planck-law>` with temperature of 5000 K.
523 Both the original and reddened spectra are plotted for comparison:
524
525 >>> sp = S.BlackBody(5000)
526 >>> sp_ext = sp * S.Extinction(0.1, 'lmcavg')
527 >>> plt.plot(sp.wave, sp.flux, 'b', label='E(B-V)=0')
528 >>> plt.plot(sp_ext.wave, sp_ext.flux, 'r', label='E(B-V)=0.1')
529 >>> plt.xlabel(sp.waveunits)
530 >>> plt.ylabel(sp.fluxunits)
531 >>> plt.title(sp.name)
532 >>> plt.legend(loc='best')
533
534 .. image:: _static/bb_ext_01.png
535 :width: 600px
536 :alt: Blackbody with and without extinction.
537
538
539 .. _pysynphot-redshift:
540
541 Redshift
542 --------
543
544 In **pysynphot**, redshifting a source spectrum is done by shifting the flux
545 location by:
546
547 .. math::
548
549 \lambda_{obs} = (1 + z) \; \lambda_{rest}
550
551 The flux values themselves are not modified. This functionality is available
552 through the :meth:`~pysynphot.spectrum.SourceSpectrum.redshift` method, where
553 you provide the value of :math:`z`. You can also use this method to perform
554 blueshift (see :ref:`Tutorial 8 <pysynphot_tutorial_8>`).
555
556 The example below applies :math:`z = 0.1` to a
557 :ref:`blackbody <pysynphot-planck-law>` with temperature of 5000 K.
558 Both the original and the redshifted spectra are plotted for comparison:
559
560 >>> sp = S.BlackBody(5000)
561 >>> sp_z = sp.redshift(0.1)
562 >>> plt.plot(sp.wave, sp.flux, 'b', label='z=0')
563 >>> plt.plot(sp_z.wave, sp_z.flux, 'r', label='z=0.1')
564 >>> plt.xlabel(sp.waveunits)
565 >>> plt.ylabel(sp.fluxunits)
566 >>> plt.title(sp.name)
567 >>> plt.legend(loc='best')
568
569 .. image:: _static/bb_z_01.png
570 :width: 600px
571 :alt: Blackbody at rest and z=0.1.
572
573
574 .. _pysynphot-renorm:
575
576 Renormalization
577 ---------------
578
579 A source spectrum can also be renormalized using
580 :meth:`~pysynphot.spectrum.SourceSpectrum.renorm` to a given flux value and unit
581 in a given bandpass. This is particularly useful when the flux of a source
582 spectrum (e.g., some models in :ref:`pysynphot-appendixa`) has been arbitrarily
583 renormalized before.
584
585 The example below renormalizes a :ref:`blackbody <pysynphot-planck-law>` with
586 temperature of 5000 K to 17 ``vegamag`` in Johnson *V*. Both the original and
587 the renormalized spectra are plotted for comparison:
588
589 >>> sp = S.BlackBody(5000)
590 >>> sp_norm = sp.renorm(17, 'vegamag', S.ObsBandpass('johnson,v'))
591 >>> plt.plot(sp.wave, sp.flux, 'b', label='Original')
592 >>> plt.plot(sp_norm.wave, sp_norm.flux, 'r', label='Renormalized')
593 >>> plt.xlabel(sp.waveunits)
594 >>> plt.ylabel(sp.fluxunits)
595 >>> plt.title(sp.name)
596 >>> plt.legend(loc='best')
597
598 .. image:: _static/bb_17_vegamag.png
599 :width: 600px
600 :alt: Blackbody with and without normalization.