Astropy版本:5.0.1

astropy.coordinates的文档:Astronomical Coordinate Systems (astropy.coordinates) — Astropy v5.0.1

astropy.wcs的文档:World Coordinate System (astropy.wcs) — Astropy v5.0.1

创建坐标系对象

  • 不同创建方式

默认坐标系框架为国际天球参考系(International Celestial Reference System, ICRS)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord,ICRS

c1 = SkyCoord('19h51m52.11s','8d55m39.1s')#输入字符串
c2 = SkyCoord(297.967, 8.92753, unit="deg")#输入角度
c3 = SkyCoord(297.967 * u.degree, 8.92753 * u.degree)
c4 = SkyCoord("19 51 52.11 +8 55 39.1", unit = (u.hourangle, u.degree))
c5 = SkyCoord("19:51:52.11 +8:55:39.1", unit = (u.hourangle, u.degree))

#还可以用numpy数组输入
ra = np.array([1, 2, 3]) * u.degree
dec = np.array([1, 2, 3]) * u.degree
c6 = SkyCoord(ra, dec, unit=u.degree)

  • 创建不同坐标系下坐标对象
1
2
3
4
5
6
#J2000的赤道坐标系
c1 = SkyCoord(ra = 297.967, dec = 8.92753, unit = u.degree, frame="icrs")
#银道坐标系
c2 = SkyCoord(l = 90, b = 0, unit = u.degree, frame="galactic")
#地平坐标系
c3 = SkyCoord(ra = 0, dec = 0, unit = u.degree, frame="gcrs")
  • 创建地球坐标对象
1
2
from astropy.coordinates import EarthLocation
sysu = EarthLocation.from_geodetic(lat=22.349368*u.deg, lon=113.584068*u.deg, height=10*u.m)

更多astropy.coordinates提供的坐标系介绍可翻阅Astronomical Coordinate Systems (astropy.coordinates) — Astropy v5.0.1的“Built-in Frame Classes”部分。

定义好坐标系对象后,即可进行我们需要的操作。

坐标系之间的转换

以银道坐标转赤道坐标为例:

1
2
3
4
>>>gc = SkyCoord(l = 0, b = 0, unit = u.degree,  frame="galactic")
>>>gc.icrs
<SkyCoord (ICRS): (ra, dec) in deg
(266.40498829, -28.93617776)>

天体角距的计算

若已知两个天体的坐标,利用astropy.coordinates即可方便地算出它们在天球上的角距。

1
2
3
4
>>>Aql_alpha = SkyCoord('19h51m52.11s','8d55m39.1s')
>>>Aql_zeta = SkyCoord('19h55m19.55s','8d31m10.0s')
>>>print(Aql_alpha.separation(Aql_zeta))
0d56m48.45276277s

若在定义坐标对象时包括了距离参数,还可以计算这两个天体的空间距离:

1
2
3
4
>>>Aql_alpha = SkyCoord('19h51m52.11s','8d55m39.1s',distance = 5.14 * u.pc)
>>>Aql_zeta = SkyCoord('19h55m19.55s','8d31m10.0s', distance = 25.5 * u.pc)
>>>print(Aql_alpha.separation_3d(Aql_zeta))
20.36087890223041 pc

不同单位制之间的换算

有时笔者需要在程序中输入目标天体的以角度为单位的坐标,但查询得到的是“hms”形式的坐标,这时用astropy.coordinates即可方便地换算。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
>>>c = SkyCoord('19h51m52.11s','8d55m39.1s')
>>>c.ra.degree
297.967125
>>>c.ra.radian
5.200507393951509
>>>c.ra.hms
hms_tuple(h=19.0, m=51.0, s=52.11000000002116)
>>>c.dec.dms
dms_tuple(d=8.0, m=55.0, s=39.099999999999824)

#输出字符串形式
>>>c.to_string()
'297.967 8.92753'
>>>c.to_string('hmsdms')
'19h51m52.11s +08d55m39.1s'
>>>c.to_string('dms')
'297d58m01.65s 8d55m39.1s'