-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathlunarday.py
executable file
·37 lines (33 loc) · 1.03 KB
/
lunarday.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
#!/usr/bin/env python3
#
# lunarday.py - Example of calculating lunar days.
#
import sys
import math
from astronomy import Time, MoonPhase, SearchMoonPhase
def main(args):
if len(args) == 1:
time = Time.Now()
elif len(args) == 2:
time = Time.Parse(args[1])
else:
print('USAGE: {} [yyyy-mm-ddThh:mm:ssZ]'.format(args[0]))
return 1
# Get the Moon phase at the starting time, so we know what
# multiple of 12 degrees to search for next.
phase = MoonPhase(time)
print("{} : Moon's phase angle = {:0.6f} degrees.".format(time, phase))
print()
print('The next 30 lunar days are:')
target = 12.0 * math.ceil(phase / 12.0)
for _ in range(30):
time = SearchMoonPhase(target, time, 2.0)
if time is None:
print('SEARCH FAILURE.')
return 0
d = 1 + int(target / 12)
print('{} : Lunar Day {}'.format(time, d))
target = math.fmod(target + 12.0, 360.0)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))