Files
astronomy/demo/python/ecliptic_of_date.py
Don Cross c7095c5038 Added Python demo ecliptic_of_date.
The demo program ecliptic_of_date.py shows how to
calculate the true ecliptic of date (ECT) angular coordinates
of the Sun, Moon, and planets for an observer somewhere on the Earth.
It calculates the equatorial of date (EQD) coordinates, then uses
a rotation matrix to convert the vector to ECT, then converts
the vector to spherical coordinates: latitude, longitude, and distance.
2023-10-02 16:36:56 -04:00

43 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
#
# ecliptic_of_date.py - by Don Cross - 2023-10-02
#
# Example program for Astronomy Engine:
# https://github.com/cosinekitty/astronomy
#
# This program shows how to calculate true ecliptic coordinates of date (ECT)
# for the Sun, Moon, and planets for an observer at a given location
# on the Earth.
#
import sys
from astronomy import Body, Equator, Rotation_EQD_ECT, RotateVector, SphereFromVector
from astro_demo_common import ParseArgs
if __name__ == '__main__':
observer, time = ParseArgs(sys.argv)
bodyList = [
Body.Sun, Body.Moon, Body.Mercury, Body.Venus, Body.Mars,
Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto
]
# Create a rotation matrix that converts equator-of-date (EQD) vectors
# to true ecliptic of date (ECT) vectors.
rot = Rotation_EQD_ECT(time)
print('{:9s} {:>8s} {:>8s} {:>11s}'.format('body', 'lon', 'lat', 'dist'))
for body in bodyList:
# Calculate equatorial coordinates of date = EQD (ofdate parameter is True).
eqd = Equator(body, time, observer, True, True)
# The returned object `eqd` is of type `Equatorial`, which contains a vector.
# Use the rotation matrix to convert that vector from (EQD) to ecliptic of date (ECT).
ect = RotateVector(rot, eqd.vec)
# Convert vector to spherical coordinate angles: ecliptic longitude, ecliptic latitude.
sphere = SphereFromVector(ect)
# Print the output for this body
print('{:9s} {:8.3f} {:8.3f} {:11.6f}'.format(body.name, sphere.lon, sphere.lat, sphere.dist))
sys.exit(0)