Space Telescope Science Institute
DrizzlePac 2012 Handbook
Table of Contents Previous Next Index Print

The DrizzlePac Handbook > Chapter 7: Examples: Using DrizzlePac for Combining Images > 7.3 ACS/WFC: Optimizing the Image Alignment for Multiple Visits

Three ACS/WFC images of a crowded stellar field, obtained at different epochs, with different PA_V3 orientations, will be aligned to a common WCS using tweakreg, then combined using astrodrizzle.
Example Overview
Align the images using TweakReg. Several runs of tweakreg are demonstrated, showing what bad results look like, and how to use them as clues to converging on good image offset determinations.
Images of the globular cluster NGC 104 (Program 10737) were obtained using ACS/WFC in the F606W filter. Three images, each taken in different visits, at different pointings and orientations, will be used to demonstrate the use of tweakreg and astrodrizzle to align and combined images. The input images for this example are flat-field calibrated images processed in the pipeline by calacs and corrected for CTE (indicated by the suffix flc.fits). A summary of the observations are provided in Table 7.5.
Table 7.5: Summary of Images in this Example
Line Number
5.697616395115E+00 -7.205982433883E+01
5.705688709088E+00 -7.206823392081E+01
5.683740916018E+00 -7.207973425822E+01

CRVAL1, CRVAL2 at the reference pixel in [sci,1]

