栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用PyEphem计算阴影长度

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用PyEphem计算阴影长度

在太阳上使用哪个场?

sun.alt
是正确的。
alt
是地平线以上的高度;它们与北方以东的方位角一起确定了相对于地平线的视在位置。

您的计算几乎是正确的。您忘记提供观察员了:

sun = ephem.Sun(o)

  1. 我不知道如何解释cot(phi)的负面结果。有人能帮我吗?

在这种情况下,太阳在地平线以下。

最后,对于给定ephem.Observer(),我对如何使用PyEphem从阴影长度向后工作感到困惑,直到下次太阳将投射该长度的阴影时。

这是一个提供功能的脚本:

g(date) -> altitude
计算下次太阳投射阴影的时间与当前长度相同(方位角-不考虑阴影的方向):

#!/usr/bin/env pythonimport mathimport ephem    import matplotlib.pyplot as pltimport numpy as npimport scipy.optimize as optdef main():    # find a shadow length for a unit-length stick    o = ephem.Observer()    o.lat, o.long = '37.0625', '-95.677068'    now = o.date    sun = ephem.Sun(o) #NOTE: use observer; it provides coordinates and time    A = sun.alt    shadow_len = 1 / math.tan(A)    # find the next time when the sun will cast a shadow of the same length    t = ephem.Date(find_next_time(shadow_len, o, sun))    print "current time:", now, "next time:", t # UTC time    ####print ephem.localtime(t) # print "next time" in a local timezonedef update(time, sun, observer):    """Update Sun and observer using given `time`."""    observer.date = time    sun.compute(observer) # computes `sun.alt` implicitly.    # return nothing to remember that it modifies objects inplacedef find_next_time(shadow_len, observer, sun, dt=1e-3):    """Solve `sun_altitude(time) = known_altitude` equation w.r.t. time."""    def f(t):        """Convert the equation to `f(t) = 0` form for the Brent's method.        where f(t) = sun_altitude(t) - known_altitude        """        A = math.atan(1./shadow_len) # len -> altitude        update(t, sun, observer)        return sun.alt - A    # find a, b such as f(a), f(b) have opposite signs    now = observer.date # time in days    x = np.arange(now, now + 1, dt) # consider 1 day    plt.plot(x, map(f, x))    plt.grid(True)    ####plt.show()    # use a, b from the plot (uncomment previous line to see it)    a, b = now+0.2, now+0.8    return opt.brentq(f, a, b) # solve f(t) = 0 equation using Brent's methodif __name__=="__main__":    main()

输出量

current time: 2011/4/19 23:22:52 next time: 2011/4/20 13:20:01


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/659912.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号