Saya menginstal paket python ephem di Sistem Linux GNU / Debian saya dan, saya bisa menggunakannya di Konsol Python QGIS. Saya menciptakan pengamat untuk titik dekat Danau Utah (AS) dan dihitung kenaikan dan matahari terbenam untuk hari '2010/6/21'. Scriptnya adalah:
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. )
Setelah berjalan di Konsol Python QGIS, hasilnya adalah:
>>>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
Ini jawabannya.
Catatan pengeditan :
Mendefinisikan cakrawala baru (misalnya 5 derajat):
.
.
.
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. )
hasilnya adalah:
>>>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