PyEphem有多准确上升并在几百年内进行计算?

时间:2017-06-21 01:37:33

标签: pyephem

计算每日的日照时数(日出 - 日出)并找到每年的最大值(通常在冬至但并非总是如此),出现一种有趣的模式。每个世纪大约有5秒钟的阳光消失。

这是PyEphem中的错误因素吗?这是准确的,PyEphem考虑到地球轨道的变化吗?还有其他原因吗?

import pandas as pd
import ephem

sun = ephem.Sun()
raleigh = ephem.Observer()
raleigh.lon, raleigh.lat = "-78.6382", '35.7796'
raleigh.horizon = '-0:34'  # USNO standard atmospheric diffraction
raleigh.pressure = 0       # atmospheric refraction parameters

def riseset(date, f):
    # compute passed function (sunrise or sunset)
    raleigh.date = date
    sun.compute(raleigh)
    sr = ephem.localtime(f(sun))
    return sr

def createdataframe(start, end):
    # create a dataframe index by daily dates, add columns for the
    # sunrise, sunset, and their delta
    df = pd.DataFrame(index=pd.date_range(start=start, end=end,  freq='D'))
    df['date'] = df.index.map(lambda d: d.strftime("%b %d"))
    df['sunrise'] = df.index.map(lambda d: riseset(d, raleigh.next_rising))
    df['sunset'] = df.index.map(lambda d: riseset(d, raleigh.next_setting))
    df['daylightdelta'] = df['sunset'] - df['sunrise']
    return df

def outputmax(df, year):
    i = df['daylightdelta'].idxmax()  # index of the day where the sun is visible above the horizon for the most time
    return "solstice: %s longest day sunrise: %s sunset: %s daylight: %s" % (
        ephem.localtime(ephem.next_solstice(str(year))).strftime("%Y %b %d %X"),
        df.loc[i]['sunrise'].strftime("%b %d %X"),
        df.loc[i]['sunset'].strftime("%T"),
        df.loc[i]['daylightdelta'])

if __name__ == "__main__":
    for year in range(1900,2201):
        # looping through 1900-2200, find the date with the most hours of sunlight
        start = '%d-01-01 04:00:00' % year # compensating for UTC which can throw off pandas columnar math
        end = '%d-12-31 23:59:00' % year
        print outputmax(createdataframe(start, end), year)

1 个答案:

答案 0 :(得分:1)

我的猜测是PyEphem向你展示了一个真实的现象。虽然我不足以列出所有影响数字的所有影响因素,例如最长的一天的长度,但对我来说最突出的一点是地球极点的倾斜随着年龄的变化而变化,目前正在减少:

https://en.wikipedia.org/wiki/Milankovitch_cycles#Axial_tilt_.28obliquity.29

让我们尝试一个非常粗略的背包猜测,这个效果可能具有的大小。如果超过41,000年,倾斜从最大值变为最小值并返回,那么从最大倾斜回到最小值的当前半周期必须花费大约20,500年。虽然当然真正的调整是正弦的,在最大值附近缓慢变化,然后在极端之间的中间更快速的变化,如果它只是线性的,作为第一近似?那么超过20,500年= 205世纪的变化率大致是:

(24.5 - 22.1)度/ 205世纪≅0.01度

因此,轴的倾斜度可能会每年变化大约百分之一度。如果将轴倾斜度改变0.01度,罗利最长的一天会变化多少秒? PyEphem不允许我们任意改变轴向倾斜,所以让我们调整Raleigh的位置。将程序的底部条款更改为:

if __name__ == "__main__":
    year = 2000
    start = '%d-01-01 04:00:00' % year # compensating for UTC which can throw off pandas columnar math
    end = '%d-12-31 23:59:00' % year

    raleigh.lat = '35.76'
    print outputmax(createdataframe(start, end), year)

    raleigh.lat = '35.77'
    print outputmax(createdataframe(start, end), year)

    raleigh.lat = '35.78'
    print outputmax(createdataframe(start, end), year)

作为输出你应该得到:

solstice: 2000 Jun 20 21:47:51 longest day sunrise: Dec 21 07:20:52 sunset: 17:04:27 daylight: 0 days 14:16:24.970989
solstice: 2000 Jun 20 21:47:51 longest day sunrise: Dec 21 07:20:54 sunset: 17:04:26 daylight: 0 days 14:16:28.206467
solstice: 2000 Jun 20 21:47:51 longest day sunrise: Dec 21 07:20:55 sunset: 17:04:24 daylight: 0 days 14:16:31.442902

每个世纪大约三到四秒,这大约是您所看到的效果的大小。我的猜测是,你的程序正在发现行星轴向倾斜的逐渐减少,逐渐使季节变得极端,最长的一天和最长的夜晚不那么极端。