求天球坐标系上两个点的距离

该博客介绍了如何利用Astropy库在Python中计算天球坐标系中两个点的角距离。通过读取fits文件的header,转换像素坐标到世界坐标,然后创建SkyCoord对象并计算它们的分离角度。示例代码展示了具体实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

天球坐标系上两个点的距离比我们想象的还要复杂一点,因为要考虑天球坐标是圆的,在大尺度结构上会有变化。运用一下代码可以求得两个坐标之间的角距离

from astropy import wcs
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy import units as u
from astropy.coordinates import Angle

inp = 'file.fits'
hdr = pf.getheader(inp)
w_n = wcs.WCS(hdr)

D1 = w_n.wcs_pix2world([[251, 300]], 0)[0]
D2 = w_n.wcs_pix2world([[200, 300]], 0)[0]
print(D1)
print(D2)
sky1 = SkyCoord(D1[0],D1[1],unit="deg")
sky2 = SkyCoord(D2[0],D2[1],unit="deg")

angle_distance = sk1.separation(sky2)   
#至此得到距离,还回的是Angle的属性

print(Angle(50*u.deg) == angle_distance)
#我们可以用Angle函数,来跟这个距离做一个对比判断。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值