mirror of
https://github.com/cosinekitty/astronomy.git
synced 2025-12-28 10:09:26 -05:00
The demo shows how to correct for light travel time to render Jupiter's moons as they appear from the Earth. Created an addition operator for the Vector class in the Python code, because it is handy. Corrected a bug in the string representation of the Python StateVector class.
63 lines
2.3 KiB
Python
Executable File
63 lines
2.3 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)
|
|
|
|
PrintBody('Jupiter', jv)
|
|
PrintBody('Io', jv + jm.moon[0])
|
|
PrintBody('Europa', jv + jm.moon[1])
|
|
PrintBody('Ganymede', jv + jm.moon[2])
|
|
PrintBody('Callisto', jv + jm.moon[3])
|
|
print()
|
|
|
|
sys.exit(0)
|