5.4 Working with Spectral Images
5.4.1 Sensitivity Units and Conversions
The calstis pipeline software produces a rectified two-dimensional spectral image when X2DCORR
is set to PERFORM
(see Section 3.4.25). The image is flux-calibrated (see Section 3.4.13). At each pixel i, this image contains the surface brightness per Angstrom, Bλi, in erg erg cm-2 sec-1 Å-1 arcsec-2. The image has a linear wavelength scale and uniform sampling in the spatial direction. Here we review how the image is calculated by the pipeline and how to convert the data in this image to other quantities.
The flux detected by pixel i in a two-dimensional spectral image is:
F_i = \frac{10^8 \cdot C_\lambda \cdot g \cdot h \cdot c}{R_\lambda \cdot A_{HST} \cdot \lambda \cdot f_\mathrm{TDS} \cdot f_\mathrm{T}} |
in erg cm-2 sec-1, where:
- C_\lambda is the wavelength dependent count rate, which is the ratio of the total counts to the exposure time. The exposure time is given in the
EXPTIME
header keyword. - g is the detector gain, which is unity for MAMA observations. For the CCD this is the conversion from counts to electrons, the value for which is given in the header keyword
ATODGAIN
. - h = 6.626e-27 erg s is Planck’s constant.
- c = 2.9979e10 cm s-1 is the speed of light.
- R_\lambda is the wavelength dependent integrated system throughput, given in the
PHOTTAB
for individual optical elements. A_{HST} = 45238.93416 cm2 is the area of the unobstructed HST mirror.
- \lambda is the wavelength in Angstroms, which is converted to cm by the factor of 108 in the numerator.
- f_\mathrm{TDS} is the correction for time-dependent sensitivity computed from the
TDSTAB
(e.g., STIS ISR 2017-06). - f_\mathrm{T} is the correction for temperature-dependent sensitivity, also computed from the
TDSTAB
.
The flux per Angstrom is:
F_{\lambda i} = \frac{F_i}{d} |
in erg cm-2 sec-1 Å-1, where: d is the dispersion in Å/pixel, derived from the CD1_1
header keyword.
The surface brightness detected by that pixel is:
B_i = \frac{F_i}{W \cdot m_\mathrm{s}} |
in erg cm-2 sec-1 arcsec-2, where:
- m_\mathrm{s} is the plate scale in arcsec/pixel in the cross-dispersion direction (i.e., spatial direction). This corresponds to the
CD2_2
header keyword value multiplied by 3600 arcsec/degree. - W is the slit width in arcsec.
The surface brightness per Angstrom, B_{\lambda i}, given in the flux calibrated, rectified, two-dimensional spectral image (_sx2 or _x2d file) is thus:
B_{\lambda i} = \frac{F_i}{d \cdot W \cdot m_\mathrm{s}} |
in erg cm-2sec-1Å-1arcsec-2. So, starting from the rectified two-dimensional spectral image (_sx2 or _x2d file),F_i,F_{\lambda i}, andB_ican be computed fromB_{\lambda i}as:
F_i = B_{\lambda i} \cdot d \cdot W \cdot m_\mathrm{s} |
F_{\lambda i} = B_{\lambda i} \cdot W \cdot m_\mathrm{s} |
B_i = B_{\lambda i} \cdot d |
Similarly, fluxes can be summed over regions in the _sx2 and _x2d files and used to compute the flux or surface brightness per Angstrom for the continuum, or flux or surface brightness of a spectral feature (after subtracting off the continuum). For a rectangular region in the spectral image spanning N_\lambdapixels in the dispersion direction (N_\lambdais proportional to Angstroms) and N_\mathrm{s}pixels in the spatial direction (N_\mathrm{s} m_\mathrm{s}arcsec along the slit):
F = \sum\limits_{i} F_i = N_\lambda \cdot N_\mathrm{s} \cdot \langle F_i \rangle = N_\lambda \cdot N_\mathrm{s} \cdot \langle B_{\lambda i} \rangle \cdot d \cdot W \cdot m_\mathrm{s} |
F_\lambda = \frac{\sum\limits_{i} F_i}{N_\lambda \cdot d} = N_\mathrm{s} \cdot \langle B_{\lambda i} \rangle \cdot W \cdot m_\mathrm{s} |
B = \frac{\sum\limits_{i} F_i}{W \cdot N_\mathrm{s} \cdot m_\mathrm{s}} = N_\lambda \cdot \langle B_{\lambda i} \rangle \cdot d |
B_\lambda = \frac{\sum\limits_{i} F_i}{N_\lambda \cdot d \cdot W \cdot N_\mathrm{s} \cdot m_\mathrm{s}} = \langle B_{\lambda i} \rangle |
where F is in erg cm-2 sec-1, F_\lambda is in erg cm-2 sec-1 Å-1, B is in erg cm-2 sec-1 arcsec-2, and B_\lambda is in erg cm-2 sec-1 Å-1 arcsec-2.
No slit loss corrections have been made above. This is correct in the limiting case of spatially uniform surface brightness. For a point source, the flux can be corrected for slit loss by using the data header keyword DIFF2PT
. This keyword is calculated as:
DIFF2PT = \frac{W \cdot m_\mathrm{s} \cdot H}{T^\mathrm{ap}} |
where W and m_\mathrm{s} are as above, T^\mathrm{ap} is the wavelength-averaged point source aperture throughput for the science aperture (which is determined from the reference table specified by the keyword APERTAB
), and H is the wavelength-averaged correction for the extraction slit of height H to a slit of infinite height, which is obtained from the reference table specified by the keyword PCTAB
. That is, to derive the flux from a point source, integrate the _x2d or _sx2 file over the default extraction slit height (from the PCTAB
) and multiply the result by DIFF2PT
. The default extraction slit height for first order modes is at present 11 pixels for the MAMAs and 7 pixels for the CCD. If the desired extraction slit height differs from the default, the PCTAB
has a set of wavelength-dependent corrections for selected alternative apertures that must also be applied. See STIS ISR 98-01 for further details. Of course, point source observers are better advised to use the x1d task to extract a one-dimensional spectrum from their long slit first order data, which will then apply the wavelength-dependent aperture throughput and extraction height corrections and the GACTAB
correction, as well as perform background subtraction. For the narrowest apertures and for some gratings and wavelength settings, the wavelength-dependent corrections can vary substantially across the detector.
In general we note that the cross dispersion profiles can be quite extended (particularly in the far-UV and in the near-IR). Fluxes derived for extended sources from the _x2d files, as above, assume that the sources are extended on scales that contain the bulk of the cross dispersion flux from a point source. Encircled energies for the first order modes can be found in STIS ISR 97-13.
See also Chapter 6 of the STIS Instrument Handbook for a more detailed discussion of units and conversions for different source types.
5.4.2 Wavelength and Spatial Information
Two-dimensional spectral images have been wavelength calibrated and rectified to linear wavelength and spatial scales. Reading the _sx2 and _x2d files (e.g., with astropy.io.fits) makes the wavelength header information stored in the standard FITS CD matrix keywords available for inspection and/or modification, and one can use those keywords directly to determine the wavelength or distance along the slit at any pixel as:
\lambda(x) = \mathtt{CRVAL1} + (x - \mathtt{CRPIX1}) \times \mathtt{CD1\_1} |
s(y) = (y - \mathtt{CRPIX2}) \times \mathtt{CD2\_2} |
where \lambda(x) is the wavelength at any given x pixel, and s(y) is the distance along the slit from slit center for any given y pixel, in units of degrees.
5.4.3 Improving the Rectification of Spectral Images
Systematic errors are introduced into the rectification of spectral images by the use of inaccurate spectral traces and by interpolation of undersampled data. CTE errors in CCD _flt or _crj images are also propagated into the rectified image; i.e., in columns (wavelength regions) with low flux levels in the target and background, the observed flux of the target will be diminished and the target will appear to be centered slightly further away from the readout amplifier, the more so for targets more distant from the readout amplifier. For the case of a point source on a spatially uniform background, one can obtain a CTE-corrected extracted spectrum (Section 3.4.6). No CTE correction is made in the much more general (and much less tractable) case of rectifying and flux-calibrating a spectral image. However, CTE effects should generally be small for targets placed at the E1 pseudo-aperture positions, implemented in July 2000.
To improve rectification, one must first ensure that accurate traces are applied to the input image. The orientation of spectral traces on the STIS detectors has been found to rotate slowly over time for the L and M modes (e.g., STIS ISR 2007-03). The rotation rate is most consequential for the later observations made with the CCD. For exposures taken just before the suspension of operations in August 2004, the Y-range of the CCD traces differed from that of the reference file traces by about half a pixel. This is sufficient to introduce tilts and curvatures into row-by-row spectra taken from the rectified image and to cause a discrepancy in the physical centers of rotation curves measured from widely separated spectral lines. New trace files were delivered with time-dependent orientations for the most commonly used first order modes and the stistools task mktrace was developed to produce an improved trace reference file for any L or M mode image, as discussed in Section 3.5.7. If needed, new trace reference files should thus be retrieved from the archive or generated with mktrace.
The greatest problem in the rectification of STIS spectral images, especially CCD images, is that the point spread function (PSF) is undersampled along the slit. The bi-linear interpolation employed by calstis, and by its constituent script stistools task x2d, produces artifacts in the rows of spectra in the rectified image when a point source is present. For gratings with spectral traces that drop by several rows as they cross the detector, the artifacts take the form of periodic scallops in the flux which change phase from one row to the next. For gratings with a trace that is confined to a height of less than one pixel, the flux in each row is modulated by a broad irregular shape. See Figure 11.9 in Section 11.3.5 of the STIS Instrument Handbook.
Interpolation artifacts can be reduced in rows near the center of a point source by using the wavelet method of interpolation described by Barrett and Dressel (2005, The HST Calibration Workshop). This method uses average interpolation (instead of point interpolation) and iterative refinement. The pixels in each column are repeatedly subdivided into pairs of subpixels and the flux is distributed among the subpixels using polynomial fits to the flux profile. The subpixels are then reassembled into pixels centered on the trace, thus producing an image that has been rectified in the spatial dimension. (Quantization effects are removed by taking the appropriate fractions of subpixels at the edges of the new pixel boundaries.)
Wavelet interpolation has been implemented in the stistools task wx2d (STIS ISR 2007-04). The task takes an _flt, _sfl, or _crj image as input and produces an array that has been rectified in the spatial direction and, optionally, a corresponding array of wavelengths. (As for input to x2d, the input image should already have SHIFTA1
and SHIFTA2
populated by the stistools task wavecal.) The user can select the order of the polynomial used to fit the flux profile, the number of subpixels to create, and the range of rows in the image to be processed. Convolution with a model PSF can be performed; this reduces the magnitude of the artifacts at the expense of resolution along the slit. The task optionally outputs the subpixeled image, with and/or without convolution. The interpolated image can be processed by x2d to linearize wavelengths and provide flux calibration. x2d automatically turns off interpolation along columns for a wx2d image, signified by WX2DCORR=’COMPLETE
’.
5.4.4 Combining Undithered Spectral Images
A set of undithered flat-fielded spectral images can easily be combined in the usual ways (outlined below) if the images are well aligned. This will be the case if the optical path has not changed appreciably and if the target has not drifted due to errors in tracking or reacquisition. The optical path is generally very stable once the grating has been positioned, and a series of science exposures is usually taken without repositioning the grating. Nearly all spectral images have associated wavecals, which were taken with the same grating positioning. To determine shifts in the optical path, calstis or its constituent task stistools task wavecal measures the positioning of the wavecal image(s) on the detector and computes the values SHIFTA1
and SHIFTA2
(shifts from the nominal x, y positions) as described in Section 3.4.23. Values for the corresponding header keywords SHIFTA1
and SHIFTA2
can be checked to see if the changes are small for the series of _flt images to be combined.
To check for target drift, first check whether the exposures were made in single guide star mode, as discussed in Section 5.2.6. If so, the roll angle of the telescope will be less well controlled, and drift may be significant for long exposures or exposures with large time separations. Even if two guide stars are used, target drift can build up over many orbits to a significant fraction of the aperture width unless a new ACQ/PEAK was performed. To check for drift, use any method that compares the wavelength scale or position along the slit. For example, for MAMA exposures that include a point source, one can check the values of A2CENTER
(Section 3.4.24) in the _x1d table extensions to look for drift along the slit in excess of the optical path shift measured by SHIFTA2
. For CCD images, one can check whether ocrreject systematically rejected long strings of pixels along a row in a _flt image because a shift along the slit caused a mismatch in flux (Section 3.5.4). If there is a mismatch, one will need to measure the shift along the slit with a method that gives robust results for images that are undersampled in the spatial direction and that have not been cleaned of cosmic rays. e.g., run the stistools task mktrace on the _flt images to look for differences in the reported central row. For either detector, one can use a spectral modelling routine such as SpecViz to look for differences in the central wavelengths of spectral features in individual _x1d images or rows of _x2d images. A shift in wavelength can be converted to a shift in pixels using the dispersion relation.
If there are measurable misalignments of the individual exposures to be combined, one will need to decide how much misalignment is acceptable in the final data products. If the resulting degradation in spatial and spectral resolution is insignificant, the _flt images can be combined in the usual ways with appropriate consideration of cleaning/masking (bad pixels, cosmic rays) and weighting the individual images and generation of a suitable error array for the combined image:
- For associated images, one can use calstis (if the default parameters are acceptable)
- For MAMA images, one can use either the IRAF msartih and mstools or the basic array manipulation capabilities of Python numpy and astropy.io.fits.
- For CCD images, one can use the stistools task ocrreject, relaxing the rejection parameters to accommodate the misalignment (Section 3.5.4).
If the misalignment of the _flt exposures is unacceptable, individual _x2d images can be combined instead. If the misalignment is due primarily to shifts in the optical path, simply average the default _x2d images, since those images have all been shifted to the nominal position. For example, generate an individual _x2d file for each CCD _flt imset, or split a MAMA _x2d file into imsets with astropy.io.fits. Then combine the individual _x2d images, using the capabilities of Python numpy or astropy.io.fits, masking, cleaning, and weighting as necessary. If there is substantial target drift, adjust SHIFTA1
and SHIFTA2
in the _flt data extension headers (Section 2.3.1) to include the increments due to the drift. If the target has drifted too close to the edge of the slit in an exposure, the flux will not be properly corrected for slit losses, and one may choose to reject that exposure.
5.4.5 Combining Dithered Spectral Images
Dithering by a few pixels along Y (the spatial dimension in a spectroscopic image) is recommended to allow removal of hot pixels when CCD images are combined. To prepare dithered images for combination, first perform bias, flat, and dark correction of the raw images with the stistools task basic2d to produce _flt images. Some of the _flt images must then be shifted up or down to align them with each other. This shifting can be accomplished with the stistools task sshift task. The cosmic ray rejection routine ocrreject can be applied to the set of shifted images to combine them into a _crj image. Hot pixels will be rejected along with the cosmic rays. The _crj images can then be reduced in the usual way applying calstis or its components. See Section 3.5.4 for a discussion of the use of this task in the broader context of improving cosmic ray rejection. If the shifted _flt images are not well aligned, they should be handled like the _flt images in Section 5.4.4.
5.4.6 Producing Rectified Spectral Images for Long-Slit Echelle Data
An entire input echelle image cannot be 2-D rectified all at once because the dispersion relation is different for each spectral order. The stistools task x2d task is thus not normally run by the STScI pipeline on echelle data, and users do not get an _x2d file as a normal data product. Nonetheless, this task can be used (with care) on echelle spectra. In this case, x2d will generate a single output FITS file with a 2-D image set (imset) for each spectral order in the input _flt file – i.e., each order is corrected and written separately.
Several problems may arise in the 2-D rectification of long-slit echelle spectra with the x2d task. One problem is that, e.g., while the 6X0.2 slit is so long that it overlaps several spectral orders, the height of the output images is small enough that they cover only one spectral order per image. If the feature the user is interested in is, say, at 50 pixels from the center in the cross-dispersion direction, but the output _x2d images are only 71 pixels high, the features will not fall within the output image (though it might appear in an image for a different spectral order). A work around for this problem is to edit the SDCTAB
and change the values in the NPIX2 and CRPIX2 columns for the OPT_ELEM and CENWAVE that were used for the observation. More than one row may need to be changed, depending on which spectral orders (SPORDER) contain data for which a full slit length should be corrected. Set NPIX2 to a large enough value to cover as much of the slit as you need, and set CRPIX2 to (NPIX2 + 1) / 2 to center the spectrum.
For the 2-D rectification of long-slit echelle spectra there are two possible sources of tilt error. The first is the "physical" tilt, due to the fact that the slit is rotated by a small angle from its nominal orientation. The slits are mounted in the aperture wheel, and the nominal orientation is that the slit be perpendicular to the line from the center of the slit to the center of the aperture wheel. This physical tilt from the nominal orientation is a fraction of a degree for most apertures; it is stored in the ANGLE column in the aperture description table (APDESTAB
) for the aperture in use. The second source of tilt error is due to an optical distortion, in which the slit image on the detector is curved and tilted. For first order data this "slit to detector" tilt appears to be quite small, but for echelle data it is much larger than the physical tilt and can be several degrees. It depends strongly on the particular echelle grating in use and varies across the detector. While this has not been thoroughly investigated, it looks as if the tilt of the slit images changes systematically across the image in the sense that the slit images have a center of rotation well off the detector, i.e., lines drawn from the rotation point to the center of the slit images are perpendicular to the slit images, and the slit images are quasi-circular arcs. If this model is correct, it should be possible to measure the tilts of the bright emission lines in calibration data and predict the behavior of the tilt as a function of the position on the detector. However, not enough calibration data are available in the archive to do this for all locations on all gratings.
For echelle data, running the stistools task x2d with default parameters takes into account only the physical tilt, but not the optical distortion, for echelle data. For first order spectral data, the optical distortion is corrected for by the dispersion relation, which varies with the Y coordinate in the image. In the case of echelle data, the dispersion relation used in calstis and its components depends on spectral order but not on Y coordinate for a given order. Consequently, the spectral lines in the 2-D echelle output image will still be tilted with an angle that varies across the detector. One can use the following procedure to correct for the "slit to detector" tilt as well as the physical tilt of the slit in a long-slit echelle _x2d image. First, measure the tilt of strong lines in the wavecal in the neighborhood of the emission lines of interest in the science data (i.e., same spectral order and wavelength region). Enter the value of this tilt, expressed in degrees measured clockwise from the Y axis, into the parameter angle in the wavecal task parameter list and into the column ANGLE in the APDESTAB
table in the row for that aperture. Run wavecal and then run x2d. Since a single value of the tilt is not representative of the entire image, regions with different tilts should be calibrated separately.