更改拟合图像的投影



这是我在这里的第一个问题,所以我会尽力解释清楚。

我正在处理一些全天空的天文图像,这些图像位于银河系坐标(在AITOF投影中)。我想把这些拟合的图像转换成RA、Dec坐标,这样图像就可以以正确的方式旋转(即星系的平面将不再处于地图中心的水平位置,而是有点扭曲)。

有人知道怎么做吗?我试图用一种不那么优雅的方式来做这件事,我在这里解释:

我打开了fits文件,以及图像所在的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

之后,我不知道如何以正确的方式对数组进行重新排序。。。

谢谢大家!

这不是pyfits问题。您必须执行转换。麻木可能会帮助你。

有几个标准(19321958)

请参阅http://scienceworld.wolfram.com/astronomy/GalacticCoordinates.html

最新更新