【问题标题】:Compute shadow length using PyEphem使用 PyEphem 计算阴影长度
【发布时间】:2011-08-08 21:40:36
【问题描述】:

我正在使用 PyEphem 并想计算阴影的长度(假设将一根单位长度的棍子种植在地下)。长度将由 cot(phi) 给出,其中 phi 是太阳仰角(如果我错了,请纠正我)。我不确定what field to use on the Sun?在下面的示例中,我使用了角度 alt:

import ephem, math
o = ephem.Observer()
o.lat, o.long = '37.0625', '-95.677068'
sun = ephem.Sun()
sunrise = o.previous_rising(sun, start=ephem.now())
noon = o.next_transit(sun, start=sunrise)
shadow = 1 / math.tan(sun.alt)

请在下面查看我的解释:

  1. 如果切线是无限的,则表明太阳就在头顶,没有阴影。
  2. 如果切线为零,则表示太阳在地平线上,阴影无限长。
  3. 我不知道如何解释 cot(phi) 的阴性结果。有人可以帮我吗?

最后,给定一个 ephem.Observer(),我对如何使用 PyEphem 从阴影长度倒退到下一次太阳将投射该长度的阴影感到困惑。

我将不胜感激。

【问题讨论】:

    标签: python shadow astronomy pyephem


    【解决方案1】:

    在太阳上使用什么场?

    sun.alt 是正确的。 alt 是地平线以上的高度;连同北以东的方位角,它们定义了相对于地平线的apparent position

    您的计算几乎是正确的。你忘了提供观察者:sun = ephem.Sun(o)

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

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

    最后,我对如何使用感到困惑 PyEphem 从 影子长度到下次什么时候 太阳会投下那个阴影 长度,给定一个 ehem.Observer()。

    这是一个给定函数的脚本:g(date) -> altitude 计算下一次太阳投射与现在相同长度的阴影的时间(不考虑方位角 -- 阴影的方向):

    #!/usr/bin/env python
    import math
    import ephem    
    import matplotlib.pyplot as plt
    import numpy as np
    import scipy.optimize as opt
    
    def 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 timezone
    
    def 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 inplace
    
    def 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 method
    
    
    if __name__=="__main__":
        main()
    

    输出

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

    【讨论】:

    • 上面的例子暗示了地球上的观察者,是吗?如果观察者是环绕地球的飞行卫星,那会怎样?地球阴影会被计算吗?
    • @AjanO: 是的,观察者在地球上给定的纬度、经度、时间。
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 2017-09-24
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多