Ho installato il pacchetto ephem python nel mio sistema GNU / Debian Linux e, potrei usarlo nella console Python di QGIS. Ho creato un osservatore per un punto vicino allo Utah Lake (USA) ed è stato calcolato il sorgere e il tramonto del sole per il giorno "2010/6/21". La sceneggiatura era:
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. )
Dopo l'esecuzione sulla console Python di QGIS, il risultato è stato:
>>>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
Questa è la risposta
Nota di modifica :
Definire un nuovo orizzonte (ad esempio 5 gradi):
.
.
.
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. )
il risultato è:
>>>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