我正在尝试编写一个程序来计算在给定时间有哪些行星在地平线上方,以及行星在天空中的方向,但我得到的结果不正确。我的代码在下面,有人知道问题可能是什么吗?
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(我不能说正确的提升,因为我现在不知道它们,但我认为那些也关闭了。)有谁知道怎么回事?