微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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 不会检查您分配给的名称是否合适;该值不是方位角,这就是它与您期望的值不匹配的原因。尝试再次通读文档,并按照其说明生成方位角;希望数字能更好地吻合。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?