首页 > 解决方案 > Astropy WCS 变换矩阵

问题描述

我正在尝试创建一个自定义 WCS 将图像的像素坐标转换为世界坐标。

给定一张带有星星的图像,我已经确定了 2 颗星星,因此我可以将图像中两个点的像素 (x,y) 与 (RA,DEC) 匹配。

我现在想要的是创建一个具有适当变换矩阵的自定义 WCS,因此当我给出任何像素坐标时,它将返回相应的 RA 和 DEC。

我知道 astrometry.net 会这样做,并使用适当的转换矩阵编写适合标题。

我的问题是,我怎样才能得到这个转换矩阵并创建我的自定义 WCS 对象?

谢谢。

编辑:这是我正在尝试的代码:

from astropy.coordinates import SkyCoord
import astropy.units as u
from astropy.wcs import WCS
from astropy.wcs.utils import fit_wcs_from_points
import numpy as np
# I have the following stars identified in my image (andromeda):
#  (X, Y)       --> (RA in degrees, DEC in degrees) --> HIP_ID
#  (640, 555)   --> (17.43421495, 35.61993419)      --> 5447
#  (1076, 32)  --> (2.09777329, 29.08952671)        --> 607
#  (161, 903)  --> (30.9751282, 42.32944223)        --> 9640
#  (932, 327)  --> (9.83272908, 30.86056254)        --> 3092
stars = SkyCoord(ra=[17.43421495, 2.09777329, 30.9751282, 9.83272908], 
                 dec=[35.61993419, 29.08952671, 42.32944223, 30.86056254], 
                 unit=u.deg)
stars
pixels_x = np.array([640, 1076, 161, 932])
pixels_y = np.array([555, 32, 903, 327])
wcs = fit_wcs_from_points((pixels_x, pixels_y), stars); wcs
wcs.wcs_pix2world(np.array([[640]]),np.array([555]),0)

为什么我什至没有得到正确的参考点?

标签: pythonastropyastronomy

解决方案


代码是正确的,问题是 Astropy 库的版本,见 bug:https ://github.com/astropy/astropy/pull/10155 。

如果有人遇到这个问题,请确保您没有使用 Astropy 4.0.1。


推荐阅读