0

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

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),正确的行星是可见的——耶!– 但是方位角都关闭了,例如,当它是 SE 时,说火星是 NE(我不能说正确的提升,因为我现在不知道它们,但我认为那些也关闭了。)有谁知道怎么回事?

4

1 回答 1

1

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

于 2021-04-08T03:47:32.977 回答