Getting on-sky coordinates from a TPV projection

TPV projection is used to store WCS information for DECam images. This example shows how to convert pixel coordinates to on-sky coordinates. More information on the TPV projection is available here: http://iraf.noao.edu/projects/ccdmosaic/tpv.html

We first need to import the tpv package and astropy.io.fits package.


In [25]:
import tpv
from astropy.io import fits

%matplotlib inline

In this example, we have a stellar catalog created using the daophot allstar command (catalog.txt). The first two columns give us x and y coordinates of detected stars in the pixel coordinates.

After that we read in the image header from the fits image (chip.fits). To get the equatorial coordinates for every star detection, we just call the tpv.transform command.


In [26]:
# read positions of stars
x, y = np.loadtxt('catalog.txt', usecols=(1,2), skiprows=3, unpack=True)

# read header
hdulist = fits.open('chip.fits')
head = hdulist[0].header

# convert positions to equatorial coordinates
ra, dec = tpv.transform(x, y, head)

We can plot the stars in both the pixel space (top) and their equatorial coordinates (bottom). We plot only every 50th star to avoid overcrowding. The stellar patterns are similar on these two panel, but slight differences exist due to the field distortion.


In [27]:
# plot detected stars
# pixel coordinates
plt.subplot(211)
plt.plot(y[::50], x[::50], 'ko')
plt.xlabel('X')
plt.ylabel('Y')
plt.gca().invert_yaxis()

# equatorial coordinates
plt.subplot(212)
plt.plot(ra[::50], dec[::50], 'ko')
plt.xlabel('RA')
plt.ylabel('Dec')

plt.tight_layout()



In [27]: