世界坐标系 (astropy.wcs
)#
介绍#
世界坐标系(WCSs)描述了一组坐标与另一组坐标之间的几何变换。一个常见的应用是将图像中的像素映射到天球上。另一个常见的应用是将像素映射到光谱中的波长。
astropy.wcs
contains utilities for managing World Coordinate System (WCS) transformations defined in several elaborate FITS WCS standard 约定。这些变换既可以向前(从像素到世界)也可以向后(从世界到像素)。
由于历史原因和支持遗留软件, astropy.wcs
maintains two separate application interfaces. The High-Level API
should be used by most applications. It abstracts out the underlying object and works transparently with other packages which support the Common Python Interface for WCS ,以更灵活的方式解决问题,并避免 limitations of the FITS WCS standard .
这个 Low Level API
是原版的 astropy.wcs
API,并最初开发为 pywcs
。它将应用程序绑定到 astropy.wcs
打包并将转换限制为它支持的三种不同类型:
核心WCS,定义见 FITS WCS standard 根据马克·卡拉布雷塔的 wcslib . (还包括
TPV
和TPD
扭曲,但不是SIP
)简单成像多项式 (SIP) 惯例。(参见 note about SIP in headers )
FITS WCS中定义的表查找失真 distortion paper .
像素约定和定义#
这两个API都假定整数像素值位于像素的中心(如 FITS WCS standard ,见第2.1.4节 Greisen et al., 2002, A&A 446, 747 )
然而,在被认为是第一个像素的地方有区别。这个 High Level API
遵循Python和C约定,第一个像素是第0个像素,即第一个像素跨越像素值-0.5到+0.5。这个 Low Level API
需要额外的 origin
值为0或1的参数,指示输入数组是基于0还是基于1。然而,笛卡尔坐标系都接受坐标系的低阶输入。公共API中像素坐标((x,y)与(行,列))的顺序取决于所使用的方法或属性,这通常可以通过属性或方法名称来确定。包含“pixel”的属性和方法采用(x,y)顺序,而包含“array”的属性和方法采用(行、列)顺序。
一个简单的例子#
使用高级WCS API的一个示例是使用 pixel_to_world
要使用默认值生成最简单的WCS,请将像素坐标转换为世界坐标:
>>> from astropy.io import fits
>>> from astropy.wcs import WCS
>>> from astropy.utils.data import get_pkg_data_filename
>>> fn = get_pkg_data_filename('data/j94f05bgq_flt.fits', package='astropy.wcs.tests')
>>> f = fits.open(fn)
>>> w = WCS(f[1].header)
>>> sky = w.pixel_to_world(30, 40)
>>> print(sky)
<SkyCoord (ICRS): (ra, dec) in deg
(5.52844243, -72.05207809)>
>>> f.close()
类似地,高级API的另一个用途是使用 world_to_pixel
要生成另一个简单的WCS,同时将世界坐标转换为像素坐标:
>>> from astropy.io import fits
>>> from astropy.wcs import WCS
>>> from astropy.utils.data import get_pkg_data_filename
>>> fn = get_pkg_data_filename('data/j94f05bgq_flt.fits', package='astropy.wcs.tests')
>>> f = fits.open(fn)
>>> w = WCS(f[1].header)
>>> x, y = w.world_to_pixel(sky)
>>> print(x, y)
30.00000214673885 39.999999958235094
>>> f.close()