Python: Jupiter's moons returned by name

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.
This commit is contained in:
Don Cross
2022-05-05 12:39:39 -04:00
parent af63d1520f
commit 66eeb3e0a0
6 changed files with 146 additions and 27 deletions

View File

@@ -265,6 +265,28 @@ class StateVector:
self.vx, self.vy, self.vz,
repr(self.t))
def __add__(self, other):
return StateVector(
self.x + other.x,
self.y + other.y,
self.z + other.z,
self.vx + other.vx,
self.vy + other.vy,
self.vz + other.vz,
self.t
)
def __sub__(self, other):
return StateVector(
self.x - other.x,
self.y - other.y,
self.z - other.z,
self.vx - other.vx,
self.vy - other.vy,
self.vz - other.vz,
self.t
)
@enum.unique
class Body(enum.Enum):
"""The celestial bodies supported by Astronomy Engine calculations.
@@ -3978,15 +4000,28 @@ class JupiterMoonsInfo:
Attributes
----------
moon : StateVector[4]
An array of state vectors, one for each of the four major moons
of Jupiter, in the following order: 0=Io, 1=Europa, 2=Ganymede, 3=Callisto.
io : StateVector
The position and velocity of Jupiter's moon Io.
europa : StateVector
The position and velocity of Jupiter's moon Europa.
ganymede : StateVector
The position and velocity of Jupiter's moon Ganymede.
callisto : StateVector
The position and velocity of Jupiter's moon Callisto.
"""
def __init__(self, moon):
self.moon = moon
self.io = moon[0]
self.europa = moon[1]
self.ganymede = moon[2]
self.callisto = moon[3]
def __repr__(self):
return 'JupiterMoonsInfo({})'.format(repr(self.moon))
return 'JupiterMoonsInfo(io={}, europa={}, ganymede={}, callisto={})'.format(
repr(self.io),
repr(self.europa),
repr(self.ganymede),
repr(self.callisto)
)
def _JupiterMoon_elem2pv(time, mu, A, AL, K, H, Q, P):