Skyfield 试图计算在给定时间行星在天空中的方向,但得到了错误的答案?

Skyfield 试图计算在给定时间行星在天空中的方向,但得到了错误的答案?,skyfield,Skyfield,我正试图编写一个程序来计算在给定时间地平线上有哪些行星,以及这些行星在天空中的方向,但是我得到了错误的结果。下面是我的代码,有人知道问题是什么吗 import numpy as np import skyfield from skyfield.api import load planets = load('de441.bsp') ts = load.timescale() earth = planets['earth'] other_planets = [planets['mercury ba

我正试图编写一个程序来计算在给定时间地平线上有哪些行星,以及这些行星在天空中的方向,但是我得到了错误的结果。下面是我的代码,有人知道问题是什么吗

import numpy as np
import skyfield
from skyfield.api import load
planets = load('de441.bsp')
ts = load.timescale()

earth = planets['earth']
other_planets = [planets['mercury barycenter'], planets['venus barycenter'], planets['mars barycenter'], planets['jupiter barycenter'], planets['saturn barycenter']]
other_planet_names = ["Mercury", "Venus", "Mars", "Jupiter", "Saturn"]
directions = ["North", "Northeast", "East", "Southeast", "South", "Southwest", "West", "Northwest"]

def planets_visible(time):
    numPlanetsViewed = 0
    for i in range (0, 5):
        az, dec, distance = earth.at(time).observe(other_planets[i]).radec()
        if dec._degrees > 0:
            numPlanetsViewed = numPlanetsViewed + 1
            string = other_planet_names[i] + " is " + str(int((round(dec._degrees, 0)))) + " degrees above the horizon!"
            print(string)
            direction = int(np.floor(((az._degrees - 22.5) % 360) / 45))
            string2 = " It is visible to the " + directions[direction] + "."
            print(string2)
            print(" ")
    if numPlanetsViewed == 0:
        print("Sorry, none of the four major planets are visible at this time!")
        
now = ts.now()
planets_visible(now)

我一直在想,比如说,现在(2021年4月7日,~4:00),正确的行星是可见的——耶但是方位角都关闭了,比如说火星在东南方向时是东北方向(我不能说正确的上升方向,因为我现在不知道它们,但我认为它们也关闭了。)有人知道发生了什么吗?

你需要仔细检查文档:
radec()
不返回方位角和高度,它返回赤经和赤纬。是的,Python允许您调用返回值
az
,但这是因为Python不检查您指定的名称是否合适;该值不是方位角,这就是它与预期值不匹配的原因。再次尝试阅读文档,并按照其说明生成方位角;希望这些数字会更一致