Debian Codegraph @

doc/source/observation.rst

raw
1 .. _pysynphot-observation:
2
3 ***********
4 Observation
5 ***********
6
7 `~pysynphot.observation.Observation` is a special type of
8 :ref:`pysynphot-spectrum`, where the source is convolved with a
9 :ref:`pysynphot-bandpass`, both which are stored in its ``spectrum`` and
10 ``bandpass`` class attributes, respectively.
11
12 It also has two different datasets:
13
14 * ``wave`` and ``flux``, as defined by the native wavelength set, which is
15 constructed when combining the source spectrum and the bandpass.
16 * ``binwave`` and ``binflux``, as defined by the binned wavelength set.
17
18 Binned wavelength set uses the optimal binning for the detector, if applicable.
19 When optimal binning is not found (e.g., a non-HST filter system), it uses the
20 native wavelength set instead (see :ref:`pysynphot-refdata`). For IRAF STSDAS
21 SYNPHOT users, this is the same behavior as the ``countrate`` task.
22 In addition, ``binwave`` can be explicitly overwritten using the ``binset``
23 keyword at initialization. Note that the given array must contain the central
24 wavelength values of the bins.
25
26 Once ``binwave`` is established, ``binflux`` is computed by integrating the
27 native flux over the width of each bin. Due to the nature of binned data,
28 ``binflux`` cannot be interpolated when sampled. To accurately represent binned
29 dataset in a plot, you should plot it as a histogram, with each ``binwave``
30 value at the mid-point of the horizontal step (see
31 :ref:`pysynphot-observation-examples`).
32
33 In contrast, the native dataset is considered to be samples of a continuous
34 function. Thus, it may be interpolated linearly and plotted without using a
35 histogram.
36
37 An observation can be sampled using its
38 :meth:`~pysynphot.observation.Observation.sample` method. By default, it samples
39 the binned dataset and does not allow interpolation; i.e., you must provide
40 a wavelength value that exactly match that in ``binwave``. It will sample the
41 native dataset and allows interpolation if the ``binned=False`` option is used.
42 For for information, see :ref:`pysynphot-command-sample`.
43
44 The following operations are disabled because they do not make sense in the
45 context of an observation, in which a photon has passed through the telescope
46 optics:
47
48 * Redshift
49 * Addition/subtraction
50 * Some multiplication (see below)
51
52 When multiplication is performed, a new observation is created using its
53 original source spectrum and a new bandpass from multiplying its original
54 bandpass with the given bandpass or scalar number. An observation cannot be
55 multiplied with another observation, source spectrum, or extinction curve.
56
57 In addition, it has unique properties, such as :ref:`pysynphot-formula-effstim`
58 (also see :ref:`pysynphot-formula-countrate`) and
59 :ref:`pysynphot-formula-efflam`.
60
61 Like a source spectrum, an observation can be written to a FITS table using its
62 :meth:`~pysynphot.observation.Observation.writefits` method (also see
63 :ref:`pysynphot-io`), which in this case, takes an additional ``binned`` keyword
64 to indicate which dataset to write.
65
66
67 .. _pysynphot-formula-countrate:
68
69 Count Rate
70 ----------
71
72 :meth:`~pysynphot.observation.Observation.countrate` is probably the most often
73 used method for an observation. It computes the total counts of a source
74 spectrum, integrated over the passband defined by a
75 :ref:`HST observing mode <pysynphot-obsmode-bandpass>`. For calculations, it
76 uses an optimal wavelength set (if available), which is constructed so that
77 one wavelength bin corresponds to one detector pixel.
78
79 It has two unique features below that are helpful when simulating a HST
80 observation. Therefore, it is ideally suited for predicting exposure times
81 (e.g., using `HST ETC <http://etc.stsci.edu/etc>`_) when writing HST proposals:
82
83 #. The input parameters were originally structured to mimic what is contained
84 in the exposure logsheets found in HST observing proposals in
85 `Astronomer's Proposal Tool (APT) <http://www.stsci.edu/scientific-community/software/astronomers-proposal-tool-apt.html>`_.
86 #. For the spectroscopic instruments, it will automatically search for and
87 use a :ref:`wavelength table <pysynphot-wavelength-table>` that is
88 appropriate for the selected instrumental dispersion mode.
89
90 Examples its usage are available in :ref:`pysynphot-observation-examples`,
91 :ref:`Tutorial 1: Observation <pysynphot_tutorial_1_obs>`, and
92 :ref:`pysynphot_tutorial_7`.
93
94
95 .. _pysynphot-command-sample:
96
97 Sampling
98 --------
99
100 :meth:`~pysynphot.observation.Observation.sample` is another useful method
101 for an observation. It allows the computation of the number of counts at a
102 particular reference wavelength (in Angstroms) for either binned or native
103 dataset.
104
105 The example below computes the number of counts for :ref:`pysynphot-vega-spec`
106 at 10000 Angstroms, as observed by HST/WFC3 IR detector using F105W filter:
107
108 >>> refwave = 10000
109 >>> obs = S.Observation(S.Vega, S.ObsBandpass('wfc3,ir,f105w'))
110 >>> obs.sample(refwave) # Binned dataset
111 6427997.452742151
112 >>> obs.sample(refwave, binned=False) # Native dataset
113 32194062.511316653
114
115 In contrast, its :py:meth:`~object.__call__` method is the same as
116 :ref:`pysynphot-spectrum`. It always computes flux in ``photlam`` and can only
117 "see" the native dataset, as illustrated by the example below:
118
119 >>> obs(refwave)
120 142.0874566775498
121
122
123 .. _pysynphot-observation-examples:
124
125 Examples
126 --------
127
128 Simulate an observation of a 5000 K blackbody through the HST/ACS WFC1 F555W
129 bandpass, and plot its binned dataset:
130
131 >>> obs = S.Observation(S.BlackBody(5000), S.ObsBandpass('acs,wfc1,f555w'))
132 >>> plt.plot(obs.binwave, obs.binflux, drawstyle='steps-mid')
133 >>> plt.xlim(4000, 7000)
134 >>> plt.xlabel(obs.waveunits)
135 >>> plt.ylabel(obs.fluxunits)
136 >>> plt.title(obs.name)
137
138 .. image:: _static/bb_acs_obs.png
139 :width: 600px
140 :alt: Observation of blackbody with ACS WFC1 F555W.
141
142 Calculate the count rate of this observation in the unit of counts/s over the
143 HST collecting area (i.e., the primary mirror) that is defined in
144 :math:`\mathrm{cm}^{2}`:
145
146 >>> obs.primary_area
147 45238.93416
148 >>> obs.countrate()
149 10080.633086603169
150
151 Calculate the effective stimulus in ``flam``:
152
153 >>> obs.effstim('flam')
154 1.9951166916464598e-15
155
156 Calculate the effective wavelength in Angstroms:
157
158 >>> obs.efflam()
159 5406.9723492971034
160
161 Convert the flux unit to counts:
162
163 >>> obs.convert('counts')
164
165 Plot observation data in both native and binned wavelength sets. Note that
166 counts per wavelength bin depends on the size of the bin because it is not
167 a flux density:
168
169 >>> plt.plot(obs.wave, obs.flux, marker='x', label='native')
170 >>> plt.plot(obs.binwave, obs.binflux, drawstyle='steps-mid', label='binned')
171 >>> plt.xlim(6010, 6040)
172 >>> plt.ylim(2, 6)
173 >>> plt.xlabel(obs.waveunits)
174 >>> plt.ylabel(obs.fluxunits)
175 >>> plt.title(obs.name)
176 >>> plt.legend(loc='best')
177
178 .. image:: _static/bb_acs_obs_histogram.png
179 :width: 600px
180 :alt: Histogram of blackbody observation with ACS WFC1 F555W.
181
182 Write the observation out to two FITS tables, one with native dataset and the
183 other binned:
184
185 >>> obs.writefits('myobs_native.fits', binned=False)
186 >>> obs.writefits('myobs_binned.fits')