Skip to content

Commit

Permalink
[rust] [python] Fix signature of try_from_altlatlong to try_from_latl…
Browse files Browse the repository at this point in the history
…ongalt

The parameters did not match the function name!
  • Loading branch information
ChristopherRabotin committed Dec 29, 2023
1 parent 3c688dd commit 4232f17
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 8 deletions.
17 changes: 17 additions & 0 deletions anise-py/tests/test_almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ def test_state_transformation():

assert orig_state == from_state_itrf93_to_eme2k

# Demo creation of a ground station
mean_earth_angular_velocity_deg_s = 0.004178079012116429
# Grab the loaded frame info
itrf93 = ctx.frame_info(Frames.EARTH_ITRF93)
paris = Orbit.from_latlongalt(
48.8566,
2.3522,
0.4,
mean_earth_angular_velocity_deg_s,
epoch,
itrf93,
)

assert abs(paris.geodetic_latitude_deg() - 48.8566) < 1e-3
assert abs(paris.geodetic_longitude_deg() - 2.3522) < 1e-3
assert abs(paris.geodetic_height_km() - 0.4) < 1e-3


if __name__ == "__main__":
test_state_transformation()
17 changes: 17 additions & 0 deletions anise/src/astro/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ impl CartesianState {
Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame)
}

/// Attempts to create a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
#[cfg(feature = "python")]
#[classmethod]
pub fn from_keplerian_apsis_radii(
_cls: &PyType,
r_a: f64,
r_p: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
Self::try_keplerian_apsis_radii(r_a, r_p, inc, raan, aop, ta, epoch, frame)
}

/// Returns the orbital momentum value on the X axis
pub fn hx(&self) -> PhysicsResult<f64> {
Ok(self.hvec()?[0])
Expand Down
72 changes: 67 additions & 5 deletions anise/src/astro/orbit_geodetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use log::error;

#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "python")]
use pyo3::types::PyType;

impl CartesianState {
/// Creates a new Orbit from the provided semi-major axis altitude in kilometers
Expand Down Expand Up @@ -51,8 +53,8 @@ impl CartesianState {
/// Creates a new Orbit from the provided altitudes of apoapsis and periapsis, in kilometers
#[allow(clippy::too_many_arguments)]
pub fn try_keplerian_apsis_altitude(
a_a: f64,
a_p: f64,
apo_alt: f64,
peri_alt: f64,
inc: f64,
raan: f64,
aop: f64,
Expand All @@ -61,8 +63,8 @@ impl CartesianState {
frame: Frame,
) -> PhysicsResult<Self> {
Self::try_keplerian_apsis_radii(
a_a + frame.mean_equatorial_radius_km()?,
a_p + frame.mean_equatorial_radius_km()?,
apo_alt + frame.mean_equatorial_radius_km()?,
peri_alt + frame.mean_equatorial_radius_km()?,
inc,
raan,
aop,
Expand All @@ -77,7 +79,7 @@ impl CartesianState {
/// **Units:** degrees, degrees, km, rad/s
/// NOTE: This computation differs from the spherical coordinates because we consider the flattening of body.
/// Reference: G. Xu and Y. Xu, "GPS", DOI 10.1007/978-3-662-50367-6_2, 2016
pub fn from_altlatlong(
pub fn try_from_latlongalt(
latitude_deg: f64,
longitude_deg: f64,
height_km: f64,
Expand Down Expand Up @@ -112,6 +114,66 @@ impl CartesianState {

#[cfg_attr(feature = "python", pymethods)]
impl CartesianState {
/// Creates a new Orbit from the provided semi-major axis altitude in kilometers
#[cfg(feature = "python")]
#[classmethod]
pub fn from_keplerian_altitude(
_cls: &PyType,
sma_altitude: f64,
ecc: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
Self::try_keplerian_altitude(sma_altitude, ecc, inc, raan, aop, ta, epoch, frame)
}

/// Creates a new Orbit from the provided altitudes of apoapsis and periapsis, in kilometers
#[cfg(feature = "python")]
#[classmethod]
pub fn from_keplerian_apsis_altitude(
_cls: &PyType,
apo_alt: f64,
peri_alt: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
Self::try_keplerian_apsis_altitude(apo_alt, peri_alt, inc, raan, aop, ta, epoch, frame)
}

/// Creates a new Orbit from the latitude (φ), longitude (λ) and height (in km) with respect to the frame's ellipsoid given the angular velocity.
///
/// **Units:** degrees, degrees, km, rad/s
/// NOTE: This computation differs from the spherical coordinates because we consider the flattening of body.
/// Reference: G. Xu and Y. Xu, "GPS", DOI 10.1007/978-3-662-50367-6_2, 2016
#[cfg(feature = "python")]
#[classmethod]
pub fn from_latlongalt(
_cls: &PyType,
latitude_deg: f64,
longitude_deg: f64,
height_km: f64,
angular_velocity: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
Self::try_from_latlongalt(
latitude_deg,
longitude_deg,
height_km,
angular_velocity,
epoch,
frame,
)
}

/// Returns the SMA altitude in km
pub fn sma_altitude_km(&self) -> PhysicsResult<f64> {
Ok(self.sma_km()? - self.frame.mean_equatorial_radius_km()?)
Expand Down
6 changes: 3 additions & 3 deletions anise/tests/astro/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ fn verif_geodetic_vallado(almanac: Almanac) {
f64_eq!(r.geodetic_longitude_deg(), long, "longitude (λ)");
f64_eq!(r.geodetic_height_km().unwrap(), height, "height");
let mean_earth_angular_velocity_deg_s = 0.004178079012116429;
let r = Orbit::from_altlatlong(
let r = Orbit::try_from_latlongalt(
lat,
long,
height,
Expand All @@ -484,7 +484,7 @@ fn verif_geodetic_vallado(almanac: Almanac) {
let ri = 6_119.403_233_271_109;
let rj = -1_571.480_316_600_378_3;
let rk = -871.560_226_712_024_7;
let r = Orbit::from_altlatlong(
let r = Orbit::try_from_latlongalt(
lat,
long,
height,
Expand All @@ -502,7 +502,7 @@ fn verif_geodetic_vallado(almanac: Almanac) {
f64_eq!(r.geodetic_height_km().unwrap(), height_val, "height");

// Check reciprocity near poles
let r = Orbit::from_altlatlong(
let r = Orbit::try_from_latlongalt(
0.1,
long,
height_val,
Expand Down

0 comments on commit 4232f17

Please sign in to comment.