Find physical coordinates of a pixel in a fits file with python -
I am stuck in a python script to get the physical sky coordinates of a given pixel from the wcs of astropy I would like to use, but I will do anything from within the dragon
I have tried these two snippets of code. Astropy.io Import fits from
to WCS def astropymethod1 (IMG) from ASTROP. WESSES: # from http://astropy.readthedocs.org/en/latest/wcs/w = WCS (IMG) lawn, lat = w.all_pix2world (100., 100., 1) Print Lawn, Let Df Astropaimeth 2 (IMG): # from http://astropy.readthedocs.org/en/latest/wcs/hdu = Fits.open (IMG) w = WCS (HDU [0] .hader) Lone, LET = w.wcs_pix2world (100., 100., 1) Print Lone, LET me The first time I get the error when I try to use WCS for the first time and the result is only pixel value at any time. I've gotten. Warning: FITSFixed Warning: WCS conversion is associated with more axes (2) images (0) [astropy.wcs.wcs] < P>
The problem is that you have a multi-extension FITS file. Here's an example session showing how you can gain access to the appropriate WCS:
in : fits into astropy.io import from [2]: h = fits . Structure ('SN1415_F625W_1_drz Fits') [3]: f = fits.open ('SN1415_F625W_1_drz.fits') [4]: F Out [4] [& LT; Astropy.io.fits.hdu.image.PrimaryHDU at 0x106735490>, & lt; Astropy.io.fits.hdu.image.ImageHDU at 0x106749750>, & lt; Astropy.io.fits.hdu.image.ImageHDU> 0x106751310, & lt; Astropy.io.fits.hdu.image.ImageHDU 0x106751d10 & gt;; & lt; 0x1067dfdd0 & gt; astropy.io.s..hdu.table.BinTableHDU;] [5]: Astropy Import from WCS [6]: w = wcs.WCS (f [0] .header) WARNING: FITSFixed Warning: In WCS conversion In the image (0) [astropy.wcs.wcs] [7]: w.wcs.naxis [7]: 2 [8]: F. [0] has more axis than the image associated with [0]. In data [9]: w = wcs.WCS (F [1] .header) [10]: w.wcs.naxis out [10]: 2 in [11]: F [1] .Data out [11] : Array ([[0.0198678, -0.04018363, 0.03330525, ..., 0., 0., 0.], [0.0695872, -0.00 9 7, 143, 0.00147662, ..., 0., 0 ., 0.], [-0.09292094, 0.02481506, -0.01057338, ..., 0., 0., 0.] ... ..., [0., 0., 0., ..., 0.02375774 , 0.0389731, 0.03825707], [0., 0., 0., ..., -0.015709-18, -0.01053802, 0.00461219], [0., 0., 0., ..., -0.0638448, -0.0240754 , 0.02679451]], dtype = float32 [12] :. W.wcs_pix2world (100, 100, 1) out [12] [array (6.113076380801787), array (0.616758775753701)] So you probably want to redefine your method: / P>
def astropymethod2 (IMG, HDID = 1): # from http://astropy.readthedocs.org/en/latest/wcs/hdu=fit (IMG) w = wcs (hdu [hduid]. Header) lon, lat = w.wcs_pix2world (100., 100., 1) Print lawn, late
Comments
Post a Comment