mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-01-30 18:21:56 -05:00
It makes more sense to report Jupiter's moons with individually named structure fields rather than an array. It reduces the overall code and documentation size, and outside of unit testing, there are few cases where iterating over an array of moons is more lucid than using the names of the moons. This is a breaking change, but hopefully very few developers are using this function yet. Fixing the breakage is very simple. Also added operator overloads for adding and subtracting StateVector, just like we already had for Vector.
70 lines
2.7 KiB
Python
Executable File
70 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# jupiter_moons.py - by Don Cross - 2021-04-15
|
|
#
|
|
# Example Python program for Astronomy Engine:
|
|
# https://github.com/cosinekitty/astronomy
|
|
#
|
|
# Calculates the coordinates of Jupiter and its four major moons
|
|
# (Io, Europa, Ganymede, and Callisto) as seen from the Earth
|
|
# at a given date and time. This program illustrates how to correct
|
|
# for the delay caused by the time it takes for light to reach
|
|
# the Earth from the Jupiter system.
|
|
#
|
|
import sys
|
|
from astronomy import Time, JupiterMoons, GeoVector, EquatorFromVector, Body, C_AUDAY
|
|
|
|
def PrintBody(name, geovec):
|
|
# Convert the geocentric vector into equatorial coordinates.
|
|
equ = EquatorFromVector(geovec)
|
|
print('{:<8s} RA {:10.6f} DEC {:10.6f} {:10.6f} AU'.format(name, equ.ra, equ.dec, equ.dist))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# If date/time is provided on the command line, use it.
|
|
# Otherwise, use the current date and time.
|
|
if len(sys.argv) == 2:
|
|
time = Time.Parse(sys.argv[1])
|
|
else:
|
|
time = Time.Now()
|
|
print('Calculations for:', time)
|
|
|
|
# Call GeoVector to calculate the geocentric position of Jupiter.
|
|
# GeoVector corrects for light travel time.
|
|
# That means it returns a vector to where Jupiter appears to be
|
|
# in the sky, when the light left Jupiter to travel toward the
|
|
# Earth to arrive here at the specified time. This is different from
|
|
# where Jupiter is at that time.
|
|
|
|
jv = GeoVector(Body.Jupiter, time, True)
|
|
|
|
# Calculate the amount of time it took light to reach the Earth from Jupiter.
|
|
# The distance to Jupiter (AU) divided by the speed of light (AU/day) = time in days.
|
|
lt_days = jv.Length() / C_AUDAY
|
|
print()
|
|
print('It took light {:0.2f} minutes to reach the Earth from Jupiter.'.format(lt_days * 24.0 * 60.0))
|
|
print()
|
|
|
|
# The JupiterMoons function calculates positions of Jupiter's moons without
|
|
# correcting for light travel time. Correct for light travel by backdating
|
|
# by the given amount of light travel time.
|
|
backdate = time.AddDays(-lt_days)
|
|
|
|
jm = JupiterMoons(backdate)
|
|
|
|
# Tricky: I'm "cheating" a little bit below by adding Vector `jv`
|
|
# to StateVector `jm.<moon>`, to result in a Vector position for each moon.
|
|
# This works because StateVector has all the fields that Vector has,
|
|
# plus the velocity components (vx, vy, vz).
|
|
# This is alarming to type purists, but just another normal day of
|
|
# "duck typing" for Pythonistas.
|
|
|
|
PrintBody('Jupiter', jv)
|
|
PrintBody('Io', jv + jm.io)
|
|
PrintBody('Europa', jv + jm.europa)
|
|
PrintBody('Ganymede', jv + jm.ganymede)
|
|
PrintBody('Callisto', jv + jm.callisto)
|
|
print()
|
|
|
|
sys.exit(0)
|