Pyephem calculate current solar time

2019-05-19 19:47发布

问题:

I am trying to calculate the local solar time based on UTC hour and longitude. I have looked through the ephem package but was not able to identify a direct method to do so. Similar questions on this matter either evoke the calculation of fixed positions (sunrise, moon, sunset) (e.g. Calculating dawn and sunset times using PyEphem) or receive suggestions of simplified methods (e.g. Local solar time function from UTC and longitude). Is there any alternative to the aforementioned solutions?

Thanks in advance

回答1:

To compute local solar time, I think that you can just ask for the current right ascension of the point directly beneath the location (its nadir point), and subtract the right ascension of the Sun to learn exactly how far from local midnight it is:

from ephem import Sun, Observer, pi, hours

dt = '2016/08/27 19:19'

sun = Sun()
sun.compute(dt)

boston = Observer()
boston.lat = '42.37'
boston.lon = '-71.03'
boston.date = dt
ra, dec = boston.radec_of('0', '-90')

print 'Sun right ascension:', sun.ra
print 'Boston nadir right ascension:', ra
print 'Solar time:', hours((ra - sun.ra) % (2 * pi)), 'hours'

Could you try out this approach and see whether it gives the numbers you expect to reasonable precision?