Within a single visit, images from small dithers are usually well-aligned. This is not the case for multiple visits which often utilize different guide star pairs, and could have WCS frames that are offset by as much as 0.5 arcseconds. This effect can be seen in Figure 7.18.
Figure 7.18: Offsets Are Visually Apparent in These Individually-Drizzled Images from Different Visits that Were Aligned Based on Original WCS Information
Stars do not fall in the same location when aligned in ds9, based on the WCS keyword values from each image's header.
The tweakreg task detects sources in multiple images, calculates the shift, rotation and scale between each image and a reference image, then updates the WCS information in the header of each image.
First, tweakreg finds sources in each image. This step, which usually involves experimenting with different values of source-finding parameters, varies depending on the type of image. It is often useful to plot source coordinates on the image to see if there are too many false detections, like cosmic rays, then modify the parameter values accordingly. (An example of how to do this can be found in Section 7.5)
Two useful source-finding parameters are the computesig and threshold parameters in the imagefindpars task (that is called by tweakreg). computesig is a switch for automatically calculating the sky standard deviation in the image, a value that is important for object detection. The threshold parameter value is the detection threshold above the local background, in units of sigma. For this example, computesig retains the default value, yes, and threshold is set to 100 to identify bright stars.
Diagnostic plots created by tweakreg are extremely useful for determining the quality of the offset fit solution:
when use2dhist and see2dplot are set to yes (default settings) in tweakreg, a two-dimensional histogram showing the initially-computed offset is displayed.
When the tweakreg parameter residplot is set to both, two types of plots are displayed: (1) four panels showing fit residuals along the x- and y-axis; (2) a vector plot showing the size of the residuals across the image.
It is usually necessary to run tweakreg a few times, adjusting source detection parameters to obtain enough real sources to compute a good offset fit solution. During these tests, the tweakreg parameter updatehdr is set to no. Once a good solution is found, tweakreg can be re-run with those same parameters with updatehdr set to yes so the WCS information in each image is updated to put them all in the same WCS frame as the reference image.
In this example, tweakreg is run from PyRAF as a command-line. Some users may prefer to use the tweakreg TEAL GUI that can be opened in PyRAF with the “epar tweakreg” command. In that interface, tweakreg should be set to its default values by clicking on the “Default” button at the upper right of the window. Then click on the “Edit imagefind parameters” button (third on the list of tweakreg parameters) to open imagefindpars. In the imagefindpars window, reset the parameter values to their defaults, set threshold to 100, then click “Save and Quit” to return to the tweakreg window to run the task.
Here, tweakreg is run at the command-line in PyRAF:
Figure 7.19: tweakreg Two-Dimensional Histogram Showing Initial Offset Determination Between Two Images, Using Default Parameters Except threshold=100
This two-dimensional histogram shows the initial offset estimate between a reference image and an input image. The tweakreg task measures the x,y positions of each "matched" source in both images to determine the images' offsets in x and y. Not all matched sources are real; some may be cosmic rays or other nearby sources. For a well-defined offset between these two images, the histogram would show a very high number of sources tightly clustered around a specific x,y position on the histogram. Here, the default tweakreg settings with threshold=100 produced a poor offset determination. Out of thousands of sources, offsets appear to be uniformly distributed across the search radius of one arcsecond (20 pixels). The color bar shows that red corresponds to 10 sources, so the uniform red color across the two-dimensional histogram indicates about 10 sources per x,y offset bin. The largest number of objects with the same offset, shown by the small cross at the lower right, is only 48 (out of thousands of sources) at x=12.09, y=-15.07 from the center.
Figure 7.20: Residuals Plots Produced by tweakreg, Using Default Parameters Except for threshold=100
Note the large RMS values. The RMS should be less than 0.1 pixels.
As tweakreg runs, status messages on the screen provide useful information about its progress. For instance, pay attention to the number of objects matched for each image, and the residual RMS for the shifts, scale and rotations. Diagnostic plots are also displayed for each pair of image being aligned and the reference image, as shown in Figures 7.19 and 7.20 that illustrate results for the first image-reference image pair.
In this first attempt, many sources were found in each image but the software was unable to find a good fit in trying to match sources in the image with their counterparts in the reference image. The two-dimensional histogram in Figure 7.19 showed a random uniform distribution of offsets with a very small peak of only 48 sources having the same offset–out of several thousand objects, this is not statistically significant. An inspection of the images, by blinking the reference image and image indicates that the offset should be around -30 in x, and -40 in y.
The next two plots produced by tweakreg are a vector plot of the residuals (not shown), and a plot of the fit residuals (Figure 7.20). In the residuals plot, a large RMS in both x and y directions is clearly apparent. This is the result of using the default search radius value, searchrad=1.0 arcseconds. For images taken during different visits at different orientations, it is possible that the software could not identify a matching source within a one arcsecond radius because the positional uncertainty of the source is larger than the search aperture. In addition, globular cluster observations have a slightly higher likelihood of locking on a “spoiler” guide star in a crowded field, which would throw off the WCS information into a greater mismatch with the reference image. So, it’s worth trying to find matches by running tweakreg using incrementally larger searchrad values to see if the two-dimensional histogram begins to show a well-defined peak.
After trying several more settings, a well-defined offset in the two-dimensional histogram, shown in Figure 7.21, was obtained with searchrad=4.0 arcseconds.
This time, many more sources are matched in the images. The two-dimensional histogram of shifts shows a strong peak and the plot of residuals, seen in Figure 7.22, shows a better fit and RMS (a good RMS value is generally less than 0.1 pixels). Additional results are also reported on the terminal, as shown below.
A small time-dependent skew in the geometric distortion has been corrected for ACS data via improved distortion solutions, as discussed in Appendix A:Plate Scales and Polynomial Distortions. While the effect has largely been corrected, a small residual skew (+/-0.05 pixels) may still remain and this may show up as a slope in the astrometric residual plots. An example of this skew is apparent in Figure 7.22. This is a known limitation in the distortion calibration and does not indicate a problem with tweakreg.
With this good offset fit, tweakreg can be run one last time with the parameter updatehdr=yes so that the header WCS information for all images are updated to match the WCS of the reference image. In addition, the wcsname parameter is set to TWEAK so that the updated set of new WCS header values are identified by the name “TWEAK” (old values are still retained in the image header under different keyword names). Since this tweakreg run is only done to update the images’ WCS, tweakreg parameters for displaying plots may be disabled.
Once the images are aligned, they can be combined using astrodrizzle. For this example, only default values were used to get a quick look at the single-drizzled aligned science images (Figure 7.23) and the final combined image (Figure 7.24).
Figure 7.21: Two-Dimensional Histogram With a Well-Defined Peak After Increasing the tweakreg Search Radius
The two-dimensional histogram of the x and y offsets between all the sources in the reference and input images. In this case the search radius has been expanded to 4 arcseconds (80 pixels, note the different axes from Figure 7.19). A large number of sources were found to have a similar offset, as shown by the red peak in the lower left, while the rest of the image contains random matches shown in blue. These offset values corresponding to the peak are a good first approximation of the offset between the two images.
Figure 7.22: Residuals Plot Corresponding to Figure 7.21
A solution to the shifts was clearly found now that stars have been matched in different images.
Figure 7.23: Section of Each Three Single-Drizzled Science Images Displayed in DS9 and Aligned by the New “TWEAK” WCS
Figure 7.24: Portion of the Final Combined Image
The final combined image shows no evidence of misalignment. A more careful check of the alignment can be done by checking the PSF of a few stars across the field using a task like imexamine.

Table of Contents Previous Next Index Print