J'ai installé le paquet ephem python dans mon système Linux GNU / Debian et je pouvais l'utiliser sur la console Python de QGIS. J'ai créé un observateur pour un point près du lac Utah (USA) et il a été calculé le lever et le coucher du soleil pour la journée '2010/6/21'. Le script était:
import ephem
#defining an observer
obs = ephem.Observer()
#defining position
long = '-112.092807'
lat = '40.135114'
obs.long = ephem.degrees(long)
obs.lat = ephem.degrees(lat)
print "long = ", obs.long, "lat = ", obs.lat
#defining date
date = '2010/6/21'
obs.date = ephem.Date(date)
#defining an astronomic object; Sun in this case
sun = ephem.Sun(obs)
r1 = obs.next_rising(sun)
s1 = obs.next_setting(sun)
print "rising sun (UTC time): ", r1
print "setting sun (UTC time): ", s1
r1_lt = ephem.Date(r1 - 6 * ephem.hour) #local time
(y, mn, d, h, min, s) = r1_lt.tuple()
print "rising sun: (local time): {:.2f}".format( h + min/60. + s/3600. )
s1_lt = ephem.Date(s1 - 6 * ephem.hour) #local time
(y, mn, d, h, min, s) = s1_lt.tuple()
print "setting sun (local time): {:.2f}".format( h + min/60. + s/3600. )
Après avoir exécuté sur la console Python de QGIS, le résultat était:
>>>execfile(u'/home/zeito/pyqgis_scripts/ephem.py'.encode('UTF-8'))
long = -112:05:34.1 lat = 40:08:06.4
rising sun (UTC time): 2010/6/21 11:58:58
setting sun (UTC time): 2010/6/21 03:01:14
rising sun: (local time): 5.98
setting sun (local time): 21.02
Telle est la réponse.
Note d'édition :
Définir un nouvel horizon (par exemple 5 degrés):
.
.
.
obs.horizon = '5'
sun = ephem.Sun(obs)
r1 = obs.next_rising(sun)
s1 = obs.next_setting(sun)
print "rising sun (UTC time): ", r1
print "setting sun (UTC time): ", s1
r1_lt = ephem.Date(r1 - 6 * ephem.hour) #local time
(y, mn, d, h, min, s) = r1_lt.tuple()
print "rising sun: (local time): {:.2f}".format( h + min/60. + s/3600. )
s1_lt = ephem.Date(s1 - 6 * ephem.hour) #local time
(y, mn, d, h, min, s) = s1_lt.tuple()
print "setting sun (local time): {:.2f}".format( h + min/60. + s/3600. )
le résultat est:
>>>execfile(u'/home/zeito/pyqgis_scripts/ephem.py'.encode('UTF-8'))
long = -112:05:34.1 lat = 40:08:06.4
rising sun (UTC time): 2010/6/21 12:31:48
setting sun (UTC time): 2010/6/21 02:28:24
rising sun: (local time): 6.53
setting sun (local time): 20.47