如何使用PyEphem计算经度

时间:2011-05-04 10:21:51

标签: python astronomy pyephem

尝试使用PyEphem计算sun lat和long,但是没有与星历表匹配 SUN:2011 MAY 04 We 04 14:46:08 13TA12 =约43度(根据网站www.findyourfate.com)

a = Sun()
a.compute('2011-05-04')
>>> a.hlon
274:18:49.1
>>> a.hlat
0:00:00.1

可能有什么不对?如何计算行星/太阳的经度。的Helio /地心。

2 个答案:

答案 0 :(得分:15)

一个有趣的问题,值得详细解答。

第一个问题。 PyEphem的日期格式为YYYY/mm/dd,而不是YYYY-mm-dd

>>> from ephem import *
>>> Date('2011-05-04')
2010/6/26 00:00:00
>>> Date('2011/05/04')
2011/5/4 00:00:00

(这种行为似乎非常无益。I reported it to Brandon Craig Rhodes as a bug并从PyEphem版本3.7.5.1开始,此行为已得到纠正。)

第二个问题。在PyEphem中,hlon通常是身体的日心经度(以太阳为中心的坐标系统中的经度)。这对太阳毫无意义。所以,作为一个特殊的无证件异常,当你查找太阳的hlonhlat时,你会获得地球的日心经度和纬度

(如果记录下来会很好。I reported this too和PyEphem 3.7.5.1现在提供符合我建议的文档。)

我相信,你想要的是太阳的ecliptic longitude。您可以使用Pyephem的Ecliptic函数找到身体的黄道坐标:

>>> sun = Sun()
>>> sun.compute('2011/05/04')
>>> Ecliptic(sun).lon
43:02:58.9

然而,findyourfate.com报告“13TA12”(即金牛座的13°12',对应于PyEphem的43:12:00)。失踪0:09发生了什么事?我认为这取决于时代的选择(也就是说要考虑多少岁差)。默认情况下,PyEphem使用标准的天文时代J2000.0。但是findyourfate.com似乎正在使用 epoch-of-date

>>> sun.compute('2011/05/04', '2011/05/04')
>>> Ecliptic(sun).lon
43:12:29.0

我希望这一切都清楚:如果没有,请问。


如果要在Python中生成整个表,可以按照以下代码执行。我不知道使用PyEphem计算月球节点的简单方法,所以我没有实现那个位。 (我希望你可以通过迭代搜索来完成,但我还没试过。)

from ephem import *
import datetime
import itertools
import math

zodiac = 'AR TA GE CN LE VI LI SC SG CP AQ PI'.split()

def format_zodiacal_longitude(longitude):
    "Format longitude in zodiacal form (like '00AR00') and return as a string."
    l = math.degrees(longitude.norm)
    degrees = int(l % 30)
    sign = zodiac[int(l / 30)]
    minutes = int(round((l % 1) * 60))
    return '{0:02}{1}{2:02}'.format(degrees, sign, minutes)

def format_angle_as_time(a):
    """Format angle as hours:minutes:seconds and return it as a string."""
    a = math.degrees(a) / 15.0
    hours = int(a)
    minutes = int((a % 1) * 60)
    seconds = int(((a * 60) % 1) * 60)
    return '{0:02}:{1:02}:{2:02}'.format(hours, minutes, seconds)

def print_ephemeris_for_date(date, bodies):
    date = Date(date)
    print datetime.datetime(*date.tuple()[:3]).strftime('%A')[:2],
    print '{0:02}'.format(date.tuple()[2]),
    greenwich = Observer()
    greenwich.date = date
    print format_angle_as_time(greenwich.sidereal_time()),
    for b in bodies:
        b.compute(date, date)
        print format_zodiacal_longitude(Ecliptic(b).long),
    print

def print_ephemeris_for_month(year, month, bodies):
    print
    print (datetime.date(year, month, 1).strftime('%B %Y').upper()
           .center(14 + len(bodies) * 7))
    print
    print 'DATE  SID.TIME',
    for b in bodies:
        print '{0: <6}'.format(b.name[:6].upper()),
    print
    for day in itertools.count(1):
        try:
            datetuple = (year, month, day)
            datetime.date(*datetuple)
            print_ephemeris_for_date(datetuple, bodies)
        except ValueError:
            break

def print_ephemeris_for_year(year):
    bodies = [Sun(), Moon(), Mercury(), Venus(), Mars(), Jupiter(), 
              Saturn(), Uranus(), Neptune(), Pluto()]
    for month in xrange(1, 13):
        print_ephemeris_for_month(year, month, bodies)
        print

答案 1 :(得分:1)

还有一个额外的角色可以让它发挥作用。 在最后一个答案的最后一行旁边:

黄道(b).long必须改为黄道(b).lon

至少在我的64位Windows 7机器上运行32位的2.7位。

此外,如果表格以度数打印出黄道经度,那将会很不错。 :)