View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

calculating with WCS keywords…

Arp wrote on Feb 04, 2011

Hello,

I am writing a program in java, and as a part of it, I want to calculate pixel coordinates, based on wcs header keywords.
So, I got the rotation matrix CD11 CD12 CD21 CD22 already calculated and saved in the header by another program.
Now I want to use these, the CV and CR values to calculate which pixel coordinates a given ra, dec coordinate has.
to understand it: I denote the rotation matrix by

a b = CD11 CD12
c d CD21 CD22
and the keywords are:

CV1 = CRVAL1
CV2 = CRVAL2
CR1 = CRPIX1
CR2 = CRPIX2

I got the following equation:
x = (d(ra-CV1) - b(dec-CV2) + CR1)/(ad-bc)
y = (-c(ra-CV1) + a(dec-CV2) + CR2)/(ad-bc)

I guess the equation should be right. I tested this, but the calculation does not yield the same pixels as DS9. It is right if I enter the CV values, then I correctly get the CR values as the result. But the further I move away from that point, the greater the error in the calculation gets.
I think it might be projection related, but I cant really put my finger on it.
Does somebody know by chance whats wrong?
thx.

Mike Fitzpatrick wrote on Feb 04, 2011

If astrometry were that easy everyone would be doing it 8-) Your equation leaves out all the fun parts of spherical trigonometry and even for a simple TAN projection it makes sense the answers diverge the farther you get from the reference pixel.

Google around for the "AST Library" from Starlink as one library to use for doing WCS in Java, there may be others as well (e.g. WCSTOOLS from SAO is a C-based library you might be able to use).

Last post on Feb 04, 2011