Copyright (c) 2024 Massachusetts Institute of Technology

SPDX-License-Identifier: MIT

Transformations#

astroforge provides a number of utilies that can transform between coordinate frames and between compatible orbital parameters. We highlight a few of these transformations in this example, but the full list can be reviewed in the API documentation for astroforge.coordinates._transformations.

Coordinate Conversions#

Convert between the International Terrestrial Reference System (ITRS) and the Mean Equator Mean Equinox of Date system (MEMED) at a specific time defined as a Modified Julian Date (MJD).

[1]:
import numpy as np
from astroforge.coordinates import ITRSToMEMED, MEMEDToITRS

MJD = 60197.5

x_itrs = np.array([-5413.11749016, 4960.20830485, 3177.18312508])  # just a random vector
x_memed = ITRSToMEMED(MJD, x_itrs)
x_itrs_2 = MEMEDToITRS(MJD, x_memed)

print(x_memed)
print(x_itrs_2)
[ 4394.69603967 -5881.50950936  3177.18312508]
[-5413.11749016  4960.20830485  3177.18312508]

Convert between ITRS and Latitude/Longitude/Altitude (degrees and km).

[2]:
from astroforge.coordinates import ITRSToLatLonAlt, LatLonAltToITRS

x_itrs = np.array([-5413.11749016, 4960.20830485, 3177.18312508])  # just a random vector
x_latlonalt = ITRSToLatLonAlt(x_itrs)
x_itrs_2 = LatLonAltToITRS(*x_latlonalt)

print(x_latlonalt)
print(x_itrs_2)
(23.511926934533797, 137.50000000001472, 1625.2463742566208)
[-5413.11749016  4960.20830485  3177.18312508]

Convert between Keplerian elements and True Equator True Equinox of Date (TETED) carteisan coordinates:

[3]:
from astroforge.coordinates import keplerian_to_cartesian, cartesian_to_keplerian

# All angles are in radians
inclination_rad = 0.1
raan_rad = 0.2
argp_rad = 0.3
ecc = 0.4
semi_major_axis_km = 10000.
mean_anomaly_rad = 0.5

x_teted, v_teted = keplerian_to_cartesian(inclination_rad=inclination_rad,
                                 raan_rad=raan_rad,
                                 argp_rad=argp_rad,
                                 ecc=ecc,
                                 semi_major_axis_km=semi_major_axis_km,
                                 mean_anomaly_rad=mean_anomaly_rad)

# Note: The pos/vel arrays need to be converted from shape (1,3) to (3,) for cartesian_to_keplerian
keplerian_elements = cartesian_to_keplerian(pos=x_teted[0], vel=v_teted[0])

print(x_teted, v_teted)
print(keplerian_elements)
[[-371.69607966 7116.79717907  707.23699658]] [[-8.19634168  2.03599094  0.36358961]]
{'inclination_rad': 0.10000000000000056, 'raan_rad': 0.19999999999999946, 'argp_rad': 0.3000000000000009, 'eccentricity': 0.4000000000000004, 'semi_major_axis_km': 10000.000000000005, 'eccentric_anomaly_rad': 0.7818320279930673, 'true_anomaly_rad': 1.1237047648504743, 'mean_anomaly_rad': 0.49999976729035667}

Orbital Element Conversions#

Calculate the True Anomaly from the Mean Anomaly.

Note: You can specify the tolerance and max number of iterations for the underlying numerical solver. By default, they will be set to 1.0e-14 and 100, respectively.

[4]:
from astroforge.coordinates import true_anomaly_from_mean_anomaly, mean_anomaly_from_true_anomaly

eccentricity = 0.5
mean_anomaly = 0.2

true_anomaly = true_anomaly_from_mean_anomaly(e=eccentricity, M=mean_anomaly)
mean_anomaly_2 = mean_anomaly_from_true_anomaly(e=eccentricity, v=true_anomaly)

print(f"True Anomaly: {true_anomaly} radians")
print(f"Mean Anomaly: {mean_anomaly_2} radians")
True Anomaly: 0.6595163855574937 radians
Mean Anomaly: 0.2 radians

Calculate the True Anomaly from the Eccentric Anomaly.

[5]:
from astroforge.coordinates import true_anomaly_from_eccentric_anomaly, eccentric_anomaly_from_true_anomaly

eccentricity = 0.5
eccentric_anomaly = 0.2

true_anomaly = true_anomaly_from_eccentric_anomaly(e=eccentricity, E=eccentric_anomaly)
eccentric_anomaly_2 = eccentric_anomaly_from_true_anomaly(e=eccentricity, v=true_anomaly)

print(f"True Anomaly:      {true_anomaly} radians")
print(f"Eccentric Anomaly: {eccentric_anomaly_2} radians")
True Anomaly:      0.3441325691613769 radians
Eccentric Anomaly: 0.19999999999999996 radians
[ ]: