Skyfield返回不正确的经纬度坐标?



我正在尝试制作一个程序,该程序需要国际空间站的纬度和经度坐标(来自Skyfield API)并将其绘制到散点图(使用matplotlib)上,以显示其估计的轨道路径。问题是,当它被绘制到散点图上时,有一堆异常值(最初我认为这只是随机的,但在绘制了一个轨道每秒钟的数据点后,结果是某种其他类型的波形)。

Skyfield以度、分、时(DMS)格式返回经纬度坐标,为了将它们绘制到图形上,我将它们转换为十进制度数(DD),并将每对经纬度坐标插入到一个列表中——所以也许这可能是一些数学问题?下图显示了国际空间站每一秒钟运行轨道的经纬度图,代码是DMS到DD的转换函数,后面跟着默认的matplotlib散点图代码。

ISS纵向散点图图像

def dms2dd(latdms, londms):
latdd = str(latdms)
for num in range(1, 11):
if '0' + str(num) in latdd:
latdd = latdd.replace('0', '')
if ' deg' in latdd or " '" in latdd or ' "' in latdd or ' ."' in latdd:
latdd = latdd.replace(' deg', '(')
latdd = latdd.replace(" '", '')
latdd = latdd.replace(' "', '(')
latdd = latdd.replace(' ."', '')
if latdd.startswith('-'):
latdd = latdd.replace('deg', ' + (-')
latdd = latdd.replace("'", '/60) + (-')
latdd = latdd.replace('"', '/3600)')
else:
latdd = latdd.replace('-', '')
latdd = latdd.replace('deg', ' + (')
latdd = latdd.replace("'", '/60) + (')
latdd = latdd.replace('"', '/3600)')
for x in range(0, 4):
latdd = latdd.removesuffix('+ (-')
latdd = latdd.removesuffix(' + (')
latdd = latdd.replace(' ', '')
latdd = eval(latdd)
londd = str(londms)
for num in range(1, 11):
if '0' + str(num) in londd:
londd = londd.replace('0', '')
if ' deg' in londd or " '" in londd or ' "' in londd or ' ."' in londd:
londd = londd.replace(' deg', '(')
londd = londd.replace(" '", '')
londd = londd.replace(' "', '(')
londd = londd.replace(' ."', '')
if londd.startswith('-'):
londd = londd.replace('deg', ' + (-')
londd = londd.replace("'", '/60) + (-')
londd = londd.replace('"', '/3600)')
else:
londd = londd.replace('-', '')
londd = londd.replace('deg', ' + (')
londd = londd.replace("'", '/60) + (')
londd = londd.replace('"', '/3600)')
for x in range(0, 4):
londd = londd.removesuffix('+ (-')
londd = londd.removesuffix(' + (')
londd = londd.replace(' ', '')
londd = eval(londd)
return latdd, londd

plt.style.use('_mpl-gallery')
# datalat and datalon are just the list versions of the latitude and longitude coords
y = datalat
x = datalon
colors = np.random.uniform(15, 80, len(x))
fig, ax = plt.subplots()
ax.scatter(x, y, s=5, c=colors, vmin=100, vmax=100)
ax.set(xlim=(-180, 180), xticks=np.arange(-180, 180),
ylim=(-90, 90), yticks=np.arange(-180, 180))
plt.show()

令人高兴的是,Skyfield使经度和纬度可以直接使用十进制度数,因此您不需要解析字符串。根据这里的文档,经度和纬度都是Angle类的实例:

https://rhodesmill.org/skyfield/api-topos.html skyfield.toposlib.GeographicPosition.latitude

Angle直接提供度,小时,弧度:

https://rhodesmill.org/skyfield/api-units.html skyfield.units.Angle

所以给定一个地理位置g,你应该能够要求它的g.longitude.degreesg.latitude.degrees,并直接使用这些十进制数字。

最新更新