【发布时间】:2016-10-01 00:47:12
【问题描述】:
这是我在这里的第一个问题,所以我会尽力解释清楚。
我正在处理一些适合全天的天文图像,它们位于银河坐标系中(在 AITOF 投影中)。 我想将这些拟合图像转换为 RA,Dec 坐标,以便图像以正确的方式旋转(即银河平面在地图中心将不再水平,而是有点扭曲)。
有人知道怎么做吗?我试图以一种不太优雅的方式来做这件事,我在这里解释一下:
我打开 fit 文件,以及图像所在的 hdu 扩展名。 我阅读了标题的适当关键字 我创建了一个具有相同形状的数组,但是每个元素现在都是几个值,它们将是每个像素的坐标。 然后我将每个元素转换为我想要的新坐标(使用 astropy.coordinates 包),最后我必须移动每个元素以便在新坐标中对它们进行排序(首先它们在银河坐标中排序,现在它们必须按天体分类)。
我到现在为止的这段代码非常慢,我相信一定有更好的方法来做我打算做的事情:
import numpy as np
import pyfits as pf
from astropy.coordinates import ICRS, Galactic
from astropy import units as u
file = pf.open('IC443.fits')
crpixx = file[0].header["CRPIX1"] # X-axis reference pixel number
crpixy = file[0].header["CRPIX2"] # Y-axis reference pixel number
crvalx = file[0].header["CRVAL1"] # X-axis reference pixel value in coordinates (galactic longitude in this case)
crvaly = file[0].header["CRVAL2"] # Y-axis reference pixel value in coordinates (galactic latitude in this case)
stepx = file[0].header["CDELT1"] # X-axis increment per pixel
stepy = file[0].header["CDELT2"] # Y-axis increment per pixel
numpixelsx = file[0].header["NAXIS1"] # number of pixels in X axis
numpixelsy = file[0].header["NAXIS2"] # number of pixels in Y axis
tab = np.zeros([numpixelsx,numpixelsy,2]) # array of zeros with the same
# number of elements than the image, where each element is now a copuple
# of two values
def assign_coords(i,j):
# function to calculate coordinate correspondent to any pixel
coord_i = (-crpix1+i)*step1+crval1
coord_j = (-crpix2+j)*step2 + crval2
return coord_i, coord_j
for k, z in product(np.arange(numpixelsx), np.arange(numpixelsy)):
tab[k][z][0], tab[k][z][1] = assign_coords(k,z)
tab_temp_x = Galactic(tab[k][z][0], tab[k][z][1], unit=(u.degree, u.degree)).fk5.ra.value
tab_temp_y = Galactic(tab[k][z][0], tab[k][z][1], unit=(u.degree, u.degree)).fk5.dec.value
tab[k][z][0] = tab_temp_x # X-coord value in the new coordinates
tab[k][z][1] = tab_temp_y # Y-coord value in the new coordinates
在那之后,我不知道如何以正确的方式对数组进行重新排序......
非常感谢大家!
【问题讨论】:
标签: python astropy fits pyfits