astrodrizzle computes "output WCS" (either for the single drizzle or for the final drizzle steps) as follows:
Find a "default" WCS:
If user provides a "reference" WCS image - use that image's WCS;
Otherwise, construct the "default" WCS using stwcs.distortion.utils.output_wcs();
If user specifies custom WCS parameters (i.e., using final_rot, final_scale, etc. or driz_sep_rot, driz_sep_scale, etc.), astrodrizzle "merges" user-specified WCS parameters with the default WCS found in the previous step. Sometimes this "merging" requires recomputation of some of the parameters of the default WCS.
A recent footprints ticket number 10154 prompted a review of the code in drizzlepac.wcs_functions.mergeWCS() function which revealed the following problems with the code:
Specification of a custom WCS parameter such as final_scale together with a "reference image" results in the recomputation of the output image size. Due to rounding errors, output size may be 1 pixel smaller than expected.
Every time output image size is computed (essentially, every time user specifies a custom WCS parameter (except for outnx) AND user provides a reference image whose CRPIX is not at the center of the image of the image (NAXIS/2 as used by the code), the computations are simply incorrect: i) image's "footprint" is rotated about NAXIS/2 instead of CRPIX and ii) "merged" WCS' CRPIX is set to outnx,y/2 thus changing the location of the reference point (which is incorrect as this unintentionally shifts the image).
In addition, setting CRPIX to NAXIS/2 is not really correct because the "center" is at the center of the pixel and not at its corner. For example, if we have an image containing a single pixel, then the index of that pixel is at the center of the pixel and thus NAXIS/2 would give 1/2=0.5 instead of 0 (using Python indexing). Secondly, FITS WCS is not using Python indexing but rather 1-based indexing so that the CRPIX of a single pixel image should be 1 instead of 0. Succinctly, correct (for FITS WCS) formula for a CRPIX at the middle of an image should be: (NAXIS+1)/2. This last part probably deserves its own issue (EDIT: see https://github.com/spacetelescope/drizzlepac/issues/63).
astrodrizzle
computes "output WCS" (either for the single drizzle or for the final drizzle steps) as follows:stwcs.distortion.utils.output_wcs()
;final_rot
,final_scale
, etc. ordriz_sep_rot
,driz_sep_scale
, etc.),astrodrizzle
"merges" user-specified WCS parameters with the default WCS found in the previous step. Sometimes this "merging" requires recomputation of some of the parameters of the default WCS.A recent footprints ticket number 10154 prompted a review of the code in
drizzlepac.wcs_functions.mergeWCS()
function which revealed the following problems with the code:final_scale
together with a "reference image" results in the recomputation of the output image size. Due to rounding errors, output size may be 1 pixel smaller than expected.outnx
) AND user provides a reference image whoseCRPIX
is not at the center of the image of the image (NAXIS/2
as used by the code), the computations are simply incorrect: i) image's "footprint" is rotated aboutNAXIS/2
instead ofCRPIX
and ii) "merged" WCS'CRPIX
is set tooutnx,y/2
thus changing the location of the reference point (which is incorrect as this unintentionally shifts the image).In addition, setting
CRPIX
toNAXIS/2
is not really correct because the "center" is at the center of the pixel and not at its corner. For example, if we have an image containing a single pixel, then the index of that pixel is at the center of the pixel and thusNAXIS/2
would give 1/2=0.5 instead of 0 (using Python indexing). Secondly, FITS WCS is not using Python indexing but rather 1-based indexing so that the CRPIX of a single pixel image should be 1 instead of 0. Succinctly, correct (for FITS WCS) formula for a CRPIX at the middle of an image should be:(NAXIS+1)/2
. This last part probably deserves its own issue (EDIT: see https://github.com/spacetelescope/drizzlepac/issues/63).CC: @stsci-hack