Debian Codegraph @

doc/source/iraf_synphot.rst

raw
1 .. _pysynphot-iraf-switcher:
2
3 **********************************
4 Switching from IRAF STSDAS SYNPHOT
5 **********************************
6
7 This section provides basic switcher's guide for those who are familiar with
8 IRAF STSDAS SYNPHOT. This guide is not meant to be all-inclusive for two
9 reasons:
10
11 * Some of the SYNPHOT tasks can be reproduced in several different ways using
12 **pysynphot**.
13 * Not all the SYNPHOT tasks are available in **pysynphot**.
14
15 The agreement of results between these two software were discussed in detail in
16 :ref:`TSR 2009-01: Pysynphot Commissioning Report (Laidler 2009) <synphot-ref-laidler2009>`.
17
18 In the tables below:
19
20 * ``sp`` represents a :ref:`source spectrum <pysynphot-spectrum>`
21 * ``bp`` represents a :ref:`bandpass <pysynphot-bandpass>`
22 * ``obs`` represents an :ref:`observation <pysynphot-observation>`
23
24
25 Source Spectrum
26 ===============
27
28 =================================================== ===========================
29 **pysynphot** SYNPHOT
30 =================================================== ===========================
31 S.FileSpectrum(filename) spec(filename)
32 S.BlackBody(temperature) bb(temperature)
33 S.FlatSpectrum(val, fluxunits=form) unit(val, form)
34 S.Powerlaw(refval, expon, fluxunits=form) pl(refval, expon, form)
35 S.GaussianSource(totflux, mu, fwhm, fluxunits=form) em(mu, fwhm, totflux, form)
36 S.ArraySpectrum(wave, flux, fluxunits=form) N/A
37 S.Icat(model, Teff, Z, log_g) icat(model, Teff, Z, log_g)
38 sp.renorm(val, form, bp) rn(sp, bp, val, form)
39 sp.redshift(z) z(sp, z)
40 sp.writefits(filename) calcspec sp filename
41 plt.plot(sp.wave, sp.flux) N/A
42 =================================================== ===========================
43
44
45 Bandpass
46 ========
47
48 There is no single bandpass method that is equivalent to IRAF STSDAS SYNPHOT
49 ``bandpar`` task, but different commands can be used separately in order to
50 derive different photometric properties, as tabulated below.
51
52 ================================ ===============================
53 **pysynphot** SYNPHOT
54 ================================ ===============================
55 S.FileBandpass(filename) thru(filename)
56 S.Box(mu, width) box(mu, width)
57 S.ObsBandpass(obsmode) band(obsmode)
58 bp.avgwave() bandpar bp photlist=avglam
59 bp.efficiency() bandpar bp photlist=qtlam
60 bp.equivwidth() bandpar bp photlist=equvw
61 bp.rectwidth() bandpar bp photlist=rectw
62 bp.photbw() bandpar bp photlist=bandw
63 bp.throughput.max() bandpar bp photlist=tpeak
64 bp.thermback() thermback obsmode
65 bp.writefits(filename) calcband bp filename
66 plt.plot(bp.wave, bp.throughput) plband bp
67 ================================ ===============================
68
69
70 Observation
71 ===========
72
73 ================================== ==================================
74 **pysynphot** SYNPHOT
75 ================================== ==================================
76 S.Observation(sp, bp) N/A
77 obs.countrate() calcphot bp sp counts
78 obs.effstim(form) calcphot bp sp form
79 obs.efflam() calcphot bp sp flam func='efflerg'
80 obs.writefits(filename) N/A
81 plt.plot(obs.binwave, obs.binflux) plspec bp sp photlam
82 ================================== ==================================
83
84
85 Miscellaneous
86 =============
87
88 ========================= =========================
89 **pysynphot** SYNPHOT
90 ========================= =========================
91 S.Extinction(val, law) ebmvx(val, law)
92 S.Extinction(val, 'gal1') ebmv(val)
93 S.Waveset(w1, w2, dw) genwave filename w1 w2 dw
94 ========================= =========================
95
96
97 .. _pysynphot-language-parser:
98
99 Language Parser
100 ===============
101
102 **pysynphot** also has a special parser that can read some of the legacy
103 SYNPHOT language for spectrum objects. However, the parser cannot perform
104 legacy commands such as ``calcphot`` or ``bandpar``.
105
106 The following table lists the available operations:
107
108 =========================== ===================================================
109 Parser Syntax Pythonic Equivalent
110 =========================== ===================================================
111 band(obsmode) S.ObsBandpass(obsmode)
112 bb(temperature) S.BlackBody(temperature)
113 box(mu, width) S.Box(mu, width)
114 ebmvx(val, law) S.Extinction(val, law)
115 em(mu, fwhm, totflux, form) S.GaussianSource(totflux, mu, fwhm, fluxunits=form)
116 icat(model, Teff, Z, log_g) S.Icat(model, Teff, Z, log_g)
117 pl(refval, expon, form) S.Powerlaw(refval, expon, fluxunits=form)
118 rn(sp, bp, val, form) sp.renorm(val, form, bp)
119 spec(filename) S.FileSpectrum(filename)
120 unit(val, form) S.FlatSpectrum(val, fluxunits=form)
121 z(sp, z) sp.redshift(z)
122 =========================== ===================================================
123
124 These are the flux units (``form``) recognized by the parser
125 (for wavelength, only Angstrom is accepted):
126
127 * ``fnu``
128 * ``flam``
129 * ``photnu``
130 * ``photlam``
131 * ``counts``
132 * ``abmag``
133 * ``stmag``
134 * ``obmag``
135 * ``vegamag``
136 * ``jy``
137 * ``mjy``
138
139 These are the reddening laws recognized by the parser.
140 They are used for the ``law`` variable in the ``ebmvx`` command above:
141
142 * ``gal1``
143 * ``gal3``
144 * ``smc``
145 * ``lmc``
146 * ``xgal``
147
148 This example shows how a blackbody can be generated using the parser and
149 the regular Python class. It also shows that they are both the same thing:
150
151 >>> from pysynphot import spparser as P
152 >>> bb1 = P.parse_spec('bb(5000)')
153 >>> bb2 = S.BlackBody(5000) # Equivalent to bb1
154 >>> assert bb1.integrate() == bb2.integrate()
155
156 Meanwhile, this example shows how to use the parser to apply extinction to
157 a redshifted and renormalized spectrum obtained from a catalog. It also
158 generates the same spectrum using regular Python commands, and compares them:
159
160 >>> sp1 = P.parse_spec('ebmvx(0.1, lmc) * z(rn(icat(k93models, 5000, -0.5, 4.4), band(johnson,v), 18, abmag), 0.01)')
161 >>> sp2 = S.Extinction(0.1, 'lmc') * S.Icat('k93models', 5000, -0.5, 4.4).renorm(18, 'abmag', S.ObsBandpass('johnson,v')).redshift(0.01)
162 >>> assert sp1.integrate() == sp2.integrate()
163
164
165 Examples
166 ========
167
168 In the examples below, the SYNPHOT commands are preceded by ``sy>``.
169 They are followed by the **pysynphot** equivalent in ``>>>``.
170 Some examples are adapted from SYNPHOT documentation.
171
172 IRAF STSDAS SYNPHOT setup::
173
174 iraf> stsdas
175 iraf> hst_calib
176 iraf> synphot
177 sy>
178
179 Calculate the pivot wavelength and the total flux (in counts/s) of a
180 5000 K blackbody in the HST/WFPC F555W bandpass. The blackbody spectrum is
181 normalized to have a *V* magnitude of 18.6::
182
183 sy> calcphot "band(wfpc,f555w)" "rn(bb(5000),band(v),18.6,vegamag)" counts
184 Mode = band(wfpc,f555w)
185 Pivot Equiv Gaussian
186 Wavelength FWHM
187 5467.653 1200.953 band(wfpc,f555w)
188 Spectrum: rn(bb(5000),band(v),18.6,vegamag)
189 VZERO (COUNTS s^-1 hstarea^-1)
190 0. 419.5938
191
192 >>> obs = S.Observation(
193 ... S.BlackBody(5000).renorm(18.6, 'vegamag', S.ObsBandpass('v')),
194 ... S.ObsBandpass('band(wfpc,f555w)'))
195 >>> obs.bandpass.pivot()
196 5467.6512917540995
197 >>> obs.countrate()
198 418.74429418688777
199
200 Calculate the total flux (in ``obmag``) of a 5000 K blackbody in the HST/ACS
201 WFC1 F555W bandpass for :math:`E(B-V)` values of 0.0, 0.25, and 0.5::
202
203 sy> calcphot "acs,wfc1,f555w" "bb(5000)*ebmv($0)" obmag vzero="0.0,0.25,0.5"
204 Mode = band(acs,wfc1,f555w)
205 Pivot Equiv Gaussian
206 Wavelength FWHM
207 5361.008 847.9977 band(acs,wfc1,f555w)
208 Spectrum: bb(5000)*ebmv($0)
209 VZERO (OBMAG s^-1 hstarea^-1)
210 0. -10.0087
211 0.25 -9.1981
212 0.5 -8.39187
213
214 >>> for ebv in (0.0, 0.25, 0.5):
215 ... obs = S.Observation(
216 ... S.BlackBody(5000) * S.Extinction(ebv, 'gal1'),
217 ... S.ObsBandpass('acs,wfc1,f555w'))
218 ... print('{0}\t{1:.4f}'.format(ebv, obs.effstim('obmag')))
219 0.0 -10.0087
220 0.25 -9.1981
221 0.5 -8.3919
222
223 Plot an observation of BD+75 325 using the HST/ACS SBC F125LP bandpass in the
224 unit of ``flam``. The spectral data for BD+75 325 are stored in
225 ``$PYSYN_CDBS/calspec/bd_75d325_stis_003.fits`` file. Because this spectrum has
226 been arbitrarily normalized in intensity, we must first renormalize it to its
227 proper *U* magnitude of 9.5::
228
229 sy> plspec "acs,sbc,f125lp" "rn(crcalspec$bd_75d325_stis_003.fits,band(u),9.5,vegamag)" flam
230
231 .. image:: _static/bd75325_plspec_ex1.png
232 :width: 600px
233 :alt: BD+75 325 observation from IRAF plspec example.
234
235 >>> filename = os.path.join(
236 ... os.environ['PYSYN_CDBS'], 'calspec', 'bd_75d325_stis_003.fits')
237 >>> obs = S.Observation(
238 ... S.FileSpectrum(filename).renorm(9.5, 'vegamag', S.ObsBandpass('u')),
239 ... S.ObsBandpass('acs,sbc,f125lp'))
240 >>> obs.convert('flam')
241 >>> plt.plot(obs.wave, obs.flux)
242 >>> plt.xlim(1000, 2200)
243 >>> plt.xlabel(obs.waveunits)
244 >>> plt.ylabel(obs.fluxunits)
245
246 .. image:: _static/bd75325_plspec_ex2.png
247 :width: 600px
248 :alt: BD+75 325 observation from pysynphot example.