-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsky.py
55 lines (42 loc) · 1.63 KB
/
sky.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ephem
from pytz import utc, timezone
from datetime import timedelta
from copy import copy
sun = ephem.Sun()
moon = ephem.Moon()
est = timezone('EST')
def get_observer():
location = ephem.Observer()
location.lon = '-83:23:24'
location.lat = '40:13:48'
location.elevation = 302
location.pressure = 0
location.horizon = '-0:34'
return location
def sunrise(observer, date):
observer.date = date.astimezone(utc)
return observer.next_rising(sun).datetime().replace(tzinfo=utc)
def sunrises(observer, start_date, offset_seconds=0):
# offset negative before, positive after
current_date = copy(start_date)
while 1:
yield sunrise(observer, current_date) + timedelta(seconds=offset_seconds)
current_date = current_date + timedelta(days=1)
def sunset(observer, date):
observer.date = date.astimezone(utc)
return observer.next_setting(sun).datetime().replace(tzinfo=utc)
def sunsets(observer, start_date, offset_seconds=0):
# offset negative before, positive after
current_date = copy(start_date)
while 1:
yield sunset(observer, current_date) + timedelta(seconds=offset_seconds)
current_date = current_date + timedelta(days=1)
def moonset(observer, date):
observer.date = date.astimezone(utc)
return observer.next_setting(moon).datetime().replace(tzinfo=utc)
def moonsets(observer, start_date, offset_seconds=0):
# offset negative before, positive after
current_date = copy(start_date)
while 1:
yield moonset(observer, current_date) + timedelta(seconds=offset_seconds)
current_date = current_date + timedelta(days=1)