Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用PyEphem计算阴影长度_Python_Shadow_Astronomy_Pyephem - Fatal编程技术网

Python 使用PyEphem计算阴影长度

Python 使用PyEphem计算阴影长度,python,shadow,astronomy,pyephem,Python,Shadow,Astronomy,Pyephem,我使用的是PyEphem,希望计算阴影的长度(假设在地面上种植了一根单位长度的木棍)。长度将由cot(φ)给出,其中φ是太阳仰角(如果我错了,请纠正我)。我不确定?在下面的示例中,我使用的是角度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()

我使用的是PyEphem,希望计算阴影的长度(假设在地面上种植了一根单位长度的木棍)。长度将由cot(φ)给出,其中φ是太阳仰角(如果我错了,请纠正我)。我不确定?在下面的示例中,我使用的是角度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)
请在下面检查我的解释:

  • 如果切线为无穷大,则表示太阳正上方且没有阴影
  • 如果切线为零,则表示太阳在地平线上,阴影无限长
  • 我不知道如何解释cot(phi)的负面结果。有人能帮我吗
  • 最后,我对如何使用PyEphem从阴影长度向后工作到下一次太阳投射该长度的阴影感到困惑,因为给定了一个ephem.Observer()

    我将非常感谢您的帮助

    在太阳上用什么场地

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

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

  • 我不知道如何解释cot(phi)的负面结果。可以 有人帮我吗
  • 在这种情况下,太阳在地平线以下

    最后,我对如何使用感到困惑 皮耶芬从一个 阴影长度到下一次 太阳会投下阴影的 长度,给定一个ephem.Observer()

    下面是一个脚本,它提供了一个函数:
    g(date)->aighty
    计算太阳下次投射阴影的时间,该阴影的长度与现在相同(不考虑方位角——阴影的方向):

    输出
    上面的例子暗示地球上有一个观测者,是吗?如果观察者是环绕地球飞行的卫星呢?地球的阴影会被解释吗?@AjanO:是的,观测者在给定的纬度、经度和时间在地球上。
    #!/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