문제

I'm interested to know at what time(s) a shadow will be cast by an obstacle on the line of sight from the observer to the sun.

So I'd like to back calculate the date/time the sun is in a particular place in the sky relative to an observer. (All the occurrences in a particular year).

Using PyEphem its very straightforward to do the opposite; for an observer position (lat,long) and time calculate sun's position - which makes me wonder why its not simple to do the reverse?

I have hunted around for a solution to this problem and I cannot find one. Any help would be greatly appreciated.

Thanks

도움이 되었습니까?

해결책

This brings up an interesting asymmetry in a wide range of mathematical models — that they have a natural “forward” direction in which we can calculate at time t what we expect a value to be (like the value of the sun’s altitude or azimuth), but no easy way to solve or express the formula in the other direction.

So, we use a range of techniques like optimization, root finding, and curve fitting, where we throw different guesses into the “forward” formula and see what comes out, adjusting the input until the output is close enough to the value we need.

If you look inside of PyEphem at its routines for things like sunrise, sunset, and the equinoxes, you will see examples of iterative searches for matching circumstances using something called Newton's method.

The same technique can be used to determine the times of other circumstances, like: when is the sun at 20° altitude?

import ephem

boston = ephem.Observer()
boston.lat = '42.37'
boston.lon = '-71.03'
boston.date = '2014/1/29 03:12:47'

sun = ephem.Sun()
sun.compute(boston)
print 'Starting altitude:', sun.alt

def f(x):
    boston.date = x
    sun.compute(boston)
    return sun.alt - ephem.degrees('20.0')

x = boston.date
print 'Searching for the correct time...'
ephem.newton(f, x, x + 0.01)
print 'At the time and date', boston.date
print 'the solar altitude is', sun.alt

The output of this script is:

Starting altitude: -57:02:36.3
Searching for the correct time...
At the time and date 2014/1/28 19:30:49
the solar altitude is 20:00:00.0

So it correctly finds the moment when the solar altitude is very, very close to twenty degrees — because Netwon functions look for zero-crossings of the functions they analyze, and we are subtracting 20° from the altitude before letting the Netwon function see it.

There are plenty of resources online about optimization if you want to read more about how to use and control the iterative process it uses, and also some very nice SciPy routines that support optimization that you might want to use instead of the fragile little newton() method used above that comes built into PyEphem:

http://docs.scipy.org/doc/scipy/reference/optimize.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top