在FITS图像中包含WCS坐标

时间:2018-04-17 15:25:21

标签: python physics astronomy astropy

我有一个2D numpy阵列' ZEA_N_sky'最初创建为

n=128
ZEA_N_sky=np.zeros((n,n))

以后,一些值被分配给该数组的每个像素。我可以使用以下代码将此数组绘制为FITS图像(可以通过ds9打开),但我希望也能看到WCS坐标。也就是说,当我将鼠标光标移动到图像上时,我应该能够看到gal-long,gal-lat; Right-Asc,Dec等。我怎样才能做到这一点?我需要手动完成还是有一些header()技巧?

使用WCS包并使用all_pix2world()提供的文档似乎不起作用(我似乎并不理解它)。如果有人可以用代码帮我吗?谢谢!

from astropy.io import fits
import numpy as np
from astropy import wcs
from astropy.table import Table

out_file_name = 'FITS_image.fits'

hdr = fits.Header()
hdr['Projection'] = "ZEA"
hdr['nd_size'] = str(nd_size)
hdr['SCALE']="nd_size/2"
fits.writeto(out_file_name, ZEA_N_sky, hdr,clobber=True)

我取得了一些进展。这是我正在使用的一些代码,我正在使用它获取WCS参数,但是我在FITS图像上获得的经度值是错误的!我想我在ZEA投影参数值中犯了错误。

NSGP=1 #Parameter for North side projection, -1 for south side

w = wcs.WCS(naxis=2)
w.wcs.crpix = [SCALE,SCALE] # SCALE is half the value of my pixel range in the image. n/2=128/2=64
w.wcs.cdelt = np.array([-NSGP*90.0/float(SCALE) * 0.90032, NSGP*90.0/float(SCALE) * 0.90032]) # increments in degrees per pixel
w.wcs.crval = [NSGP*90.0, NSGP*90.0] #RA and dec values in hours and degrees    
w.wcs.ctype = ["GLON-ZEA", "GLAT-ZEA"]
#w.wcs.set_pv([(180, NSGP, float(SCALE))])

out_file_name = 'N_Mateu_ZEA_stream_mask.fits'
# Now, write out the WCS object as a FITS header
header = w.to_header()
hdu = fits.PrimaryHDU(ZEA_N_sky,header=header)
hdu.writeto(out_file_name, clobber=True)

1 个答案:

答案 0 :(得分:1)

尝试使用正确的图像WCS参数制作WCS对象,然后调用header = wcs.to_header,并将图像数据和标题存储在FITS文件中。 请参见示例here

通常您不会自己创建WCS或标题,而是您从FITS文件中读取的内容。在这种情况下,您执行wcs = WCS(header)以从FITS标头创建WCS对象。 请参见示例here