How to determine if it is daytime (light outside?) in python using ephem library -
the ephem python library can determine next sunrise , sunset.
what want know if lite outside or not @ moment in time. there simple function phone call in ephem returns this?
organizations united states of america naval observatory have definitions “it lite outside” — can find usno’s definitions here:
http://aa.usno.navy.mil/faq/docs/rst_defs.php
once take definition want, inquire sun
object alt
, compare value height in definition usno. recommend utilize alt
, fast pyephem compute. if instead inquire sunrise , sunset, sent pyephem off on expensive iterative search has maintain trying different times of day until discovers moment of sunrise , sunset — not interested in, sounds like. want compare sun's height own threshold “is lite outside.”
note alt
in radians, need convert chosen number of degrees before comparing:
import ephem
s = ephem.sun() sf = ephem.city('san francisco') s.compute(sf) twilight = -12 * ephem.degree print 'is lite in sf?', s.alt > twilight
python light pyephem
No comments:
Post a Comment