【问题标题】:How to calculate longitude using PyEphem如何使用 PyEphem 计算经度
【发布时间】:2011-08-18 10:08:03
【问题描述】:

尝试使用 PyEphem 计算太阳经纬度,但与星历不匹配
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/地心。

【问题讨论】:

  • 只是猜测,但是否与您输入“2011-05-04”没有具体时间信息有关?
  • 没关系,只要变化很小。但是 43 对 274 是巨大的。一定是缺少了什么。
  • 说我疯了,但我认为惯例是 -180
  • @John Machin - 没必要。一些系统mod 360 和西半球是 180 .. 359。

标签: python astronomy pyephem


【解决方案1】:

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

第一个问题。 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 时,您会得到地球的日心经度和纬度。 p>

(如果记录在案就好了。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

【讨论】:

  • 谢谢。这对我来说是完美的答案。它解决了我的问题。但是,只有 Sun 需要黄道平移吗?或所有行星(行星在我的情况下也不匹配,所以我会尝试翻译它们)。谢谢。
  • 是的,似乎所有天体都需要黄道经度。请参阅打印表格的代码。你能解释一下你用这个做什么吗?
  • 是的,我对所有的身体都使用了黄道,结果很好。我正在尝试将它用于我在股票市场的个人研究项目,以了解江恩方法的相关性或现实性。
  • 出色的解释布兰登。顺便说一句,在上面的例子中,(Ecliptic(sun).lon) 返回 0.7513583544261719。要返回 43:02:58.8,我认为需要使用“打印”语句
【解决方案2】:

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

Ecliptic(b).long 必须更改为 Ecliptic(b).lon

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    相关资源
    最近更新 更多