如何用PyEphem计算经度

2024-05-16 20:48:05 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用PyEphem计算太阳纬度和太阳时长,但与星历不匹配
太阳:2011年5月4日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

怎么了?如何计算行星/太阳的经度。太阳/地心。在


Tags: com网站www行星wesuncomputepyephem
2条回答

有一个额外的角色,必须去做这个工作。 在最后一个答案的最后一行旁边:

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

至少在我的64位Windows7机器上运行32位的2.7版本。在

另外,如果表格以黄道经度的度数打印出来,那就更好了。:)

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

第一个问题。PyEphem的日期格式是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通常是天体的日心经度(太阳中心坐标系中的经度)。这对太阳来说毫无意义。因此,作为一个特殊的未记录的异常,当你查找太阳的hlon和{}时,你会得到地球的日心经度和纬度。在

(如果这件事有记录就好了。I reported this too和PyEphem 3.7.5.1现在提供了遵循我建议的文档。)

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

^{2}$

然而,findyourfate.com报告了“13TA12”(也就是说,金牛座的13°12′,对应于皮耶芬的43:12:00)。失踪的0:09怎么了?我认为这可以归结为历元的选择(也就是说,要考虑多少岁差)。默认情况下,PyEphem使用标准天文历元J2000.0。但是findyourfate.com网站似乎在使用日期纪元:

>>> 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

相关问题 更多 >