spacetelescope / drizzlepac

AstroDrizzle for HST images.
https://drizzlepac.readthedocs.io
BSD 3-Clause "New" or "Revised" License
51 stars 38 forks source link

Multiple issues related to how astrodrizzle uses custom WCS parameters #62

Closed mcara closed 7 years ago

mcara commented 7 years ago

astrodrizzle computes "output WCS" (either for the single drizzle or for the final drizzle steps) as follows:

  1. 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();
  2. 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:

  1. 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.
  2. 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).

CC: @stsci-hack

mcara commented 7 years ago

Solved in https://github.com/spacetelescope/drizzlepac/pull/65