Go up one levelGo to Previous Go to Next

Converting between World and Image Pixel Coordinates

Conversion between world and image coordinates is handled by the WCS and related classes. Class WCS is a reference counted class that manages a pointer to a subclass of the abstract base class WCSrep . SAOWCS is a subclass of WCSRep , which is based on Doug Mink's wcssubs package (also used by saoimage ) 1 . This class is initialized with a FITS image header and can then be used to convert coordinates and distances on the image.

Example:

 
WCS wcs(new SAOWCS(fitsHeaderString)); 
double x, y, ra, dec; 
... 
// convert x,y to world coords 
if (wcs.pix2wcs(x, y, ra, dec) != 0) {
    return ERROR;
} 
// convert ra,dec to image coords 
if (wcs.wcs2pix(ra, dec, x, y) != 0) {
    return ERROR;
}

The WCS class uses reference counting in order to make it easy to share an instance of the class among other classes. In the above example, the memory allocated for the SAOWCS object is managed by the WCS class and deleted when there are no more references to it.

 
WCS wcs2 = wcs; // both are reference counted copies of the same object !

The WCS class also has support for setting up world coordinates without a FITS header, with the wcs method:

 
wcs.set(ra, dec, secpix, xrefpix, yrefpix, nxpix, nypix, rotate, equinox, 
        epoch, proj);

The arguments here are:

ra

Center right ascension in degrees.

dec

Center declination in degrees.

secpix

Number of arcseconds per pixel.

xrefpix

Reference pixel X coordinate.

yrefpix

Reference pixel Y coordinate.

nxpix

Number of pixels along x-axis.

nypix

Number of pixels along y-axis.

rotate

Rotation angle (clockwise positive) in degrees.

equinox

Equinox of coordinates, 1950 and 2000 supported.

epoch

Epoch of coordinates, used for FK4/FK5 conversion no effect if 0.

proj

Projection

For changing the center of the projection, you can use the shift method:

 
wcs.shift(ra, dec, equinox);

The leaves all of the other parameters the same, but changes the center reference position. More information can be found in the man page WCS(3) .


1. The GAIA plugin for skycat also defines a subclass of WCSRep based on the Starlink libraries.


Go up one levelGo to Previous Go to Next

Please send questions or comments to abrighto@eso.org.
Copyright © 1998 ESO - European Southern Observatory