mirror of
https://github.com/cosinekitty/astronomy.git
synced 2025-12-25 16:48:34 -05:00
Started work on a Python demo for finding when the moon reaches relative longitudes with other solar system bodies that are multiples of 30 degrees. It is not finished yet, but getting close. Added operator overloads for the Python Time class so that times can be compared against each other. This makes it easier to sort a list of times, for example.
38 lines
1.0 KiB
Python
Executable File
38 lines
1.0 KiB
Python
Executable File
#!/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))
|