Pyephem calculate current solar time
<p>I am trying to calculate the local solar time based on UTC hour and longitude. I have looked through the <code>ephem</code> 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. <a href="http://stackoverflow.com/questions/2637293/calculating-dawn-and-sunset-times-using-pyephem">Calculating dawn and sunset times using PyEphem</a>) or receive suggestions of simplified methods (e.g. <a href="http://stackoverflow.com/questions/13314626/local-solar-time-function-from-utc-and-longitude">Local solar time function from UTC and longitude</a>). Is there any alternative to the aforementioned solutions?</p>

<p>Thanks in advance</p>

<p>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: </p>

<pre><code>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'
</code></pre>

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

python pyephem