8

PyEphemを使用していて、影の長さを計算したいと思います(単位長の棒が地面に植えられていると仮定します)。長さはcot(phi)で与えられます。ここで、phiは太陽高度です(間違っている場合は訂正してください)。太陽でどのフィールドを使うべきかわかりませんか?以下の例では、角度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を使用して、影の長さから次に太陽がその長さの影を落とすまでの逆方向の作業方法について混乱しています。

これについて助けていただければ幸いです。

4

1 に答える 1

10

太陽で使用するフィールドは何ですか?

sun.alt正しいです。alt地平線より上の高度です。北の東の方位角とともに、それらは地平線に対する見かけの位置を定義します。

あなたの計算はほぼ正しいです。オブザーバーを提供するのを忘れました:sun = ephem.Sun(o)

  1. cot(phi)の否定的な結果を解釈する方法がわかりません。誰かが私を助けることができますか?

この場合、太陽は地平線の下にあります。

最後に、ephem.Observer()を指定して、PyEphemを使用して、影の長さから次に太陽がその長さの影を落とすまでの逆方向の作業方法について混乱しています。

関数を指定したスクリプトは次のとおりです。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
于 2011-04-19T23:09:02.823 に答える