Skip to content

Instantly share code, notes, and snippets.

@barentsen
Created March 28, 2017 21:26
Show Gist options
  • Save barentsen/548f88ef38f645276fccea1481c76fc3 to your computer and use it in GitHub Desktop.
Save barentsen/548f88ef38f645276fccea1481c76fc3 to your computer and use it in GitHub Desktop.
Simple example for conversion from pixel (x,y) to celestial (ra,dec) using astropy
"""Example conversion from pixel coordinates to ra/dec."""
from astropy.io import fits
from astropy.wcs import WCS
x, y = 250, 250
f = fits.open('f242_e0_c98.fits')
mywcs = WCS(f[0].header)
ra, dec = mywcs.all_pix2world([[x, y]], 0)[0]
@alisson26
Copy link

x, y = 250, 250 are the length of data in axis 1 and 2 of the fits file?

This script can be applied to fits file with header like this in attach image?

Captura de tela de 2024-04-29 11-35-22

Thanks in advanced for u help, dear.

@derrickrcochran
Copy link

derrickrcochran commented Feb 19, 2025

The script is optimized to convert pixel coordinates to celestial coordinates using the Astropy library, ensuring the necessary compatibility headers is important, especially when using poppy playtime chapter 3 to reference specific data formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment