试图计算给定时间行星天空的方向,但得到不正确的答案?

问题描述

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

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(我不能说正确的提升,因为我现在不知道它们,但我认为这些也是关闭的。)有人知道怎么回事吗?

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...