Skip to content

Instantly share code, notes, and snippets.

@barentsen
Created January 28, 2015 18:37
Show Gist options
  • Save barentsen/46a4b44223ae05377702 to your computer and use it in GitHub Desktop.
Save barentsen/46a4b44223ae05377702 to your computer and use it in GitHub Desktop.
Silly hack to read the WCS of a Kepler target file into astropy.wcs
"""Reads the WCS for the raw pixel counts into astropy.wcs"""
from astropy.io import fits
from astropy.wcs import WCS
f = fits.open('tpf_dstn.fits.gz')
funny_keywords = {'1CTYP4': 'CTYPE1',
'2CTYP4': 'CTYPE2',
'1CRPX4': 'CRPIX1',
'2CRPX4': 'CRPIX2',
'1CRVL4': 'CRVAL1',
'2CRVL4': 'CRVAL2',
'1CUNI4': 'CUNIT1',
'2CUNI4': 'CUNIT2',
'1CDLT4': 'CDELT1',
'2CDLT4': 'CDELT2',
'11PC4': 'PC1_1',
'12PC4': 'PC1_2',
'21PC4': 'PC2_1',
'22PC4': 'PC2_2'}
mywcs = {}
for oldkey, newkey in funny_keywords.iteritems():
mywcs[newkey] = f[1].header[oldkey]
print(WCS(mywcs).wcs_pix2world(1, 1, 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment