Skip to content

Instantly share code, notes, and snippets.

@jorgepiloto
Created April 15, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgepiloto/9fbdb1155e3ff4743f52c4a1dcfdb188 to your computer and use it in GitHub Desktop.
Save jorgepiloto/9fbdb1155e3ff4743f52c4a1dcfdb188 to your computer and use it in GitHub Desktop.
Converts from custom MarsICRS to MarsFixed using Orekit API
""" Validate poliastro frames against Orekit ones """
from orekit.pyhelpers import setup_orekit_curdir
from org.hipparchus.geometry.euclidean.threed import Vector3D
from org.orekit.bodies import CelestialBodyFactory
from org.orekit.frames import FramesFactory, Transform, UpdatableFrame
from org.orekit.time import AbsoluteDate
from org.orekit.utils import PVCoordinatesProvider, TimeStampedPVCoordinates
import orekit
# Setup orekit virtual machine and associated data
VM = orekit.initVM()
setup_orekit_curdir("orekit-data.zip")
# Declare the J2000 date and ICRF frame
J2000 = AbsoluteDate.J2000_EPOCH
FRAME_ICRF = FramesFactory.getICRF()
# Get Mars and compute its position w.r.t. ICRF
Mars = CelestialBodyFactory.getMars()
PVMars_ICRF = PVCoordinatesProvider.cast_(Mars).getPVCoordinates(J2000, FRAME_ICRF)
# Compute Mars inertial and fixed frames
MarsINERTIAL = Mars.getInertiallyOrientedFrame()
MarsFIXED = Mars.getBodyOrientedFrame()
# Define MarsICRF as a pure translation of ICRF but centered in current planet
# location
MarsICRF = UpdatableFrame(FRAME_ICRF, Transform(J2000, PVMars_ICRF), "MarsICRF", False)
# Compute the transformation between MarsICRF -> MarsFIXED
MarsICRF_to_MarsFIXED = MarsICRF.getTransformTo(MarsFIXED, J2000)
# Define a PV vector w.r.t. MarsICRF frame
POS = Vector3D(float(7000e3), float(5000e3), float(200e3)) # [m]
VEL = Vector3D(float(0), float(2.5e3), float(0.5e3)) # [m / s]
PV_in_MarsICRF = TimeStampedPVCoordinates(J2000, POS, VEL)
# Apply the conversion from MarsICRF -> MarsFIXED
PV_in_MarsFixed = MarsICRF_to_MarsFIXED.transformPVCoordinates(PV_in_MarsICRF)
computed_pos = list(PV_in_MarsFixed.getPosition().toArray())
# Expected position w.r.t. MarsFIXED (computed with GMAT-2020a)
expected_pos = [-8471.116775897131e3, 845.0749156806216e3, 1251.410786458257e3]
expected_vel = [1.692787736347916e3, -1.145272280803045e3, -0.6168731511636765e3]
# Print computed and expected positions
print(f"{computed_pos = }\n{expected_pos = }")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment