Author Topic: Possible bug in ImageSolver results in exported FITS files  (Read 4718 times)

Offline rga218

  • Newcomer
  • Posts: 37
Hi, I'm attempting to use a FITS image with an embedded WCS solution obtained by ImageSolver, and am finding that the WCS appears to behave rather oddly when applied outside of PixInsight. My image solves perfectly within PixInsight. Here is the WCS for the image (with the FITS header keys shown on the left, and the ImageSolver result shown at the right):

https://www.dropbox.com/s/j5ynukm0qpypkuj/ImageSolver.png

The results from AnnotateImage look excellent:

https://www.dropbox.com/s/hz5vj1mdjlfpp8p/AnnotateImageExample.png

The problem occurs when I try to use the exported image outside of PixInsight, in particular with the ds9 image viewer. The celestial coordinates returned by ds9 are way off... importing a stellar catalog (e.g. NOMAD) shows no alignment with reference stars. Curiously, if I solve the same image using TheSkyX then the agreement with catalogs is excellent. However the WCS keywords embedded by PixInsight look very different from those embedded by TheSkyX, with the sign of the CD1_2 and CD2_2 terms in the rotation matrix reversed.

Here is the image in case anybody wants to play with it:

https://www.dropbox.com/s/21zutxh34b3lhn8/ImageSolverVegaExample.fit

It is a roughly 2.5 x 2 degree image of a field around Vega (obtained with a 400mm f/2.8 lens using a CCD camera with 5.4 micron pixels). The image is oriented so that the X-Y axis points roughly in the N-S direction.

Thank you,

Roberto Abraham

P.S. here are the WCS keywords embedded by PixInsight:

EQUINOX =                2000. / Equatorial equinox
CTYPE1  = 'RA---TAN'           / Axis1 projection: Gnomonic
CTYPE2  = 'DEC--TAN'           / Axis2 projection: Gnomonic
CRPIX1  =               1676.5 / Axis1 reference pixel
CRPIX2  =               1266.5 / Axis2 reference pixel
CRVAL1  =        279.327971188 / Axis1 reference value
CRVAL2  =        38.6798565002 / Axis2 reference value
CD1_1   =    7.92816434949E-06 / Scale matrix (1,1)
CD1_2   =    -0.00079221967717 / Scale matrix (1,2)
CD2_1   =   -0.000792282626439 / Scale matrix (2,1)
CD2_2   =   -7.19229275726E-06 / Scale matrix (2,2)
CDELT1  =   -0.000792318699457 / Axis1 scale
CDELT2  =    0.000792255747321 / Axis2 scale
CROTA1  =         90.546739641 / Axis1 rotation angle (deg)
CROTA2  =         90.546739641 / Axis2 rotation angle (deg)


Here are the corresponding keywords embedded by TheSkyX:

EQUINOX =                2000. / epoch of mean equator & equinox
CTYPE1  = 'RA---TAN'           / gnomonic projection
CTYPE2  = 'DEC--TAN'           / gnomonic projection
CRPIX1  =     1676.08338371305 / pixel i-coordinate at field center
CRPIX2  =     1267.60199073113 / pixel j-coordinate at field center
CRVAL1  =     279.329166666667 / RA at field center
CRVAL2  =     38.6802777777778 / Dec at field center
CD1_1   = 7.56034420304441E-06 / xi rotation-skew-scale matrix element
CD1_2   = 0.000791726504200464 / xj rotation-skew-scale matrix element
CD2_1   = -0.000791551970901808 / yi rotation-skew-scale matrix element
CD2_2   = 7.43568812353928E-06 / yj rotation-skew-scale matrix element
CDELT1  =    -0.00079194016179 / Axis1 scale
CDELT2  =    0.000792040101465 / Axis2 scale
CROTA1  =        90.5408644328 / Axis1 rotation angle (deg)
CROTA2  =        90.5408644328 / Axis2 rotation angle (deg)
RADECSYS= 'FK5     '           / type of RA-Dec
MJD-OBS =                   0. / epoch of observation (TAI MJD)



Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Possible bug in ImageSolver results in exported FITS files
« Reply #1 on: 2013 August 09 16:46:32 »
Roberto,

ImageSolver is sensitive to the FITS coordinate origin preference, and introduces a vertical flip in the matrix elements depending on the setting.

Format Explorer > FITS > Edit Preferences > Miscellaneous Options > Coordinate Origin

Try closing the FITS image, setting the origin to Lower Left Corner, reopening the image and rerunning the script.

Thanks,
Mike

Offline rga218

  • Newcomer
  • Posts: 37
Re: Possible bug in ImageSolver results in exported FITS files
« Reply #2 on: 2013 August 09 17:19:10 »
Dear Mike,

Thank you, that worked perfectly! ImageSolver and AnnotateImage are wonderful tools.

Thanks again,

Roberto

« Last Edit: 2013 August 09 17:29:09 by rga218 »
Roberto Abraham
Professor of Astronomy & Astrophysics
University of Toronto

Offline bob_franke

  • Newcomer
  • Posts: 36
    • Focal Pointe Observatory
Re: Possible bug in ImageSolver results in exported FITS files
« Reply #3 on: 2013 September 14 21:49:34 »
Hello everyone,

Sorry, but I still feel this is a bug / oversight / undocumented feature... Take your pick.

With the default settings, PI displays the image without the vertical flip. The image solver then puts a vertical flip in the Scale Matrix. When PixInsight saves images, the data are never changed. This results in a FITS file without a vertically flipped image and a vertical flip indication in the header.

When PI is set to the display the image vertically flipped, the image solver still puts a vertical flip in the Scale Matrix relative to how the image is displayed. This results in a saved image with the Scale Matrix in agreement with the image data.

Here is a webpage with a more detailed description of my analysis. This includes Aladin screenshots to illustrate the problem.
http://bf-astro.com/eXcalibrator/excalPixInsight2.htm

Regards,
Bob
http://bf-astro.com

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Possible bug in ImageSolver results in exported FITS files
« Reply #4 on: 2013 September 15 10:14:19 »
Hi Bob,

When using ImageSolver only the convention Bottom-Up should be used: The formulas for computing the WCS parameters are extracted from "Representations of world coordinates in FITS", E.W. Greisen and M.R. Calabretta. This paper clearly states in the first paragraph of section 5.1:
Quote
Therefore, we recommend that FITS writers order the pixels so that the first pixel in the FITS file (for each image plane) be the one that would be displayed in the lower-left corner (with the first axis increasing to the right and the second axis increasing upwards) by the imaging system of the FITS writer.

ImageSolver has no way to know how the FITS file is going to be written (bottom-up or up-bottom) so it can not modify the tags to match the orientation in the file.

Until PI v1.7 the default was using the "professional" convention (bottom-up), however since the first release candidate of PI 1.8 this has changed and now PI uses the "amateur" convention (up-bottom).