PyEphem:如何计算月球节点的位置?

时间:2015-05-29 10:50:59

标签: pyephem

有没有办法在pyEphem中获取Moon的上升/下降节点(北/南节点)的经度?

由于

1 个答案:

答案 0 :(得分:0)

Pyephem可以在某些日期计算行星的位置,但反之亦然,因此我通常将在一段时间内计算出的行星位置存储在数据框中并从那里开始工作。这就是我搜索Moon节点的方式:

import ephem
import pandas as pd
import numpy as np

# Let's create a data frame with 2 columns: lon and lat to store
# the daily ecliptic coordinates of Earth's Moon for the year 2001.
# I like to work in degrees of the circle, so I always convert from radians.
Mo = ephem.Moon()
df = pd.DataFrame(index=pd.date_range(start='2001-01-01', end='2001-12-31', freq='D'))
df['lon'] = df.index.map(lambda d: [Mo.compute(d, epoch=d), np.rad2deg(ephem.Ecliptic(Mo).lon)][1])
df['lat'] = df.index.map(lambda d: [Mo.compute(d, epoch=d), np.rad2deg(ephem.Ecliptic(Mo).lat)][1])

# To find the Moon's nodes you need to first find the dates when Moon
# is crossing the ecliptic (so its latitude changes sign), then find
# the longitudes for those dates.
xdates = df.index[np.where(np.diff(np.sign(df['lat'].values)) != 0)]
nodes = df['lon'][xdates]

要验证结果,首先打印df统计数据,您应该看到如下内容:

In [180]: df.describe()
Out[180]:
              lon         lat
count  365.000000  365.000000
mean   181.984888   -0.285830
std    107.690034    3.642805
min      0.910882   -5.298351
25%     85.118205   -3.918240
50%    184.577992   -0.595535
75%    277.629225    3.290252
max    359.851182    5.285288

注意最大纬度为5.285288,等于月球和太阳轨道平面之间的角度。接下来打印xdates:

In [181]: xdates
Out[181]:
DatetimeIndex(['2001-01-09', '2001-01-22', '2001-02-06', '2001-02-19',
               '2001-03-05', '2001-03-18', '2001-04-01', '2001-04-14',
               '2001-04-28', '2001-05-11', '2001-05-25', '2001-06-07',
               '2001-06-21', '2001-07-05', '2001-07-19', '2001-08-01',
               '2001-08-15', '2001-08-28', '2001-09-11', '2001-09-24',
               '2001-10-08', '2001-10-21', '2001-11-04', '2001-11-17',
               '2001-12-02', '2001-12-15', '2001-12-29'],
              dtype='datetime64[ns]', freq=None)

并将日期与第三方来源进行比较,即。月亮的2001年过境日期可以在这里找到:http://astropixels.com/ephemeris/moon/moonnodes2001.html。注意,节点序列是asc,desc,asc,desc等,并且任何两个连续节点相隔大约180度。

如果您需要使用黄道快速查找月球交叉口的日期,此方法效果最佳,因为经度值是在午夜计算的,月球可以行进到大约。每天经度15度,所以为了获得更好的准确性,你必须经过交叉日期的每一分钟才能找到1度精度的实际时间和经度,或者使用这个肮脏的小黑客:

# Calculate lon and lat diffs on the main data frame:
df['lon_diff'] = df['lon'].diff()
df['lat_diff'] = df['lat'].diff()

# Export the nodes' rows into a separate data frame and for each row there
# find the longitude of the crossing by the formula:
#  lon_x = lon + (lat/lat_diff) * lon_diff
nodes = df.ix[xdates]
nodes['lon_x'] = nodes.apply(lambda r: r['lon'] + np.abs(r['lat']/r['lat_diff'])*r['lon_diff'], axis=1)

差异告诉我们月球每天有多少度lon或lat,所以比率lat:lat_diff告诉月亮在午夜与黄道的距离,或者换句话说,月亮的1天是多少?需要实际达到0度纬度。此值乘以当天的lon_diff,得出月亮在午夜的位置和交叉点的位置之间的经度数。我希望这种方法对你来说足够准确:)