STScI Logo

Hubble Space Telescope
DrizzlePac: How to Run Tweakreg

The tweakreg task (see the Drizzlepac Web page) is used align the World Coordinate System (WCS) for images taken during different visits (e.g. on different guide stars). It updates the headers directly with the final shift information (without needing a separate shift file).

To load the package (after pyraf has been started), issue the command:

>>> import drizzlepac

Here are the images will we be aligning.

Note that there are plenty of stars, so we should be able to get a good fit.

You run tweakreg on the _flt.fits (or _flc.fits) files by issuing the command:

>>>epar tweakreg
which will bring up the parameter file for the task.

Note that the first image in your input list will be the reference image for the fit; if you want a different image as the reference, you can specify the file name. The default parameters for imagefind (which determines how the software identifies objects in the image) should work for most images as a good starting point. You should not update the headers until you are certain you have a good fit (i.e. the parameters are optimized for your particular dataset). You should see the Drizzlepac Handbook for suggestions on how to optimize the various parameters for different types of data.

With your parameters set, execute the task. From the task summary, we can see that there are many stars in the fit, that the shifts are small, that there is no rotation, and the RMS is low.

We also get 3 plots. The first plot shows a 2-dimensional histogram for the initial shift. This plot should show a tight cluster around the calculated offset value.

The second plot is a vector plot showing the magntidue with direction of the residuals as a function of location, and is useful for spotting localized systematic deviations in the image alignment. A good alignment yields small, randomly oriented vectors.

The third plot has 4 pieces, which show the fit residuals DX and DY as a function of X and Y position in the image. We want plots where the residuals are flat with no slope, there are no wildly variant points, and the RMS is low.

The solution looks good, but it may be possible to optimize the fit by changing the threshold parameter (see the Drizzlepac handbook for guidance). We will first change the threshold parameter from 4 to 2 to allow more stars to be used in the fit.

We can see that while more stars were used, the RMS in both X and Y is greater than the previous run. This is a clear indication that many of the stars used in the fit are too faint, and hence introduce large uncertainties. After experimentation, we find that increasing the threshold from 4 to 9.5 gives a fit with many stars and low RMS.

We can now rerun tweakreg with the header update turned on. If we look at the headers, we can see that we have added a new WCS definition.

>>>hedit *flt.fits[sci,1] wcsname* .
>>j8cd02tyq_flt.fits[sci,1},WCSNAME0 = OPUS...................original fit
>>j8cd02tyq_flt.fits[sci,1},WCSNAME  = TWEAK..................fit used for display/processing
>>j8cd02tyq_flt.fits[sci,1},WCSNAMEA = IDC-p7d1548qj...pipeline fit
>>j8cd02tyq_flt.fits[sci,1},WCSNAMEB = TWEAK................tweakreg fit 

There are 3 solutions - the original fit, the pipeline fit, and the new tweakreg fit; the WCSNAME keyword contains the fit that will be used for displaying and processing the data. We can now run astrodrizzle on the data.

We can now look at a matching problem (this is similar to example 7.3 in the Drizzlepac handbook). Since this is a very crowded field, I have set the threshold to 100 to just use the brightest stars.

In this case, there were plenty of stars found in the images, but the residuals are high, and only a few matches were found. Looking at the histogram plot, we do not see a clustering of points, but rather a random distribution.

If we look at the data, we can see the problem.

The coordinates of the circled star differ by over 2" between the 2 images. In this case, the imagefind parameters are fine, but the WCS offset between the images is larger than our 1" search radius. We therefore need to modify the search radius to be 4".

We now run tweakreg and get the following:

We now have 6687 stars in the fit, and the fit is good. Looking at the histogram, we see a tight cluster at an offset of -31, -41. With an image scale of 0.05"/pixel, we derive an offset of around 2", as expected from our visual inspection of the data.

We would now run tweakreg again with header updating turned on, and then run on more time with the updated headers to see if there is anything other problems.